From 63846be876e8cae7faf3d926ccd99dc149b6e7ff Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Thu, 17 Dec 2020 14:26:40 +0000 Subject: [PATCH] Applys warp patch --- dwm.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/dwm.c b/dwm.c index 131cab5..874f38a 100644 --- a/dwm.c +++ b/dwm.c @@ -237,6 +237,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); @@ -908,6 +909,7 @@ focusmon(const Arg *arg) unfocus(selmon->sel, 0); selmon = m; focus(NULL); + warp(selmon->sel); } void @@ -1475,6 +1477,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 @@ -2258,6 +2262,28 @@ swallowingclient(Window w) return NULL; } +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) {