summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberts Muktupāvels <alberts.muktupavels@gmail.com>2021-12-28 13:50:24 +0200
committerMarco Trevisan <mail@3v1n0.net>2022-02-17 13:35:41 +0000
commit5681d7d1ba277df1ac45f987457ec2775e6a5ba6 (patch)
tree2d4ef3e5e82e46ed6b6cef710499ff2bfb6b20b9
parent5797929fa5185dc78e8f9db3d855006d694fb589 (diff)
downloadlibwnck-5681d7d1ba277df1ac45f987457ec2775e6a5ba6.tar.gz
window: move window_hash to WnckHandle
-rw-r--r--libwnck/private.h2
-rw-r--r--libwnck/window.c37
-rw-r--r--libwnck/wnck-handle-private.h10
-rw-r--r--libwnck/wnck-handle.c37
4 files changed, 58 insertions, 28 deletions
diff --git a/libwnck/private.h b/libwnck/private.h
index 6bf8f7e..26a3437 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -70,8 +70,6 @@ const char* _wnck_window_get_startup_id (WnckWindow *window);
time_t _wnck_window_get_needs_attention_time (WnckWindow *window);
time_t _wnck_window_or_transient_get_needs_attention_time (WnckWindow *window);
-void _wnck_window_shutdown_all (void);
-
WnckWorkspace* _wnck_workspace_create (int number,
WnckScreen *screen);
void _wnck_workspace_destroy (WnckWorkspace *space);
diff --git a/libwnck/window.c b/libwnck/window.c
index 25c56a5..8f6c8b7 100644
--- a/libwnck/window.c
+++ b/libwnck/window.c
@@ -48,8 +48,6 @@
#define FALLBACK_NAME _("Untitled window")
#define ALL_WORKSPACES ((int) 0xFFFFFFFF)
-static GHashTable *window_hash = NULL;
-
/* Keep 0-7 in sync with the numbers in the WindowState enum. Yeah I'm
* a loser.
*/
@@ -219,16 +217,6 @@ static WnckWindow* find_last_transient_for (GList *windows,
static guint signals[LAST_SIGNAL] = { 0 };
-void
-_wnck_window_shutdown_all (void)
-{
- if (window_hash != NULL)
- {
- g_hash_table_destroy (window_hash);
- window_hash = NULL;
- }
-}
-
static void
wnck_window_init (WnckWindow *window)
{
@@ -460,10 +448,7 @@ wnck_window_finalize (GObject *object)
WnckWindow*
wnck_window_get (gulong xwindow)
{
- if (window_hash == NULL)
- return NULL;
- else
- return g_hash_table_lookup (window_hash, &xwindow);
+ return _wnck_handle_get_window (_wnck_get_handle (), xwindow);
}
/**
@@ -488,15 +473,14 @@ _wnck_window_create (Window xwindow,
WnckScreen *screen,
gint sort_order)
{
+ WnckHandle *handle;
WnckWindow *window;
Screen *xscreen;
- if (window_hash == NULL)
- window_hash = g_hash_table_new_full (_wnck_xid_hash, _wnck_xid_equal,
- NULL, g_object_unref);
+ handle = _wnck_screen_get_handle (screen);
+ window = _wnck_handle_get_window (handle, xwindow);
- g_return_val_if_fail (g_hash_table_lookup (window_hash, &xwindow) == NULL,
- NULL);
+ g_return_val_if_fail (window == NULL, NULL);
xscreen = WNCK_SCREEN_XSCREEN (screen);
@@ -504,9 +488,9 @@ _wnck_window_create (Window xwindow,
window->priv->xwindow = xwindow;
window->priv->screen = screen;
- g_hash_table_insert (window_hash, &window->priv->xwindow, window);
+ _wnck_handle_insert_window (handle, &window->priv->xwindow, window);
- /* Hash now owns one ref, caller gets none */
+ /* Handle now owns one ref, caller gets none */
/* Note that xwindow may correspond to a WnckApplication's xwindow,
* that's why we select the union of the mask we want for Application
@@ -567,15 +551,18 @@ _wnck_window_create (Window xwindow,
void
_wnck_window_destroy (WnckWindow *window)
{
+ WnckHandle *handle;
Window xwindow = window->priv->xwindow;
g_return_if_fail (WNCK_IS_WINDOW (window));
+ handle = _wnck_screen_get_handle (window->priv->screen);
+
g_return_if_fail (wnck_window_get (xwindow) == window);
- g_hash_table_remove (window_hash, &xwindow);
+ _wnck_handle_remove_window (handle, &xwindow);
- /* Removing from hash also removes the only ref WnckWindow had */
+ /* Removing from handle also removes the only ref WnckWindow had */
g_return_if_fail (wnck_window_get (xwindow) == NULL);
}
diff --git a/libwnck/wnck-handle-private.h b/libwnck/wnck-handle-private.h
index c0f8d9d..ff5b4f9 100644
--- a/libwnck/wnck-handle-private.h
+++ b/libwnck/wnck-handle-private.h
@@ -59,6 +59,16 @@ void _wnck_handle_remove_application (WnckHandle *self,
WnckApplication *_wnck_handle_get_application (WnckHandle *self,
gulong xwindow);
+void _wnck_handle_insert_window (WnckHandle *self,
+ gpointer xwindow,
+ WnckWindow *window);
+
+void _wnck_handle_remove_window (WnckHandle *self,
+ gpointer xwindow);
+
+WnckWindow *_wnck_handle_get_window (WnckHandle *self,
+ gulong xwindow);
+
G_END_DECLS
#endif
diff --git a/libwnck/wnck-handle.c b/libwnck/wnck-handle.c
index 1bbb3a4..f1ddf1c 100644
--- a/libwnck/wnck-handle.c
+++ b/libwnck/wnck-handle.c
@@ -40,6 +40,7 @@ struct _WnckHandle
GHashTable *class_group_hash;
GHashTable *app_hash;
+ GHashTable *window_hash;
};
enum
@@ -177,7 +178,12 @@ wnck_handle_finalize (GObject *object)
}
_wnck_screen_shutdown_all ();
- _wnck_window_shutdown_all ();
+
+ if (self->window_hash != NULL)
+ {
+ g_hash_table_destroy (self->window_hash);
+ self->window_hash = NULL;
+ }
G_OBJECT_CLASS (wnck_handle_parent_class)->finalize (object);
}
@@ -273,6 +279,11 @@ wnck_handle_init (WnckHandle *self)
NULL,
g_object_unref);
+ self->window_hash = g_hash_table_new_full (_wnck_xid_hash,
+ _wnck_xid_equal,
+ NULL,
+ g_object_unref);
+
gdk_window_add_filter (NULL, filter_func, self);
}
@@ -366,3 +377,27 @@ _wnck_handle_get_application (WnckHandle *self,
return g_hash_table_lookup (self->app_hash, &xwindow);
}
+
+void
+_wnck_handle_insert_window (WnckHandle *self,
+ gpointer xwindow,
+ WnckWindow *window)
+{
+ g_hash_table_insert (self->window_hash, xwindow, window);
+}
+
+void
+_wnck_handle_remove_window (WnckHandle *self,
+ gpointer xwindow)
+{
+ g_hash_table_remove (self->window_hash, xwindow);
+}
+
+WnckWindow *
+_wnck_handle_get_window (WnckHandle *self,
+ gulong xwindow)
+{
+ g_return_val_if_fail (WNCK_IS_HANDLE (self), NULL);
+
+ return g_hash_table_lookup (self->window_hash, &xwindow);
+}