From 606ca8f4504b9f85bf5510a68be2a7d88e365b91 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 9 Feb 2025 02:12:11 -0800 Subject: key: warp pointer to middle of focused window when chasing Now when holding down XK_m during focus changing operations the pointer will follow the focus, which should be handy on multihead. Also simply pressing Mod1+XK_m without doing anything else will chase the currently focused window, so you can bring the pointer where you are immediately on demand using the keyboard. --- src/key.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/key.c') diff --git a/src/key.c b/src/key.c index 4061236..bcf8903 100644 --- a/src/key.c +++ b/src/key.c @@ -492,6 +492,22 @@ void vwm_key_pressed(vwm_t *vwm, Window win, XKeyPressedEvent *keypress) break; } + /* if we're chasing focus with the pointer, center the pointer in the focused window */ + if (chase_it) { + /* We have to get the latest window attrs for this to always do the right thing, + * otherwise it's kind of racy as we've often _just_ changed window attrs, + * and want to query them to warp the pointer to the current configuration. + */ + XSync(VWM_XDISPLAY(vwm), False); + vwin = vwm_win_get_focused(vwm); + if (vwin) { + XWindowAttributes attrs; + + XGetWindowAttributes(VWM_XDISPLAY(vwm), vwin->xwindow->id, &attrs); + XWarpPointer(VWM_XDISPLAY(vwm), None, vwin->xwindow->id, 0, 0, 0, 0, attrs.width / 2, attrs.height / 2); + } + } + /* if what we're doing requests a grab, if not already grabbed, grab keyboard */ if (!key_is_grabbed && do_grab) { VWM_TRACE("saving focused_origin of %p", vwin); -- cgit v1.2.3