diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2017-10-05 16:48:58 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2017-10-05 16:53:35 -0700 |
commit | 7096b3b6c1325630d18e5d61aac58f9c3772b8e1 (patch) | |
tree | 2b615b2bbf82b7c1463e01ed0e73cacf6896c397 /src | |
parent | 29fa9c0870eebc152a92da2290e405be6e37fc56 (diff) |
window: split out focused window setter
vwm_win_focus() previously simultaneously told the X server to set the
input focus on the window (if mapped) and set the internal vwm state of
the window to focused.
These are really two separate operations:
1. request the X server to focus the window
2. change vwm's concept of the currently focused window
Since clients can call XSetInputFocus() as well, there's need for doing
step 2 discretely in response to FocusIn events.
Nothing is functionally different after this commit, it just exposes
step 2 as a separate vwm_win_set_focused() function for a future commit
to leverage in handling of FocusIn events.
Diffstat (limited to 'src')
-rw-r--r-- | src/window.c | 48 | ||||
-rw-r--r-- | src/window.h | 1 |
2 files changed, 28 insertions, 21 deletions
diff --git a/src/window.c b/src/window.c index 5827d0b..953590d 100644 --- a/src/window.c +++ b/src/window.c @@ -97,6 +97,31 @@ vwm_window_t * vwm_win_get_focused(vwm_t *vwm) } +/* set the currently focused window */ +/* this sets our internal state of which window is focused, and updates window border color as needed */ +/* note X input focus is not affected by this. */ +void vwm_win_set_focused(vwm_t *vwm, vwm_window_t *vwin) +{ + /* update the border color accordingly */ + if (vwin->shelved) { + /* set the border of the newly focused window to the shelved color */ + XSetWindowBorder(VWM_XDISPLAY(vwm), vwin->xwindow->id, vwin == vwm->console ? vwm->colors.shelved_console_border_color.pixel : vwm->colors.shelved_window_border_color.pixel); + /* fullscreen windows in the shelf when focused, since we don't intend to overlap there */ + vwm_win_autoconf(vwm, 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_window) + /* set the border of the previously focused window on the same desktop to the unfocused color */ + XSetWindowBorder(VWM_XDISPLAY(vwm), vwin->desktop->focused_window->xwindow->id, vwm->colors.unfocused_window_border_color.pixel); + + /* set the border of the newly focused window to the focused color */ + XSetWindowBorder(VWM_XDISPLAY(vwm), vwin->xwindow->id, vwm->colors.focused_window_border_color.pixel); + + /* persist this on a per-desktop basis so it can be restored on desktop switches */ + vwin->desktop->focused_window = vwin; + } +} + + /* "autoconfigure" windows (configuration shortcuts like fullscreen/halfscreen/quarterscreen) and restoring the window */ void vwm_win_autoconf(vwm_t *vwm, vwm_window_t *vwin, vwm_screen_rel_t rel, vwm_win_autoconf_t conf, ...) { @@ -203,33 +228,14 @@ void vwm_win_autoconf(vwm_t *vwm, vwm_window_t *vwin, vwm_screen_rel_t rel, vwm_ /* focus a window */ -/* this updates window border color as needed and the X input focus if mapped */ void vwm_win_focus(vwm_t *vwm, vwm_window_t *vwin) { VWM_TRACE("focusing: %#x", (unsigned int)vwin->xwindow->id); - if (vwm_xwin_is_mapped(vwm, vwin->xwindow)) { - /* if vwin is mapped give it the input focus */ + if (vwm_xwin_is_mapped(vwm, vwin->xwindow)) /* note X only allows mapped windows to have input focus */ XSetInputFocus(VWM_XDISPLAY(vwm), vwin->xwindow->id, RevertToPointerRoot, CurrentTime); - } - /* update the border color accordingly */ - if (vwin->shelved) { - /* set the border of the newly focused window to the shelved color */ - XSetWindowBorder(VWM_XDISPLAY(vwm), vwin->xwindow->id, vwin == vwm->console ? vwm->colors.shelved_console_border_color.pixel : vwm->colors.shelved_window_border_color.pixel); - /* fullscreen windows in the shelf when focused, since we don't intend to overlap there */ - vwm_win_autoconf(vwm, 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_window) - /* set the border of the previously focused window on the same desktop to the unfocused color */ - XSetWindowBorder(VWM_XDISPLAY(vwm), vwin->desktop->focused_window->xwindow->id, vwm->colors.unfocused_window_border_color.pixel); - - /* set the border of the newly focused window to the focused color */ - XSetWindowBorder(VWM_XDISPLAY(vwm), vwin->xwindow->id, vwm->colors.focused_window_border_color.pixel); - - /* persist this on a per-desktop basis so it can be restored on desktop switches */ - vwin->desktop->focused_window = vwin; - } + vwm_win_set_focused(vwm, vwin); } diff --git a/src/window.h b/src/window.h index 4d75440..c177b48 100644 --- a/src/window.h +++ b/src/window.h @@ -43,6 +43,7 @@ void vwm_win_map(vwm_t *vwm, vwm_window_t *vwin); void vwm_win_mru(vwm_t *vwm, vwm_window_t *vwin); vwm_window_t * vwm_win_lookup(vwm_t *vwm, Window win); vwm_window_t * vwm_win_get_focused(vwm_t *vwm); +void vwm_win_set_focused(vwm_t *vwm, vwm_window_t *vwin); typedef enum _vwm_side_t { VWM_SIDE_TOP, |