[libwnck/wip/muktupavels/wnck-handle: 1/2] support multiple handles at same time
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libwnck/wip/muktupavels/wnck-handle: 1/2] support multiple handles at same time
- Date: Thu, 17 Feb 2022 15:08:18 +0000 (UTC)
commit 5195846b1a6e63124fa1106e23249e07c813bb35
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Aug 20 17:27:13 2019 +0300
support multiple handles at same time
libwnck/application.c | 8 +++----
libwnck/class-group.c | 4 ++--
libwnck/screen.c | 10 ++++----
libwnck/window.c | 16 +++++++++----
libwnck/wnck-handle-private.h | 9 -------
libwnck/wnck-handle.c | 56 ++++++++++++++++++++++++++++++++++++-------
libwnck/wnck-handle.h | 29 ++++++++++++++--------
libwnck/wnckprop.c | 45 +++++++++++++++++++---------------
8 files changed, 114 insertions(+), 63 deletions(-)
---
diff --git a/libwnck/application.c b/libwnck/application.c
index be955af9..30591b3b 100644
--- a/libwnck/application.c
+++ b/libwnck/application.c
@@ -192,7 +192,7 @@ wnck_application_finalize (GObject *object)
WnckApplication*
wnck_application_get (gulong xwindow)
{
- return _wnck_handle_get_application (_wnck_get_handle (), xwindow);
+ return wnck_handle_get_application (_wnck_get_handle (), xwindow);
}
/**
@@ -508,7 +508,7 @@ _wnck_application_create (Window xwindow,
Screen *xscreen;
handle = _wnck_screen_get_handle (screen);
- application = _wnck_handle_get_application (handle, xwindow);
+ application = wnck_handle_get_application (handle, xwindow);
g_return_val_if_fail (application == NULL, NULL);
@@ -558,13 +558,13 @@ _wnck_application_destroy (WnckApplication *application)
handle = _wnck_screen_get_handle (application->priv->screen);
- g_return_if_fail (_wnck_handle_get_application (handle, xwindow) == application);
+ g_return_if_fail (wnck_handle_get_application (handle, xwindow) == application);
_wnck_handle_remove_application (handle, &xwindow);
/* Removing from handle also removes the only ref WnckApplication had */
- g_return_if_fail (wnck_application_get (xwindow) == NULL);
+ g_return_if_fail (wnck_handle_get_application (handle, xwindow) == NULL);
}
static void
diff --git a/libwnck/class-group.c b/libwnck/class-group.c
index 683a3813..380f1b7b 100644
--- a/libwnck/class-group.c
+++ b/libwnck/class-group.c
@@ -203,7 +203,7 @@ wnck_class_group_finalize (GObject *object)
WnckClassGroup *
wnck_class_group_get (const char *id)
{
- return _wnck_handle_get_class_group (_wnck_get_handle (), id);
+ return wnck_handle_get_class_group (_wnck_get_handle (), id);
}
/**
@@ -226,7 +226,7 @@ _wnck_class_group_create (WnckScreen *screen,
WnckClassGroup *class_group;
handle = _wnck_screen_get_handle (screen);
- class_group = _wnck_handle_get_class_group (handle, res_class);
+ class_group = wnck_handle_get_class_group (handle, res_class);
g_return_val_if_fail (class_group == NULL, NULL);
diff --git a/libwnck/screen.c b/libwnck/screen.c
index dbe94a60..45ad9481 100644
--- a/libwnck/screen.c
+++ b/libwnck/screen.c
@@ -1420,7 +1420,7 @@ update_client_list (WnckScreen *screen)
{
WnckWindow *window;
- window = wnck_window_get (mapping[i]);
+ window = wnck_handle_get_window (screen->priv->handle, mapping[i]);
if (window == NULL)
{
@@ -1439,7 +1439,7 @@ update_client_list (WnckScreen *screen)
leader = wnck_window_get_group_leader (window);
- app = wnck_application_get (leader);
+ app = wnck_handle_get_application (screen->priv->handle, leader);
if (app == NULL)
{
app = _wnck_application_create (leader, screen);
@@ -1452,7 +1452,7 @@ update_client_list (WnckScreen *screen)
res_class = wnck_window_get_class_group_name (window);
- class_group = wnck_class_group_get (res_class);
+ class_group = wnck_handle_get_class_group (screen->priv->handle, res_class);
if (class_group == NULL)
{
class_group = _wnck_class_group_create (screen, res_class);
@@ -1516,7 +1516,7 @@ update_client_list (WnckScreen *screen)
{
WnckWindow *window;
- window = wnck_window_get (stack[i]);
+ window = wnck_handle_get_window (screen->priv->handle, stack[i]);
g_assert (window != NULL);
@@ -1930,7 +1930,7 @@ update_active_window (WnckScreen *screen)
_wnck_atom_get ("_NET_ACTIVE_WINDOW"),
&xwindow);
- window = wnck_window_get (xwindow);
+ window = wnck_handle_get_window (screen->priv->handle, xwindow);
if (window == screen->priv->active_window)
return;
diff --git a/libwnck/window.c b/libwnck/window.c
index ebd7cf1a..1f12004e 100644
--- a/libwnck/window.c
+++ b/libwnck/window.c
@@ -449,7 +449,7 @@ wnck_window_finalize (GObject *object)
WnckWindow*
wnck_window_get (gulong xwindow)
{
- return _wnck_handle_get_window (_wnck_get_handle (), xwindow);
+ return wnck_handle_get_window (_wnck_get_handle (), xwindow);
}
/**
@@ -479,7 +479,7 @@ _wnck_window_create (Window xwindow,
Screen *xscreen;
handle = _wnck_screen_get_handle (screen);
- window = _wnck_handle_get_window (handle, xwindow);
+ window = wnck_handle_get_window (handle, xwindow);
g_return_val_if_fail (window == NULL, NULL);
@@ -565,7 +565,7 @@ _wnck_window_destroy (WnckWindow *window)
/* Removing from handle also removes the only ref WnckWindow had */
- g_return_if_fail (wnck_window_get (xwindow) == NULL);
+ g_return_if_fail (wnck_handle_get_window (handle, xwindow) == NULL);
}
static Display *
@@ -741,9 +741,13 @@ wnck_window_get_application (WnckWindow *window)
WnckWindow*
wnck_window_get_transient (WnckWindow *window)
{
+ WnckHandle *handle;
+
g_return_val_if_fail (WNCK_IS_WINDOW (window), NULL);
- return wnck_window_get (window->priv->transient_for);
+ handle = wnck_screen_get_handle (window->priv->screen);
+
+ return wnck_handle_get_window (handle, window->priv->transient_for);
}
/**
@@ -1162,11 +1166,13 @@ _wnck_window_get_startup_id (WnckWindow *window)
if (window->priv->startup_id == NULL &&
window->priv->group_leader != None)
{
+ WnckHandle *handle;
WnckApplication *app;
/* Fall back to group leader property */
- app = wnck_application_get (window->priv->group_leader);
+ handle = wnck_screen_get_handle (window->priv->screen);
+ app = wnck_handle_get_application (handle, window->priv->group_leader);
if (app != NULL)
return wnck_application_get_startup_id (app);
diff --git a/libwnck/wnck-handle-private.h b/libwnck/wnck-handle-private.h
index f17b3154..cca13e17 100644
--- a/libwnck/wnck-handle-private.h
+++ b/libwnck/wnck-handle-private.h
@@ -40,9 +40,6 @@ void _wnck_handle_insert_class_group (WnckHandle *self,
void _wnck_handle_remove_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);
@@ -50,9 +47,6 @@ void _wnck_handle_insert_application (WnckHandle *self,
void _wnck_handle_remove_application (WnckHandle *self,
gpointer xwindow);
-WnckApplication *_wnck_handle_get_application (WnckHandle *self,
- gulong xwindow);
-
void _wnck_handle_insert_window (WnckHandle *self,
gpointer xwindow,
WnckWindow *window);
@@ -60,9 +54,6 @@ void _wnck_handle_insert_window (WnckHandle *self,
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 57e1216b..0995da74 100644
--- a/libwnck/wnck-handle.c
+++ b/libwnck/wnck-handle.c
@@ -97,8 +97,8 @@ filter_func (GdkXEvent *gdkxevent,
WnckWindow *window;
WnckApplication *app;
- window = wnck_window_get (xevent->xany.window);
- app = wnck_application_get (xevent->xany.window);
+ window = wnck_handle_get_window (self, xevent->xany.window);
+ app = wnck_handle_get_application (self, xevent->xany.window);
if (app)
_wnck_application_process_property_notify (app, xevent);
@@ -113,7 +113,7 @@ filter_func (GdkXEvent *gdkxevent,
{
WnckWindow *window;
- window = wnck_window_get (xevent->xconfigure.window);
+ window = wnck_handle_get_window (self, xevent->xconfigure.window);
if (window)
_wnck_window_process_configure_notify (window, xevent);
@@ -524,9 +524,21 @@ _wnck_handle_remove_class_group (WnckHandle *self,
g_hash_table_remove (self->class_group_hash, id);
}
+/**
+ * wnck_handle_get_class_group:
+ * @self: a #WnckHandle
+ * @id: identifier name of the sought resource class.
+ *
+ * Gets the #WnckClassGroup corresponding to @id.
+ *
+ * Returns: (transfer none): the #WnckClassGroup corresponding to
+ * @id, or %NULL if there is no #WnckClassGroup with the specified
+ * @id. The returned #WnckClassGroup is owned by libwnck and must not be
+ * referenced or unreferenced.
+ */
WnckClassGroup *
-_wnck_handle_get_class_group (WnckHandle *self,
- const char *id)
+wnck_handle_get_class_group (WnckHandle *self,
+ const char *id)
{
g_return_val_if_fail (WNCK_IS_HANDLE (self), NULL);
@@ -548,9 +560,23 @@ _wnck_handle_remove_application (WnckHandle *self,
g_hash_table_remove (self->app_hash, xwindow);
}
+
+/**
+ * wnck_handle_get_application:
+ * @self: a #WnckHandle
+ * @xwindow: the X window ID of a group leader.
+ *
+ * Gets the #WnckApplication corresponding to the group leader with @xwindow
+ * as X window ID.
+ *
+ * Returns: (transfer none): the #WnckApplication corresponding to
+ * @xwindow, or %NULL if there no such #WnckApplication could be found. The
+ * returned #WnckApplication is owned by libwnck and must not be referenced or
+ * unreferenced.
+ */
WnckApplication *
-_wnck_handle_get_application (WnckHandle *self,
- gulong xwindow)
+wnck_handle_get_application (WnckHandle *self,
+ gulong xwindow)
{
g_return_val_if_fail (WNCK_IS_HANDLE (self), NULL);
@@ -572,9 +598,21 @@ _wnck_handle_remove_window (WnckHandle *self,
g_hash_table_remove (self->window_hash, xwindow);
}
+/**
+ * wnck_handle_get_window:
+ * @self: a #WnckHandle
+ * @xwindow: an X window ID.
+ *
+ * Gets a preexisting #WnckWindow for the X window @xwindow. This will not
+ * create a #WnckWindow if none exists. The function is robust against bogus
+ * window IDs.
+ *
+ * Returns: (transfer none): the #WnckWindow for @xwindow. The returned
+ * #WnckWindow is owned by libwnck and must not be referenced or unreferenced.
+ */
WnckWindow *
-_wnck_handle_get_window (WnckHandle *self,
- gulong xwindow)
+wnck_handle_get_window (WnckHandle *self,
+ gulong xwindow)
{
g_return_val_if_fail (WNCK_IS_HANDLE (self), NULL);
diff --git a/libwnck/wnck-handle.h b/libwnck/wnck-handle.h
index a7b5c861..b58a47f0 100644
--- a/libwnck/wnck-handle.h
+++ b/libwnck/wnck-handle.h
@@ -31,21 +31,30 @@ G_BEGIN_DECLS
#define WNCK_TYPE_HANDLE (wnck_handle_get_type ())
G_DECLARE_FINAL_TYPE (WnckHandle, wnck_handle, WNCK, HANDLE, GObject)
-WnckHandle *wnck_handle_new (WnckClientType client_type);
+WnckHandle *wnck_handle_new (WnckClientType client_type);
-WnckScreen *wnck_handle_get_default_screen (WnckHandle *self);
+WnckScreen *wnck_handle_get_default_screen (WnckHandle *self);
-WnckScreen *wnck_handle_get_screen (WnckHandle *self,
- int index);
+WnckScreen *wnck_handle_get_screen (WnckHandle *self,
+ int index);
-WnckScreen *wnck_handle_get_screen_for_root (WnckHandle *self,
- gulong root_window_id);
+WnckScreen *wnck_handle_get_screen_for_root (WnckHandle *self,
+ gulong root_window_id);
-void wnck_handle_set_default_icon_size (WnckHandle *self,
- gsize icon_size);
+void wnck_handle_set_default_icon_size (WnckHandle *self,
+ gsize icon_size);
-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);
+
+WnckClassGroup *wnck_handle_get_class_group (WnckHandle *self,
+ const char *id);
+
+WnckApplication *wnck_handle_get_application (WnckHandle *self,
+ gulong xwindow);
+
+WnckWindow *wnck_handle_get_window (WnckHandle *self,
+ gulong xwindow);
G_END_DECLS
diff --git a/libwnck/wnckprop.c b/libwnck/wnckprop.c
index fa4844a6..a6622b54 100644
--- a/libwnck/wnckprop.c
+++ b/libwnck/wnckprop.c
@@ -291,7 +291,7 @@ static GOptionEntry space_entries[] = {
{ NULL }
};
-static void clean_up (void);
+static void clean_up (WnckHandle *handle);
/* this part is mostly stolen from xutils.c */
typedef struct
@@ -1708,8 +1708,9 @@ wm_state_set (Display *display,
}
static WnckWindow *
-find_managed_window (Display *display,
- Window window)
+find_managed_window (WnckHandle *handle,
+ Display *display,
+ Window window)
{
GdkDisplay *gdk_display;
Window root;
@@ -1720,7 +1721,7 @@ find_managed_window (Display *display,
int result;
if (wm_state_set (display, window))
- return wnck_window_get (window);
+ return wnck_handle_get_window (handle, window);
gdk_display = gdk_x11_lookup_xdisplay (display);
g_assert (gdk_display != NULL);
@@ -1736,11 +1737,11 @@ find_managed_window (Display *display,
{
if (wm_state_set (display, kids [i]))
{
- retval = wnck_window_get (kids [i]);
+ retval = wnck_handle_get_window (handle, kids [i]);
break;
}
- retval = find_managed_window (display, kids [i]);
+ retval = find_managed_window (handle, display, kids [i]);
if (retval != NULL)
break;
}
@@ -1752,12 +1753,14 @@ find_managed_window (Display *display,
}
static void
-handle_button_press_event (Display *dpy, XIDeviceEvent *event)
+handle_button_press_event (WnckHandle *handle,
+ Display *dpy,
+ XIDeviceEvent *event)
{
if (event->child == None)
return;
- got_from_user = find_managed_window (dpy, event->child);
+ got_from_user = find_managed_window (handle, dpy, event->child);
}
static GdkFilterReturn
@@ -1765,6 +1768,7 @@ target_filter (GdkXEvent *gdk_xevent,
GdkEvent *gdk_event,
gpointer data)
{
+ WnckHandle *handle = data;
XEvent *xevent = (XEvent *) gdk_xevent;
XGenericEventCookie *cookie = &xevent->xcookie;
@@ -1779,13 +1783,13 @@ target_filter (GdkXEvent *gdk_xevent,
switch (event->evtype)
{
case XI_ButtonPress:
- handle_button_press_event (cookie->display, event);
- clean_up ();
+ handle_button_press_event (handle, cookie->display, event);
+ clean_up (handle);
return GDK_FILTER_REMOVE;
case XI_KeyPress:
if (event->detail == XKeysymToKeycode (cookie->display, XK_Escape))
{
- clean_up ();
+ clean_up (handle);
return GDK_FILTER_REMOVE;
}
break;
@@ -1808,6 +1812,7 @@ prepare (GdkSeat *seat,
static gboolean
get_target (gpointer data)
{
+ WnckHandle *handle;
GdkWindow *root;
GdkDisplay *display;
GdkSeat *seat;
@@ -1815,13 +1820,15 @@ get_target (gpointer data)
GdkSeatCapabilities caps;
GdkGrabStatus status;
+ handle = data;
+
root = gdk_get_default_root_window ();
display = gdk_display_get_default ();
seat = gdk_display_get_default_seat (display);
cross = gdk_cursor_new_for_display (display, GDK_CROSS);
caps = GDK_SEAT_CAPABILITY_POINTER | GDK_SEAT_CAPABILITY_KEYBOARD;
- gdk_window_add_filter (root, (GdkFilterFunc) target_filter, NULL);
+ gdk_window_add_filter (root, (GdkFilterFunc) target_filter, handle);
status = gdk_seat_grab (seat, root, caps, TRUE, cross, NULL, prepare, NULL);
g_object_unref (cross);
@@ -1829,7 +1836,7 @@ get_target (gpointer data)
if (status != GDK_GRAB_SUCCESS)
{
g_warning ("Seat grab failed.");
- clean_up ();
+ clean_up (handle);
return FALSE;
}
@@ -1839,7 +1846,7 @@ get_target (gpointer data)
}
static void
-clean_up (void)
+clean_up (WnckHandle *handle)
{
GdkWindow *root;
GdkDisplay *display;
@@ -1849,7 +1856,7 @@ clean_up (void)
display = gdk_display_get_default ();
seat = gdk_display_get_default_seat (display);
- gdk_window_remove_filter (root, (GdkFilterFunc) target_filter, NULL);
+ gdk_window_remove_filter (root, (GdkFilterFunc) target_filter, handle);
gdk_seat_ungrab (seat);
gtk_main_quit ();
@@ -1966,7 +1973,7 @@ main (int argc, char **argv)
if (get_from_user)
{
- g_idle_add (get_target, NULL);
+ g_idle_add (get_target, handle);
gtk_main ();
@@ -2014,7 +2021,7 @@ main (int argc, char **argv)
if (got_from_user)
class_group = wnck_window_get_class_group (got_from_user);
else
- class_group = wnck_class_group_get (interact_class_group);
+ class_group = wnck_handle_get_class_group (handle, interact_class_group);
if (class_group)
{
@@ -2039,7 +2046,7 @@ main (int argc, char **argv)
if (got_from_user)
app = wnck_window_get_application (got_from_user);
else
- app = wnck_application_get (interact_app_xid);
+ app = wnck_handle_get_application (handle, interact_app_xid);
if (app)
{
@@ -2062,7 +2069,7 @@ main (int argc, char **argv)
if (got_from_user)
window = got_from_user;
else
- window = wnck_window_get (xid);
+ window = wnck_handle_get_window (handle, xid);
if (window)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]