From c5c8786363705488e58c6af137738d6ba75315b7 Mon Sep 17 00:00:00 2001 From: o9000 Date: Sun, 20 Mar 2016 15:48:48 +0100 Subject: [PATCH] systray: Fix race in sorting icons by name --- src/systray/systraybar.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 2faa007..b687ecb 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -526,6 +526,13 @@ gboolean add_icon(Window win) } } + // Dangerous actions begin + XSync(server.display, False); + error = FALSE; + XErrorHandler old = XSetErrorHandler(window_error_handler); + + XSelectInput(server.display, win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask); + XTextProperty xname; char *name; if (XGetWMName(server.display, win, &xname)) { @@ -571,8 +578,19 @@ gboolean add_icon(Window win) fprintf(stderr, "XGetWindowAttributes(server.display, win = %ld, &attr)\n", win); if (XGetWindowAttributes(server.display, win, &attr) == False) { free(name); + XSelectInput(server.display, win, NoEventMask); + + // Dangerous actions end + XSync(server.display, False); + XSetErrorHandler(old); + return FALSE; } + + // Dangerous actions end + XSync(server.display, False); + XSetErrorHandler(old); + unsigned long mask = 0; XSetWindowAttributes set_attr; Visual *visual = server.visual; @@ -606,6 +624,7 @@ gboolean add_icon(Window win) mask = CWBackPixmap; } } + if (systray_profile) fprintf(stderr, "XCreateWindow(...)\n"); Window parent = XCreateWindow(server.display, @@ -683,9 +702,6 @@ gboolean reparent_icon(TrayWindow *traywin) XSync(server.display, False); error = FALSE; XErrorHandler old = XSetErrorHandler(window_error_handler); - if (systray_profile) - fprintf(stderr, "XSelectInput(server.display, traywin->win, ...)\n"); - XSelectInput(server.display, traywin->win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask); XWithdrawWindow(server.display, traywin->win, server.screen); XReparentWindow(server.display, traywin->win, traywin->parent, 0, 0);