aboutsummaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2021-12-15 21:25:09 +0100
committerRomain Gonçalves <me@rgoncalves.se>2021-12-15 21:25:09 +0100
commit018f43edb995e24b036841462db019456f28533b (patch)
tree76b9211f06cdcf3ac1862bd46e025c6b7a670b7a /dwm.c
parent8c47572f9b377066adc1046e51d1bbae2bbf3bb4 (diff)
downloaddwm-018f43edb995e24b036841462db019456f28533b.tar.gz
patches: Add warp for automatically moving mouse
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/dwm.c b/dwm.c
index c589809..e23be38 100644
--- a/dwm.c
+++ b/dwm.c
@@ -229,6 +229,7 @@ static void updatetitle(Client *c);
static void updatewindowtype(Client *c);
static void updatewmhints(Client *c);
static void view(const Arg *arg);
+static void warp(const Client *c);
static Client *wintoclient(Window w);
static Monitor *wintomon(Window w);
static int xerror(Display *dpy, XErrorEvent *ee);
@@ -829,6 +830,7 @@ focusmon(const Arg *arg)
unfocus(selmon->sel, 0);
selmon = m;
focus(NULL);
+ warp(selmon->sel);
}
void
@@ -1369,6 +1371,8 @@ restack(Monitor *m)
}
XSync(dpy, False);
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+ if (m == selmon && (m->tagset[m->seltags] & m->sel->tags) && selmon->lt[selmon->sellt] != &layouts[2])
+ warp(m->sel);
}
void
@@ -2057,6 +2061,28 @@ view(const Arg *arg)
arrange(selmon);
}
+void
+warp(const Client *c)
+{
+ int x, y;
+
+ if (!c) {
+ XWarpPointer(dpy, None, root, 0, 0, 0, 0, selmon->wx + selmon->ww/2, selmon->wy + selmon->wh/2);
+ return;
+ }
+
+ if (!getrootptr(&x, &y) ||
+ (x > c->x - c->bw &&
+ y > c->y - c->bw &&
+ x < c->x + c->w + c->bw*2 &&
+ y < c->y + c->h + c->bw*2) ||
+ (y > c->mon->by && y < c->mon->by + bh) ||
+ (c->mon->topbar && !y))
+ return;
+
+ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
+}
+
Client *
wintoclient(Window w)
{
remember that computers suck.