From 667dbddff7a2656695fda5ea65529b918713359d Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 14 Aug 2016 19:09:31 -0700 Subject: Set input focus in vwm_win_focus() when is_mapped() It's inappropriate to assume the window being focused is in the visible context. This caused the input focus to spuriously vanish if a window on another desktop went away causing the next one, also invisible, to get focused. I'm surprised how long I went without ever noticing this bug! My workflow basically never has windows vanishing that aren't in the focused context. --- vwm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/vwm.c b/vwm.c index 3b16d8c..2f31f9d 100644 --- a/vwm.c +++ b/vwm.c @@ -1702,13 +1702,15 @@ static void vwm_win_autoconf(vwm_window_t *vwin, vwm_screen_rel_t rel, vwm_win_a /* focus a window */ -/* this updates window border color as needed and the X input focus */ +/* this updates window border color as needed and the X input focus if mapped */ static void vwm_win_focus(vwm_window_t *vwin) { VWM_TRACE("focusing: %#x", (unsigned int)vwin->xwindow->id); - /* change the focus to the new window */ - XSetInputFocus(display, vwin->xwindow->id, RevertToPointerRoot, CurrentTime); + if(vwm_xwin_is_mapped(vwin->xwindow)) { + /* if vwin is mapped give it the input focus */ + XSetInputFocus(display, vwin->xwindow->id, RevertToPointerRoot, CurrentTime); + } /* update the border color accordingly */ if(vwin->shelved) { @@ -1717,17 +1719,16 @@ static void vwm_win_focus(vwm_window_t *vwin) /* fullscreen windows in the shelf when focused, since we don't intend to overlap there */ vwm_win_autoconf(vwin, VWM_SCREEN_REL_POINTER, VWM_WIN_AUTOCONF_FULL); /* XXX TODO: for now the shelf follows the pointer, it's simple. */ } else { - if(vwin->desktop == focused_desktop && focused_desktop->focused_window) { - /* if we've changed focus within the same desktop, set the currently focused window border to the - * unfocused color. Otherwise, we want to leave the focused color on the old window on the old desktop */ - XSetWindowBorder(display, focused_desktop->focused_window->xwindow->id, unfocused_window_border_color.pixel); + if(vwin->desktop->focused_window) { + /* set the border of the previously focused window on the same desktop to the unfocused color */ + XSetWindowBorder(display, vwin->desktop->focused_window->xwindow->id, unfocused_window_border_color.pixel); } /* set the border of the newly focused window to the focused color */ XSetWindowBorder(display, vwin->xwindow->id, focused_window_border_color.pixel); /* persist this on a per-desktop basis so it can be restored on desktop switches */ - focused_desktop->focused_window = vwin; + vwin->desktop->focused_window = vwin; } } -- cgit v1.2.3