[gtk+] Stop using foreign windows for xsettings



commit 9f6b556dc29d93713aae2bb0279cd0fa15500310
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Aug 22 15:08:14 2017 -0400

    Stop using foreign windows for xsettings
    
    Stop wrapping the xsettings manager window in a foreign
    window. This means that we cannot use the gdk window filter
    APIs anymore, so just do the filtering in a non-generic
    way.

 gdk/x11/gdkeventsource.c   |   15 ++++++++++-
 gdk/x11/gdkscreen-x11.h    |    2 +-
 gdk/x11/xsettings-client.c |   58 +++++++++++--------------------------------
 gdk/x11/xsettings-client.h |    8 ++++++
 4 files changed, 38 insertions(+), 45 deletions(-)
---
diff --git a/gdk/x11/gdkeventsource.c b/gdk/x11/gdkeventsource.c
index a088cb0..0e7657d 100644
--- a/gdk/x11/gdkeventsource.c
+++ b/gdk/x11/gdkeventsource.c
@@ -22,6 +22,7 @@
 #include "gdkinternals.h"
 #include "gdkwindow-x11.h"
 #include "gdkprivate-x11.h"
+#include "xsettings-client.h"
 
 
 static gboolean gdk_event_source_prepare  (GSource     *source,
@@ -271,6 +272,9 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
   GdkEventTranslator *event_translator;
   GdkWindow *filter_window;
   Display *dpy;
+  GdkX11Screen *x11_screen;
+
+  x11_screen = (GdkX11Screen*)gdk_display_get_default_screen (event_source->display);
 
   dpy = GDK_DISPLAY_XDISPLAY (event_source->display);
 
@@ -287,8 +291,17 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
   if (filter_window)
     event->any.window = g_object_ref (filter_window);
 
+  /* apply XSettings filters */
+  if (xevent->xany.window == XRootWindow (dpy, 0))
+    result = gdk_xsettings_root_window_filter (xevent, event, x11_screen);
+
+  if (result == GDK_FILTER_CONTINUE &&
+      xevent->xany.window == x11_screen->xsettings_manager_window)
+    result = gdk_xsettings_manager_window_filter (xevent, event, x11_screen);
+
   /* Run default filters */
-  if (_gdk_default_filters)
+  if (result == GDK_FILTER_CONTINUE &&
+      _gdk_default_filters)
     {
       /* Apply global filters */
       result = gdk_event_apply_filters (xevent, event, NULL);
diff --git a/gdk/x11/gdkscreen-x11.h b/gdk/x11/gdkscreen-x11.h
index 4ed6cc9..fa7b873 100644
--- a/gdk/x11/gdkscreen-x11.h
+++ b/gdk/x11/gdkscreen-x11.h
@@ -59,7 +59,7 @@ struct _GdkX11Screen
   char *window_manager_name;
 
   /* X Settings */
-  GdkWindow *xsettings_manager_window;
+  Window xsettings_manager_window;
   Atom xsettings_selection_atom;
   GHashTable *xsettings; /* string of GDK settings name => GValue */
 
diff --git a/gdk/x11/xsettings-client.c b/gdk/x11/xsettings-client.c
index cc21636..5275b19 100644
--- a/gdk/x11/xsettings-client.c
+++ b/gdk/x11/xsettings-client.c
@@ -413,13 +413,13 @@ read_settings (GdkX11Screen *x11_screen,
 
   x11_screen->xsettings = NULL;
 
-  if (x11_screen->xsettings_manager_window)
+  if (x11_screen->xsettings_manager_window != 0)
     {
       Atom xsettings_atom = gdk_x11_get_xatom_by_name_for_display (display, "_XSETTINGS_SETTINGS");
 
       gdk_x11_display_error_trap_push (display);
       result = XGetWindowProperty (gdk_x11_display_get_xdisplay (display),
-                                   gdk_x11_window_get_xid (x11_screen->xsettings_manager_window),
+                                   x11_screen->xsettings_manager_window,
                                   xsettings_atom, 0, LONG_MAX,
                                   False, xsettings_atom,
                                   &type, &format, &n_items, &bytes_after, &data);
@@ -475,53 +475,33 @@ get_selection_atom (GdkX11Screen *x11_screen)
   return _gdk_x11_get_xatom_for_display_printf (x11_screen->display, "_XSETTINGS_S%d", 
x11_screen->screen_num);
 }
 
-static GdkFilterReturn
-gdk_xsettings_manager_window_filter (GdkXEvent *xevent,
-                                     GdkEvent  *event,
-                                     gpointer   data);
-
 static void
 check_manager_window (GdkX11Screen *x11_screen,
                       gboolean      notify_changes)
 {
   GdkDisplay *display;
   Display *xdisplay;
-  Window manager_window_xid;
 
   display = x11_screen->display;
   xdisplay = gdk_x11_display_get_xdisplay (display);
 
-  if (x11_screen->xsettings_manager_window)
-    {
-      gdk_window_remove_filter (x11_screen->xsettings_manager_window, gdk_xsettings_manager_window_filter, 
x11_screen);
-      g_object_unref (x11_screen->xsettings_manager_window);
-    }
-
   gdk_x11_display_grab (display);
 
-  manager_window_xid = XGetSelectionOwner (xdisplay, get_selection_atom (x11_screen));
-  x11_screen->xsettings_manager_window = gdk_x11_window_foreign_new_for_display (display,
-                                                                   manager_window_xid);
-  /* XXX: Can't use gdk_window_set_events() here because the first call to this
-   * function happens too early in gdk_init() */
-  if (x11_screen->xsettings_manager_window)
+  x11_screen->xsettings_manager_window = XGetSelectionOwner (xdisplay, get_selection_atom (x11_screen));
+
+  if (x11_screen->xsettings_manager_window != 0)
     XSelectInput (xdisplay,
-                  gdk_x11_window_get_xid (x11_screen->xsettings_manager_window),
+                  x11_screen->xsettings_manager_window,
                   PropertyChangeMask | StructureNotifyMask);
 
   gdk_x11_display_ungrab (display);
-  
+
   gdk_display_flush (display);
 
-  if (x11_screen->xsettings_manager_window)
-    {
-      gdk_window_add_filter (x11_screen->xsettings_manager_window, gdk_xsettings_manager_window_filter, 
x11_screen);
-    }
-      
   read_settings (x11_screen, notify_changes);
 }
 
-static GdkFilterReturn
+GdkFilterReturn
 gdk_xsettings_root_window_filter (GdkXEvent *xevent,
                                   GdkEvent  *event,
                                   gpointer   data)
@@ -542,11 +522,11 @@ gdk_xsettings_root_window_filter (GdkXEvent *xevent,
       check_manager_window (x11_screen, TRUE);
       return GDK_FILTER_REMOVE;
     }
-  
+
   return GDK_FILTER_CONTINUE;
 }
 
-static GdkFilterReturn
+GdkFilterReturn
 gdk_xsettings_manager_window_filter (GdkXEvent *xevent,
                                      GdkEvent  *event,
                                      gpointer   data)
@@ -558,22 +538,20 @@ gdk_xsettings_manager_window_filter (GdkXEvent *xevent,
     {
       check_manager_window (x11_screen, TRUE);
       /* let GDK do its cleanup */
-      return GDK_FILTER_CONTINUE; 
+      return GDK_FILTER_CONTINUE;
     }
   else if (xev->xany.type == PropertyNotify)
     {
       read_settings (x11_screen, TRUE);
       return GDK_FILTER_REMOVE;
     }
-  
-  return GDK_FILTER_CONTINUE;;
+
+  return GDK_FILTER_CONTINUE;
 }
 
 void
 _gdk_x11_xsettings_init (GdkX11Screen *x11_screen)
 {
-  gdk_window_add_filter (gdk_display_get_root_window (x11_screen->display), 
gdk_xsettings_root_window_filter, x11_screen);
-
   check_manager_window (x11_screen, FALSE);
 }
 
@@ -586,18 +564,12 @@ _gdk_x11_settings_force_reread (GdkX11Screen *x11_screen)
 void
 _gdk_x11_xsettings_finish (GdkX11Screen *x11_screen)
 {
-  gdk_window_remove_filter (gdk_display_get_root_window (x11_screen->display), 
gdk_xsettings_root_window_filter, x11_screen);
   if (x11_screen->xsettings_manager_window)
-    {
-      gdk_window_remove_filter (x11_screen->xsettings_manager_window, gdk_xsettings_manager_window_filter, 
x11_screen);
-      g_object_unref (x11_screen->xsettings_manager_window);
-      x11_screen->xsettings_manager_window = NULL;
-    }
-  
+    x11_screen->xsettings_manager_window = 0;
+
   if (x11_screen->xsettings)
     {
       g_hash_table_unref (x11_screen->xsettings);
       x11_screen->xsettings = NULL;
     }
 }
-
diff --git a/gdk/x11/xsettings-client.h b/gdk/x11/xsettings-client.h
index 89adc7d..aacac57 100644
--- a/gdk/x11/xsettings-client.h
+++ b/gdk/x11/xsettings-client.h
@@ -29,4 +29,12 @@ void _gdk_x11_xsettings_init            (GdkX11Screen        *x11_screen);
 void _gdk_x11_xsettings_finish          (GdkX11Screen        *x11_screen);
 void _gdk_x11_settings_force_reread     (GdkX11Screen        *x11_screen);
 
+GdkFilterReturn gdk_xsettings_root_window_filter    (GdkXEvent *xevent,
+                                                     GdkEvent  *event,
+                                                     gpointer   data);
+GdkFilterReturn gdk_xsettings_manager_window_filter (GdkXEvent *xevent,
+                                                     GdkEvent  *event,
+                                                     gpointer   data);
+
+
 #endif /* XSETTINGS_CLIENT_H */


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