From fdb1d2c7485c62f3c47e8b14b2807372c240d84a Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Thu, 22 Jul 2010 22:07:26 +0200 Subject: [PATCH] Systray: Fix BadWindow (because of unmap event) and segfault at pressing button --- src/event.c | 14 ++------------ src/systray.c | 13 ++++++------- src/wmfs.c | 12 +++++++----- src/wmfs.h | 2 +- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/event.c b/src/event.c index 3b80d96..979e53f 100644 --- a/src/event.c +++ b/src/event.c @@ -350,7 +350,7 @@ destroynotify(XDestroyWindowEvent *ev) else if((s = systray_find(ev->window))) { setwinstate(s->win, WithdrawnState); - systray_del(s->win); + systray_del(s); systray_update(); } @@ -480,20 +480,11 @@ keypress(XKeyPressedEvent *ev) void mappingnotify(XMappingEvent *ev) { - Systray *s; - XRefreshKeyboardMapping(ev); if(ev->request == MappingKeyboard) grabkeys(); - if(!(s = systray_find(ev->window))) - { - setwinstate(s->win, NormalState); - ewmh_send_message(s->win, s->win, "_XEMBED", CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, 0, 0); - } - - return; } @@ -650,8 +641,7 @@ unmapnotify(XUnmapEvent *ev) if((s = systray_find(ev->window))) { - setwinstate(s->win, WithdrawnState); - systray_del(s->win); + systray_del(s); systray_update(); } diff --git a/src/systray.c b/src/systray.c index 931fa12..fcf6d20 100644 --- a/src/systray.c +++ b/src/systray.c @@ -97,7 +97,7 @@ systray_add(Window win) setwinstate(s->win, WithdrawnState); XSelectInput(dpy, s->win, StructureNotifyMask | PropertyChangeMask| EnterWindowMask | FocusChangeMask); - XReparentWindow(dpy, s->win, traywin, 0, 0); + XReparentWindow(dpy, s->win, traywin, 0, 0); ewmh_send_message(s->win, s->win, "_XEMBED", CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0, traywin, 0); @@ -112,15 +112,14 @@ systray_add(Window win) } void -systray_del(Window win) +systray_del(Systray *s) { - Systray *t, **ss; + Systray **ss; - if(!(t = systray_find(win))) - return; + for(ss = &trayicons; *ss && *ss != s; ss = &(*ss)->next); + *ss = s->next; - for(ss = &trayicons; *ss && *ss != t; ss = &(*ss)->next); - *ss = t->next; + IFREE(s); return; } diff --git a/src/wmfs.c b/src/wmfs.c index 43db14d..8e7a3f2 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -210,7 +210,6 @@ scan(void) Atom rt; int s, rf, tag = -1, screen = -1, free = -1; ulong ir, il; - long flags; uchar *ret; Client *c; @@ -218,12 +217,14 @@ scan(void) if(XQueryTree(dpy, ROOT, &usl, &usl2, &w, &n)) for(i = n - 1; i != -1; --i) - if(XGetWindowAttributes(dpy, w[i], &wa) - && !(wa.override_redirect || XGetTransientForHint(dpy, w[i], &usl)) + { + XGetWindowAttributes(dpy, w[i], &wa); + + if(!wa.override_redirect/* || XGetTransientForHint(dpy, w[i], &usl))*/ && wa.map_state == IsViewable) { - if((flags = ewmh_get_xembed_state(w[i]))) - systray_add(w[i]); + if(ewmh_get_xembed_state(w[i])) + systray_add(w[i]); if(XGetWindowProperty(dpy, w[i], ATOM("_WMFS_TAG"), 0, 32, False, XA_CARDINAL, &rt, &rf, &ir, &il, &ret) == Success && ret) @@ -257,6 +258,7 @@ scan(void) client_update_attributes(c); } + } /* Set update layout request */ for(c = clients; c; c = c->next) diff --git a/src/wmfs.h b/src/wmfs.h index e7227aa..360c04d 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -352,7 +352,7 @@ Bool systray_acquire(void); void systray_init(void); void systray_kill(void); void systray_add(Window win); -void systray_del(Window win); +void systray_del(Systray *s); void systray_configure(Systray *s); void systray_state(Systray *s); void systray_freeicons(void);