dwm

dynamic window manager

git clone https://9o.is/git/dwm.git

commit f04dfcd36bf666e040ab5bb8417052eb273c71ca
parent ed424e1e466738606ce2c148104b3cf7a4551c19
Author: Jul <jul@9o.is>
Date:   Mon, 16 Feb 2026 12:07:37 +0800

fix null pointer error

Diffstat:
Mdwm.c | 27+++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/dwm.c b/dwm.c @@ -1058,6 +1058,13 @@ focusmon(const Arg *arg) */ void +warpmouse() +{ + if (selmon->sel) + XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); +} + +void focusstack(const Arg *arg) { Client *c = NULL, *i; @@ -1083,12 +1090,12 @@ focusstack(const Arg *arg) selmon->fg = c; arrange(selmon); focus(c); - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2); + warpmouse(); } else if (c) { focus(c); restack(selmon); - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2); + warpmouse(); } } @@ -1114,7 +1121,7 @@ focusstacknum(const Arg *arg) if (c) { focus(c); restack(selmon); - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2); + warpmouse(); } } @@ -1240,7 +1247,7 @@ incnmaster(const Arg *arg) { selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); arrange(selmon); - XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); + warpmouse(); } #ifdef XINERAMA @@ -1481,7 +1488,7 @@ pop(Client *c) attach(c); focus(c); arrange(c->mon); - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2); + warpmouse(); } void @@ -1813,7 +1820,7 @@ setmfact(const Arg *arg) return; selmon->mfact = f; arrange(selmon); - XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); + warpmouse(); } void @@ -1986,7 +1993,7 @@ tag(const Arg *arg) setclienttagprop(selmon->sel); focus(NULL); arrange(selmon); - XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); + warpmouse(); } } @@ -2071,7 +2078,7 @@ toggletag(const Arg *arg) setclienttagprop(selmon->sel); focus(NULL); arrange(selmon); - XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); + warpmouse(); } } @@ -2084,7 +2091,7 @@ toggleview(const Arg *arg) selmon->tagset[selmon->seltags] = newtagset; focus(NULL); arrange(selmon); - XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); + warpmouse(); } } @@ -2442,7 +2449,7 @@ view(const Arg *arg) selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; focus(NULL); arrange(selmon); - XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); + warpmouse(); } pid_t