dwm-warp-6.4.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-warp-6.4.diff (2082B)
       ---
            1 From a229c36f51ad6f8b40109ed53c643f242351962a Mon Sep 17 00:00:00 2001
            2 From: Jonas Dujava <jonas.dujava@gmail.com>
            3 Date: Fri, 26 May 2023 22:14:48 +0200
            4 Subject: [PATCH] Warp patch
            5 
            6 Warps the mouse cursor to the center of the currently focused
            7 window or screen when the mouse cursor is
            8   (a) on a different screen, or
            9   (b) on top of a different window.
           10 
           11 This version properly handles warping to windows that have not been
           12 mapped yet (before it resulted in a change of the stack order).
           13 See the discussion in (thanks goes to Bakkeby):
           14     https://github.com/bakkeby/patches/issues/60
           15 ---
           16  dwm.c | 26 ++++++++++++++++++++++++++
           17  1 file changed, 26 insertions(+)
           18 
           19 diff --git a/dwm.c b/dwm.c
           20 index e5efb6a..7ea6c14 100644
           21 --- a/dwm.c
           22 +++ b/dwm.c
           23 @@ -228,6 +228,7 @@ static void updatetitle(Client *c);
           24  static void updatewindowtype(Client *c);
           25  static void updatewmhints(Client *c);
           26  static void view(const Arg *arg);
           27 +static void warp(const Client *c);
           28  static Client *wintoclient(Window w);
           29  static Monitor *wintomon(Window w);
           30  static int xerror(Display *dpy, XErrorEvent *ee);
           31 @@ -834,6 +835,7 @@ focusmon(const Arg *arg)
           32          unfocus(selmon->sel, 0);
           33          selmon = m;
           34          focus(NULL);
           35 +        warp(selmon->sel);
           36  }
           37  
           38  void
           39 @@ -1366,6 +1368,8 @@ restack(Monitor *m)
           40                                  wc.sibling = c->win;
           41                          }
           42          }
           43 +        if (m == selmon && (m->tagset[m->seltags] & m->sel->tags) && m->lt[m->sellt]->arrange != &monocle)
           44 +                warp(m->sel);
           45          XSync(dpy, False);
           46          while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
           47  }
           48 @@ -2044,6 +2048,28 @@ view(const Arg *arg)
           49          arrange(selmon);
           50  }
           51  
           52 +void
           53 +warp(const Client *c)
           54 +{
           55 +        int x, y;
           56 +
           57 +        if (!c) {
           58 +                XWarpPointer(dpy, None, root, 0, 0, 0, 0, selmon->wx + selmon->ww / 2, selmon->wy + selmon->wh / 2);
           59 +                return;
           60 +        }
           61 +
           62 +        if (!getrootptr(&x, &y) ||
           63 +                (x > c->x - c->bw &&
           64 +                 y > c->y - c->bw &&
           65 +                 x < c->x + c->w + c->bw*2 &&
           66 +                 y < c->y + c->h + c->bw*2) ||
           67 +                (y > c->mon->by && y < c->mon->by + bh) ||
           68 +                (c->mon->topbar && !y))
           69 +                return;
           70 +
           71 +        XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
           72 +}
           73 +
           74  Client *
           75  wintoclient(Window w)
           76  {
           77 -- 
           78 2.40.1
           79