commit fb9b31955a167a21ff7862599e63495e936a8886
parent 2637b9acfe5afc88deeb31e2ba7fab59bf1edd43
Author: Jaye Shovelton <Beanie.github@proton.me>
Date: Sun, 29 Nov 2026 16:58:23 +0000
[dwm][patch][spawnonemptytag] Add alternative implementation
It's simpler and doesn't require effort from the user so I've made it
the default.
Diffstat:
3 files changed, 71 insertions(+), 59 deletions(-)
diff --git a/dwm.suckless.org/patches/spawnonemptytag/dwm-spawnonemptytag-6.8.diff b/dwm.suckless.org/patches/spawnonemptytag/dwm-spawnonemptytag-6.8.diff
@@ -1,78 +1,85 @@
-From 6ecf97475394209f12607684b384023318a185af Mon Sep 17 00:00:00 2001
+From f76a4a25f2a4a2c3f96effb50ccee700c0c38542 Mon Sep 17 00:00:00 2001
From: Jaye Shovelton <Beanie.github@proton.me>
-Date: Sun, 29 Nov 2026 05:01:44 +0000
+Date: Sun, 29 Nov 2026 16:55:23 +0000
Subject: [PATCH] Switch to the closest empty tag upon spawning a command
---
- config.def.h | 4 ++--
- dwm.c | 26 ++++++++++++++++++++++++++
- 2 files changed, 28 insertions(+), 2 deletions(-)
+ dwm.c | 35 ++++++++++++++++++++++++++++++-----
+ 1 file changed, 30 insertions(+), 5 deletions(-)
-diff --git a/config.def.h b/config.def.h
-index 81c3fc0..9022fe0 100644
---- a/config.def.h
-+++ b/config.def.h
-@@ -64,7 +64,7 @@ static const char *termcmd[] = { "st", NULL };
- static const Key keys[] = {
- /* modifier key function argument */
- { MODKEY, XK_p, spawn, {.v = dmenucmd } },
-- { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
-+ { MODKEY|ShiftMask, XK_Return, spawnwindow, {.v = termcmd } },
- { MODKEY, XK_b, togglebar, {0} },
- { MODKEY, XK_j, focusstack, {.i = +1 } },
- { MODKEY, XK_k, focusstack, {.i = -1 } },
-@@ -105,7 +105,7 @@ static const Button buttons[] = {
- { ClkLtSymbol, 0, Button1, setlayout, {0} },
- { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
- { ClkWinTitle, 0, Button2, zoom, {0} },
-- { ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
-+ { ClkStatusText, 0, Button2, spawnwindow, {.v = termcmd } },
- { ClkClientWin, MODKEY, Button1, movemouse, {0} },
- { ClkClientWin, MODKEY, Button2, togglefloating, {0} },
- { ClkClientWin, MODKEY, Button3, resizemouse, {0} },
diff --git a/dwm.c b/dwm.c
-index 53b393e..30996fc 100644
+index 53b393e..1ce967c 100644
--- a/dwm.c
+++ b/dwm.c
-@@ -205,6 +205,7 @@ static void setup(void);
- static void seturgent(Client *c, int urg);
- static void showhide(Client *c);
- static void spawn(const Arg *arg);
-+static void spawnwindow(const Arg *arg);
- static void tag(const Arg *arg);
- static void tagmon(const Arg *arg);
- static void tile(Monitor *m);
-@@ -1666,6 +1667,31 @@ spawn(const Arg *arg)
+@@ -184,6 +184,7 @@ static void monocle(Monitor *m);
+ static void motionnotify(XEvent *e);
+ static void movemouse(const Arg *arg);
+ static Client *nexttiled(Client *c);
++static unsigned int occlusions(Monitor *m);
+ static void pop(Client *c);
+ static void propertynotify(XEvent *e);
+ static void quit(const Arg *arg);
+@@ -307,6 +308,23 @@ applyrules(Client *c)
+ XFree(ch.res_class);
+ if (ch.res_name)
+ XFree(ch.res_name);
++
++ /* find an empty tag */
++ unsigned int occ = occlusions(c->mon);
++ unsigned int tagset = c->mon->tagset[c->mon->seltags];
++ Arg ctag, tag;
++ ctag.ui = tagset & -tagset; /* get earliest tag in tagset */
++ tag = ctag;
++ while (tag.ui & occ) {
++ unsigned int newtag = ((tag.ui << 1) & TAGMASK) | (tag.ui >> (LENGTH(tags) - 1));
++ occ ^= tag.ui;
++ tag.ui = newtag;
++ }
++ if (tag.ui != ctag.ui && !c->isfloating)
++ /* NOTE: this uses selmon instead of c->mon, but it's assumed they're
++ the same */
++ view(&tag);
++
+ c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
+ }
+
+@@ -700,7 +718,7 @@ drawbar(Monitor *m)
+ int x, w, tw = 0;
+ int boxs = drw->fonts->h / 9;
+ int boxw = drw->fonts->h / 6 + 2;
+- unsigned int i, occ = 0, urg = 0;
++ unsigned int i, occ = occlusions(m), urg = 0;
+ Client *c;
+
+ if (!m->showbar)
+@@ -713,10 +731,8 @@ drawbar(Monitor *m)
+ drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
}
+
+- for (c = m->clients; c; c = c->next) {
+- occ |= c->tags;
+- if (c->isurgent)
+- urg |= c->tags;
++ for (c = m->clients; c && c->isurgent; c = c->next) {
++ urg |= c->tags;
+ }
+ x = 0;
+ for (i = 0; i < LENGTH(tags); i++) {
+@@ -1209,6 +1225,15 @@ nexttiled(Client *c)
+ return c;
}
-+void
-+spawnwindow(const Arg *arg)
++unsigned int
++occlusions(Monitor *m)
+{
+ unsigned int occ = 0;
-+ unsigned int tagset = selmon->tagset[selmon->seltags];
-+ Arg ct, t;
-+
-+ for(Client *c = selmon->clients; c; c=c->next)
++ for(Client *c = m->clients; c; c = c->next)
+ occ |= c->tags == TAGMASK ? 0 : c->tags;
-+ /* get earliest tag in tagset */
-+ ct.ui = tagset & -tagset;
-+ t = ct;
-+
-+ while (t.ui & occ) {
-+ unsigned int newt = ((t.ui << 1) & TAGMASK) | (t.ui >> (LENGTH(tags) - 1));
-+ occ ^= t.ui;
-+ t.ui = newt;
-+ }
-+
-+ if (t.ui != ct.ui)
-+ view(&t);
-+
-+ spawn(arg);
++ return occ;
+}
+
void
- tag(const Arg *arg)
+ pop(Client *c)
{
--
2.56.1
diff --git a/dwm.suckless.org/patches/spawnonemptytag/dwm-spawnonemptytag-6.8.diff b/dwm.suckless.org/patches/spawnonemptytag/dwm-spawnonemptytag-spawnwindow-6.8.diff
diff --git a/dwm.suckless.org/patches/spawnonemptytag/index.md b/dwm.suckless.org/patches/spawnonemptytag/index.md
@@ -3,7 +3,7 @@ spawnonemptytag
Description
-----------
-When a binding executes `spawnwindow`, this patch switches to the closest empty
+When a non-floating window is spawned, this patch switches to the closest empty
tag on the right. It wraps round if there are no more tags and does nothing if
the current tag is empty or there are no empty tags.
@@ -11,6 +11,11 @@ Download
--------
* [dwm-spawnonemptytag-6.8.diff](dwm-spawnonemptytag-6.8.diff)
+Alternative implementation that splits `spawn`, allowing control over which
+commands trigger switching:
+
+* [dwm-spawnonemptytag-spawnwindow-6.8.diff](dwm-spawnonemptytag-spawnwindow-6.8.diff)
+
Authors
-------
* Jaye Shovelton - <Beanie.github@proton.me>