From e17db88db54aafd9298c6db48a48569840acd328 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 24 Mar 2017 22:15:37 -0700 Subject: xevent: use vwm_win_map() instead of XMapWindow() In vwm_xevent_handle_map_request() XMapWindow was always directly being called. When we have a vwin, we really shouldn't be calling XMapWindow() since we can't detect the generated MapNotify like we can with vwm_win_map(). --- src/xevent.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/xevent.c b/src/xevent.c index fcbb551..d082f9a 100644 --- a/src/xevent.c +++ b/src/xevent.c @@ -176,32 +176,40 @@ void vwm_xevent_handle_map_request(vwm_t *vwm, XMapRequestEvent *ev) vwm_window_t *vwin = NULL; int domap = 1; - if ((xwin = vwm_xwin_lookup(vwm, ev->window)) && !(vwin = xwin->managed)) { - /* Basically all managed windows become managed on the map request, - * even previously managed ones are unmanaged on unmap, then remanaged - * on subsequent map request. Exceptions are preexisting windows that - * are already mapped at create time, those won't generate map requests - * but are managed at create. - */ - vwin = vwm_win_manage_xwin(vwm, xwin); - VWM_TRACE("managed xwin \"%s\" at map request", xwin->name); - } - - /* XXX: note that _normally_ both xwin and vwin should be non-NULL here, and - * the care being taken WRT !xwin or !vwin is purely defensive to permit the - * default of simply mapping windows on request when things are broken. - */ - + xwin = vwm_xwin_lookup(vwm, ev->window); if (xwin) { xwin->mapped = 1; + + if (!(vwin = xwin->managed)) { + /* Basically all managed windows become managed on the map request, + * even previously managed ones are unmanaged on unmap, then remanaged + * on subsequent map request. Exceptions are preexisting windows that + * are already mapped at create time, those won't generate map requests + * but are managed at create. + */ + vwin = vwm_win_manage_xwin(vwm, xwin); + VWM_TRACE("managed xwin \"%s\" at map request", xwin->name); + } + + /* XXX: note that _normally_ both xwin and vwin should be non-NULL here, and + * the care being taken WRT !xwin or !vwin is purely defensive to permit the + * default of simply mapping windows on request when things are broken. + */ + domap = vwm_xwin_is_mapped(vwm, xwin); } if (domap) { - XMapWindow(VWM_XDISPLAY(vwm), ev->window); - if (vwin && vwin->desktop->focused_window == vwin) { - XSync(VWM_XDISPLAY(vwm), False); - XSetInputFocus(VWM_XDISPLAY(vwm), vwin->xwindow->id, RevertToPointerRoot, CurrentTime); + if (vwin) { + vwm_win_map(vwm, vwin); + + /* XSetInputFocus() must to happen after XMapWindow(), so do it here. */ + if (vwm_win_focused(vwm) == vwin) + XSetInputFocus(VWM_XDISPLAY(vwm), vwin->xwindow->id, RevertToPointerRoot, CurrentTime); + } else { + /* this is unexpected */ + XMapWindow(VWM_XDISPLAY(vwm), ev->window); + VWM_BUG("handled map request of unmanaged window vwin=%p xwin=%p id=%u", vwin, xwin, ev->window); } } } -- cgit v1.2.3