Compare commits

..

2 Commits

Author SHA1 Message Date
Jakub
4f9dcc5d42 make window follow patch monitor independent 2024-05-16 23:26:34 -04:00
Jakub
ae22b05118 Replace warp patch with currsor warp patch
This reverts commit 329fadf62a.
Fixes "stutter" when dragging mfact
2024-05-16 23:12:25 -04:00
2 changed files with 20 additions and 115 deletions

56
dwm.c
View File

@ -126,7 +126,6 @@ typedef struct {
typedef struct Pertag Pertag; typedef struct Pertag Pertag;
struct Monitor { struct Monitor {
char ltsymbol[16]; char ltsymbol[16];
char wfsymbol[2];
float mfact; float mfact;
int nmaster; int nmaster;
int num; int num;
@ -265,7 +264,6 @@ static void updatetitle(Client *c);
static void updatewindowtype(Client *c); static void updatewindowtype(Client *c);
static void updatewmhints(Client *c); static void updatewmhints(Client *c);
static void view(const Arg *arg); static void view(const Arg *arg);
static void warp(const Client *c);
static Client *wintoclient(Window w); static Client *wintoclient(Window w);
static Monitor *wintomon(Window w); static Monitor *wintomon(Window w);
static int xerror(Display *dpy, XErrorEvent *ee); static int xerror(Display *dpy, XErrorEvent *ee);
@ -286,6 +284,7 @@ static const char broken[] = "broken";
static char stext[256]; static char stext[256];
static char estextl[256]; static char estextl[256];
static char estextr[256]; static char estextr[256];
static char wfsymbol[2];
static int screen; static int screen;
static int sw, sh; /* X display screen geometry width, height */ static int sw, sh; /* X display screen geometry width, height */
static int bh; /* bar height */ static int bh; /* bar height */
@ -565,7 +564,7 @@ buttonpress(XEvent *e)
arg.ui = 1 << i; arg.ui = 1 << i;
} else if (ev->x < (x = (x + TEXTW(selmon->ltsymbol)))) } else if (ev->x < (x = (x + TEXTW(selmon->ltsymbol))))
click = ClkLtSymbol; click = ClkLtSymbol;
else if (ev->x < x + TEXTW(selmon->wfsymbol)) else if (ev->x < x + TEXTW(wfsymbol))
click = ClkFollowSymbol; click = ClkFollowSymbol;
/* 2px right padding */ /* 2px right padding */
else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2) else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
@ -804,8 +803,8 @@ createmon(void)
m->pertag->showbars[i] = m->showbar; m->pertag->showbars[i] = m->showbar;
} }
m->wfsymbol[0] = WFDEFAULT; wfsymbol[0] = WFDEFAULT;
m->wfsymbol[1] = '\0'; wfsymbol[1] = '\0';
return m; return m;
} }
@ -899,8 +898,8 @@ drawbar(Monitor *m)
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
w = TEXTW(m->wfsymbol); w = TEXTW(wfsymbol);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->wfsymbol, 0); x = drw_text(drw, x, 0, w, bh, lrpad / 2, wfsymbol, 0);
if ((w = m->ww - tw - x) > bh) { if ((w = m->ww - tw - x) > bh) {
if (n > 0) { if (n > 0) {
@ -1048,7 +1047,8 @@ focusmon(const Arg *arg)
unfocus(selmon->sel, 0); unfocus(selmon->sel, 0);
selmon = m; selmon = m;
focus(NULL); focus(NULL);
warp(selmon->sel); if (selmon->sel)
XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2);
} }
void void
@ -1098,6 +1098,7 @@ focusstack(int inc, int hid)
showwin(c); showwin(c);
c->mon->hidsel = 1; c->mon->hidsel = 1;
} }
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
} }
} }
@ -1390,8 +1391,11 @@ manage(Window w, XWindowAttributes *wa)
unfocus(selmon->sel, 0); unfocus(selmon->sel, 0);
c->mon->sel = c; c->mon->sel = c;
arrange(c->mon); arrange(c->mon);
if (!HIDDEN(c)) if (!HIDDEN(c)) {
XMapWindow(dpy, c->win); XMapWindow(dpy, c->win);
if (c && c->mon == selmon)
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
}
if (term) if (term)
swallow(term, c); swallow(term, c);
focus(NULL); focus(NULL);
@ -1766,8 +1770,6 @@ restack(Monitor *m)
wc.sibling = c->win; wc.sibling = c->win;
} }
} }
if (m == selmon && (m->tagset[m->seltags] & m->sel->tags) && m->lt[m->sellt]->arrange != &monocle)
warp(m->sel);
XSync(dpy, False); XSync(dpy, False);
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
} }
@ -2161,7 +2163,7 @@ tag(const Arg *arg)
focus(NULL); focus(NULL);
arrange(selmon); arrange(selmon);
} }
if (selmon->wfsymbol[0] == WFACTIVE) if (wfsymbol[0] == WFACTIVE)
view(arg); view(arg);
} }
@ -2171,7 +2173,7 @@ tagmon(const Arg *arg)
if (!selmon->sel || !mons->next) if (!selmon->sel || !mons->next)
return; return;
sendmon(selmon->sel, dirtomon(arg->i)); sendmon(selmon->sel, dirtomon(arg->i));
if (selmon->wfsymbol[0] == WFACTIVE) if (wfsymbol[0] == WFACTIVE)
focusmon(arg); focusmon(arg);
} }
@ -2233,7 +2235,7 @@ toggleextrabar(const Arg *arg)
void void
togglefollow(const Arg *arg) togglefollow(const Arg *arg)
{ {
selmon->wfsymbol[0] = (selmon->wfsymbol[0] == WFACTIVE) ? WFINACTIVE : WFACTIVE; wfsymbol[0] = (wfsymbol[0] == WFACTIVE) ? WFINACTIVE : WFACTIVE;
drawbars(); drawbars();
} }
@ -2329,6 +2331,7 @@ togglewin(const Arg *arg)
showwin(c); showwin(c);
focus(c); focus(c);
restack(selmon); restack(selmon);
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
} }
} }
@ -2385,6 +2388,9 @@ unmanage(Client *c, int destroyed)
arrange(m); arrange(m);
focus(NULL); focus(NULL);
updateclientlist(); updateclientlist();
if (m == selmon && m->sel)
XWarpPointer(dpy, None, m->sel->win, 0, 0, 0, 0,
m->sel->w/2, m->sel->h/2);
} }
} }
@ -2841,28 +2847,6 @@ swallowingclient(Window w)
return NULL; 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 * Client *
wintoclient(Window w) wintoclient(Window w)
{ {

View File

@ -1,79 +0,0 @@
From a229c36f51ad6f8b40109ed53c643f242351962a Mon Sep 17 00:00:00 2001
From: Jonas Dujava <jonas.dujava@gmail.com>
Date: Fri, 26 May 2023 22:14:48 +0200
Subject: [PATCH] Warp patch
Warps the mouse cursor to the center of the currently focused
window or screen when the mouse cursor is
(a) on a different screen, or
(b) on top of a different window.
This version properly handles warping to windows that have not been
mapped yet (before it resulted in a change of the stack order).
See the discussion in (thanks goes to Bakkeby):
https://github.com/bakkeby/patches/issues/60
---
dwm.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/dwm.c b/dwm.c
index e5efb6a..7ea6c14 100644
--- a/dwm.c
+++ b/dwm.c
@@ -228,6 +228,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);
@@ -834,6 +835,7 @@ focusmon(const Arg *arg)
unfocus(selmon->sel, 0);
selmon = m;
focus(NULL);
+ warp(selmon->sel);
}
void
@@ -1366,6 +1368,8 @@ restack(Monitor *m)
wc.sibling = c->win;
}
}
+ if (m == selmon && (m->tagset[m->seltags] & m->sel->tags) && m->lt[m->sellt]->arrange != &monocle)
+ warp(m->sel);
XSync(dpy, False);
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
@@ -2044,6 +2048,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)
{
--
2.40.1