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.
This commit is contained in:
Matthias Clasen 2017-08-22 15:08:14 -04:00
parent 5bd8884bf8
commit 9f6b556dc2
4 changed files with 38 additions and 45 deletions

View File

@ -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);

View File

@ -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 */

View File

@ -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;
}
}

View File

@ -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 */