From d82d349daa3fdccbef0186ae19311004c4bb2434 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 15 Feb 2015 03:57:49 +0100 Subject: be slightly more reliable when following destroyed windows --- libtopmenu-server/topmenu-widget.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'libtopmenu-server') diff --git a/libtopmenu-server/topmenu-widget.c b/libtopmenu-server/topmenu-widget.c index 9c8092b..762a792 100644 --- a/libtopmenu-server/topmenu-widget.c +++ b/libtopmenu-server/topmenu-widget.c @@ -232,13 +232,22 @@ static gboolean topmenu_widget_follow_window(TopMenuWidget *self, Window window) return FALSE; // Ignore the window this widget is on as a candidate } - // Add this window to the list of windows we are following - g_queue_push_head(&self->priv->followed_windows, GSIZE_TO_POINTER(window)); - + gdk_error_trap_push(); XWindowAttributes win_attrs; if (XGetWindowAttributes(dpy, window, &win_attrs)) { - XSelectInput(dpy, window, win_attrs.your_event_mask | PropertyChangeMask); + long event_mask = win_attrs.your_event_mask | StructureNotifyMask | PropertyChangeMask; + if (event_mask != win_attrs.your_event_mask) { + XSelectInput(dpy, window, event_mask); + } } + gdk_flush(); + if (gdk_error_trap_pop()) { + g_debug("got error while trying to follow window 0x%lx", window); + return FALSE; // Assume window has been destroyed. + } + + // Add this window to the list of windows we are following + g_queue_push_head(&self->priv->followed_windows, GSIZE_TO_POINTER(window)); if (topmenu_widget_try_window(self, window)) { // Found a menu bar on this window -- cgit v1.2.3