From: Matthias Kruk Date: Sun, 28 Mar 2021 06:24:28 +0000 (+0900) Subject: Move the pointer to the correct window when changing focus X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=ef336cc63f252a58a152b61ad4b31c3049449221;p=dwm Move the pointer to the correct window when changing focus Changing the focus via the keyboard moves the pointer to the wrong window because selmon->sel isn't changed where I expected it to be changed. This commit addresses the issue by moving the pointer to the client passed to the setfocus() function instead of using the client in selmon->sel. --- diff --git a/dwm.c b/dwm.c index 7359921..60e4104 100755 --- a/dwm.c +++ b/dwm.c @@ -262,6 +262,7 @@ struct kbptr { }; static void kbptr_move(const union arg *arg); +static void kbptr_move_on(struct client *client, const union arg *arg); static void kbptr_click(const union arg *arg); static struct kbptr kbptr = { 0, 0, 0, 0 }; @@ -2158,17 +2159,15 @@ Bool sendevent(Window w, Atom proto, int mask, long d0, long d1, long d2, long d return(exists); } -static void kbptr_move(const union arg *arg) +static void kbptr_move_on(struct client *client, const union arg *arg) { - struct client *client; unsigned int dir; unsigned int stepsize; - if(!selmon || !selmon->sel) { + if(!client || !arg) { return; } - client = selmon->sel; dir = arg->ui & KBPTR_DMASK; stepsize = arg->ui & KBPTR_HALFSTEP; @@ -2215,6 +2214,16 @@ static void kbptr_move(const union arg *arg) return; } +static void kbptr_move(const union arg *arg) +{ + if(!selmon || !selmon->sel) { + return; + } + + kbptr_move_on(selmon->sel, arg); + return; +} + static int do_button(struct client *client, const unsigned int button, const unsigned int pressrelease) @@ -2300,18 +2309,17 @@ static void kbptr_click(const union arg *arg) void setfocus(struct client *c) { - union arg ptr_dest; + union arg ptrdst = { .ui = KBPTR_CENTER }; if(!c->neverfocus) { XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); } - ptr_dest.ui = KBPTR_CENTER; - kbptr_move(&ptr_dest); - sendevent(c->win, wmatom[WMTakeFocus], NoEventMask, wmatom[WMTakeFocus], CurrentTime, 0, 0, 0); + kbptr_move_on(c, &ptrdst); + return; }