]> git.corax.cc Git - dwm/commitdiff
Move the pointer to the correct window when changing focus kbptr
authorMatthias Kruk <m@m10k.eu>
Sun, 28 Mar 2021 06:24:28 +0000 (15:24 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 28 Mar 2021 06:24:28 +0000 (15:24 +0900)
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.

dwm.c

diff --git a/dwm.c b/dwm.c
index 7359921f8d6acbc4f2b5ad5b709268002e4e3cd4..60e4104108981702b7e431c730a9ffcfe04c0d51 100755 (executable)
--- 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;
 }