[libwnck/wip/muktupavels/wnck-handle-3: 3/4] application: move app_hash to WnckHandle




commit 853ec7d65718f8925b51fdc5e69ac1c263bd763f
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Dec 28 13:42:09 2021 +0200

    application: move app_hash to WnckHandle

 libwnck/application.c         | 42 ++++++++++++++++--------------------------
 libwnck/private.h             |  1 -
 libwnck/wnck-handle-private.h | 40 +++++++++++++++++++++++++---------------
 libwnck/wnck-handle.c         | 37 ++++++++++++++++++++++++++++++++++++-
 4 files changed, 77 insertions(+), 43 deletions(-)
---
diff --git a/libwnck/application.c b/libwnck/application.c
index 8d78209..08b8f6e 100644
--- a/libwnck/application.c
+++ b/libwnck/application.c
@@ -25,6 +25,7 @@
 #include <glib/gi18n-lib.h>
 #include "application.h"
 #include "private.h"
+#include "wnck-handle-private.h"
 #include "wnck-icon-cache-private.h"
 
 /**
@@ -49,8 +50,6 @@
 
 #define FALLBACK_NAME _("Untitled application")
 
-static GHashTable *app_hash = NULL;
-
 struct _WnckApplicationPrivate
 {
   Window xwindow; /* group leader */
@@ -96,16 +95,6 @@ static void wnck_application_finalize    (GObject        *object);
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-void
-_wnck_application_shutdown_all (void)
-{
-  if (app_hash != NULL)
-    {
-      g_hash_table_destroy (app_hash);
-      app_hash = NULL;
-    }
-}
-
 static void
 wnck_application_init (WnckApplication *application)
 {
@@ -203,10 +192,7 @@ wnck_application_finalize (GObject *object)
 WnckApplication*
 wnck_application_get (gulong xwindow)
 {
-  if (app_hash == NULL)
-    return NULL;
-  else
-    return g_hash_table_lookup (app_hash, &xwindow);
+  return _wnck_handle_get_application (_wnck_get_handle (), xwindow);
 }
 
 /**
@@ -514,15 +500,14 @@ WnckApplication*
 _wnck_application_create (Window      xwindow,
                           WnckScreen *screen)
 {
+  WnckHandle      *handle;
   WnckApplication *application;
   Screen          *xscreen;
 
-  if (app_hash == NULL)
-    app_hash = g_hash_table_new_full (_wnck_xid_hash, _wnck_xid_equal,
-                                      NULL, g_object_unref);
+  handle = _wnck_screen_get_handle (screen);
+  application = _wnck_handle_get_application (handle, xwindow);
 
-  g_return_val_if_fail (g_hash_table_lookup (app_hash, &xwindow) == NULL,
-                        NULL);
+  g_return_val_if_fail (application == NULL, NULL);
 
   xscreen = WNCK_SCREEN_XSCREEN (screen);
 
@@ -545,9 +530,11 @@ _wnck_application_create (Window      xwindow,
                                                            application->priv->xwindow,
                                                            _wnck_atom_get ("_NET_STARTUP_ID"));
 
-  g_hash_table_insert (app_hash, &application->priv->xwindow, application);
+  _wnck_handle_insert_application (handle,
+                                   &application->priv->xwindow,
+                                   application);
 
-  /* Hash now owns one ref, caller gets none */
+  /* Handle now owns one ref, caller gets none */
 
   /* Note that xwindow may correspond to a WnckWindow's xwindow,
    * so we select events needed by either
@@ -563,13 +550,16 @@ _wnck_application_create (Window      xwindow,
 void
 _wnck_application_destroy (WnckApplication *application)
 {
+  WnckHandle *handle;
   Window xwindow = application->priv->xwindow;
 
-  g_return_if_fail (wnck_application_get (xwindow) == application);
+  handle = _wnck_screen_get_handle (application->priv->screen);
+
+  g_return_if_fail (_wnck_handle_get_application (handle, xwindow) == application);
 
-  g_hash_table_remove (app_hash, &xwindow);
+  _wnck_handle_remove_application (handle, &xwindow);
 
-  /* Removing from hash also removes the only ref WnckApplication had */
+  /* Removing from handle also removes the only ref WnckApplication had */
 
   g_return_if_fail (wnck_application_get (xwindow) == NULL);
 }
diff --git a/libwnck/private.h b/libwnck/private.h
index 372e1cb..6bf8f7e 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -96,7 +96,6 @@ WnckApplication* _wnck_application_create  (Window           xwindow,
                                             WnckScreen      *screen);
 void             _wnck_application_destroy (WnckApplication *app);
 void             _wnck_application_load_icons (WnckApplication *app);
-void             _wnck_application_shutdown_all (void);
 
 WnckClassGroup  *_wnck_class_group_create        (WnckScreen     *screen,
                                                   const char     *res_class);
diff --git a/libwnck/wnck-handle-private.h b/libwnck/wnck-handle-private.h
index caa41ee..c0f8d9d 100644
--- a/libwnck/wnck-handle-private.h
+++ b/libwnck/wnck-handle-private.h
@@ -25,29 +25,39 @@ G_BEGIN_DECLS
 
 typedef struct _WnckHandle WnckHandle;
 
-WnckHandle     *_wnck_handle_new                        (WnckClientType  client_type);
+WnckHandle      *_wnck_handle_new                        (WnckClientType  client_type);
 
-WnckClientType  _wnck_handle_get_client_type            (WnckHandle     *self);
+WnckClientType   _wnck_handle_get_client_type            (WnckHandle     *self);
 
-void            _wnck_handle_set_default_icon_size      (WnckHandle     *self,
-                                                         gsize           icon_size);
+void             _wnck_handle_set_default_icon_size      (WnckHandle     *self,
+                                                          gsize           icon_size);
 
-gsize           _wnck_handle_get_default_icon_size      (WnckHandle     *self);
+gsize            _wnck_handle_get_default_icon_size      (WnckHandle     *self);
 
-void            _wnck_handle_set_default_mini_icon_size (WnckHandle     *self,
-                                                         gsize           icon_size);
+void             _wnck_handle_set_default_mini_icon_size (WnckHandle     *self,
+                                                          gsize           icon_size);
 
-gsize           _wnck_handle_get_default_mini_icon_size (WnckHandle     *self);
+gsize            _wnck_handle_get_default_mini_icon_size (WnckHandle     *self);
 
-void            _wnck_handle_insert_class_group         (WnckHandle      *self,
-                                                         const char      *id,
-                                                         WnckClassGroup  *class_group);
+void             _wnck_handle_insert_class_group         (WnckHandle      *self,
+                                                          const char      *id,
+                                                          WnckClassGroup  *class_group);
 
-void            _wnck_handle_remove_class_group         (WnckHandle      *self,
-                                                         const char      *id);
+void             _wnck_handle_remove_class_group         (WnckHandle      *self,
+                                                          const char      *id);
 
-WnckClassGroup *_wnck_handle_get_class_group            (WnckHandle      *self,
-                                                         const char      *id);
+WnckClassGroup  *_wnck_handle_get_class_group            (WnckHandle      *self,
+                                                          const char      *id);
+
+void             _wnck_handle_insert_application         (WnckHandle      *self,
+                                                          gpointer         xwindow,
+                                                          WnckApplication *app);
+
+void             _wnck_handle_remove_application         (WnckHandle      *self,
+                                                          gpointer         xwindow);
+
+WnckApplication *_wnck_handle_get_application            (WnckHandle      *self,
+                                                          gulong           xwindow);
 
 G_END_DECLS
 
diff --git a/libwnck/wnck-handle.c b/libwnck/wnck-handle.c
index eb14f65..1bbb3a4 100644
--- a/libwnck/wnck-handle.c
+++ b/libwnck/wnck-handle.c
@@ -39,6 +39,7 @@ struct _WnckHandle
   gsize           default_mini_icon_size;
 
   GHashTable     *class_group_hash;
+  GHashTable     *app_hash;
 };
 
 enum
@@ -169,7 +170,12 @@ wnck_handle_finalize (GObject *object)
       self->class_group_hash = NULL;
     }
 
-  _wnck_application_shutdown_all ();
+  if (self->app_hash != NULL)
+    {
+      g_hash_table_destroy (self->app_hash);
+      self->app_hash = NULL;
+    }
+
   _wnck_screen_shutdown_all ();
   _wnck_window_shutdown_all ();
 
@@ -262,6 +268,11 @@ wnck_handle_init (WnckHandle *self)
                                                   NULL,
                                                   g_object_unref);
 
+  self->app_hash = g_hash_table_new_full (_wnck_xid_hash,
+                                          _wnck_xid_equal,
+                                          NULL,
+                                          g_object_unref);
+
   gdk_window_add_filter (NULL, filter_func, self);
 }
 
@@ -331,3 +342,27 @@ _wnck_handle_get_class_group (WnckHandle *self,
 
   return g_hash_table_lookup (self->class_group_hash, id ? id : "");
 }
+
+void
+_wnck_handle_insert_application (WnckHandle      *self,
+                                 gpointer         xwindow,
+                                 WnckApplication *app)
+{
+  g_hash_table_insert (self->app_hash, xwindow, app);
+}
+
+void
+_wnck_handle_remove_application (WnckHandle *self,
+                                 gpointer    xwindow)
+{
+  g_hash_table_remove (self->app_hash, xwindow);
+}
+
+WnckApplication *
+_wnck_handle_get_application (WnckHandle *self,
+                              gulong      xwindow)
+{
+  g_return_val_if_fail (WNCK_IS_HANDLE (self), NULL);
+
+  return g_hash_table_lookup (self->app_hash, &xwindow);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]