commit 13dcce4d1dcfefdb90904dd564147547fe17fe78
parent 2061e695b297d9b575ac6fa34e31474b33a66ddc
Author: Jaye Shovelton <Beanie.github@proton.me>
Date: Tue, 1 Dec 2026 00:26:21 +0000
[dwm][patch][bindtagrule] Add a patch to spawn & switch to a fixed-tag window in one bind
Diffstat:
2 files changed, 138 insertions(+), 0 deletions(-)
diff --git a/dwm.suckless.org/patches/bindtagrule/dwm-bindtagrule-6.8.diff b/dwm.suckless.org/patches/bindtagrule/dwm-bindtagrule-6.8.diff
@@ -0,0 +1,122 @@
+From 52f10bb87286cce076d24246742f61bdd9834938 Mon Sep 17 00:00:00 2001
+From: Jaye Shovelton <Beanie.github@proton.me>
+Date: Tue, 1 Dec 2026 07:11:54 +0000
+Subject: [PATCH] Add a patch to spawn and switch to a fixed-tag window in one
+ bind.
+
+---
+ dwm.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------
+ 1 file changed, 50 insertions(+), 6 deletions(-)
+
+diff --git a/dwm.c b/dwm.c
+index 53b393e..1cdf86c 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -151,6 +151,7 @@ static void buttonpress(XEvent *e);
+ static void checkotherwm(void);
+ static void cleanup(void);
+ static void cleanupmon(Monitor *mon);
++static int clientexists(const Rule *r);
+ static void clientmessage(XEvent *e);
+ static void configure(Client *c);
+ static void configurenotify(XEvent *e);
+@@ -192,6 +193,7 @@ static void resize(Client *c, int x, int y, int w, int h, int interact);
+ static void resizeclient(Client *c, int x, int y, int w, int h);
+ static void resizemouse(const Arg *arg);
+ static void restack(Monitor *m);
++static int rulematches(const Rule *r, const char *name, const char *class, const char *instance);
+ static void run(void);
+ static void scan(void);
+ static int sendevent(Client *c, Atom proto);
+@@ -292,10 +294,7 @@ applyrules(Client *c)
+
+ for (i = 0; i < LENGTH(rules); i++) {
+ r = &rules[i];
+- if ((!r->title || strstr(c->name, r->title))
+- && (!r->class || strstr(class, r->class))
+- && (!r->instance || strstr(instance, r->instance)))
+- {
++ if (rulematches(r, c->name, class, instance)) {
+ c->isfloating = r->isfloating;
+ c->tags |= r->tags;
+ for (m = mons; m && m->num != r->monitor; m = m->next);
+@@ -511,6 +510,22 @@ cleanupmon(Monitor *mon)
+ free(mon);
+ }
+
++int
++clientexists(const Rule *r)
++{
++ const char *class, *instance;
++ XClassHint ch = { NULL, NULL };
++ for (Client *c = selmon->clients; c; c = c->next) {
++ XGetClassHint(dpy, c->win, &ch);
++ class = ch.res_class ? ch.res_class : broken;
++ instance = ch.res_name ? ch.res_name : broken;
++ if (rulematches(r, c->name, class, instance))
++ return 1;
++ }
++
++ return 0;
++}
++
+ void
+ clientmessage(XEvent *e)
+ {
+@@ -1379,6 +1394,14 @@ restack(Monitor *m)
+ while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+ }
+
++int
++rulematches(const Rule *r, const char *name, const char *class, const char *instance)
++{
++ return (!r->title || strcasestr(name, r->title))
++ && (!r->class || strcasestr(class, r->class))
++ && (!r->instance || strcasestr(instance, r->instance));
++}
++
+ void
+ run(void)
+ {
+@@ -1648,6 +1671,27 @@ void
+ spawn(const Arg *arg)
+ {
+ struct sigaction sa;
++ char **strarr = (char **)arg->v;
++
++ /* slightly hacky: if spawning a program via `SHCMD`, check if any of the
++ * rules are matched. If they are, check if the tag is specified. If it
++ * is, switch to that tag. This can't happen more cleanly or anywhere else,
++ * since this has to happen even if no window is spawned, and we have no
++ * way of already knowing if the window exists
++ */
++ if (!strcmp(strarr[0], "/bin/sh")) {
++ char *progname = strarr[2];
++
++ for (int i = 0; i < LENGTH(rules); i++) {
++ const Rule *r = &rules[i];
++ if (r->tags && rulematches(r, progname, progname, progname)) {
++ Arg tag = { .ui = r->tags };
++ view(&tag);
++ if (clientexists(r))
++ return;
++ }
++ }
++ }
+
+ if (arg->v == dmenucmd)
+ dmenumon[0] = '0' + selmon->num;
+@@ -1661,8 +1705,8 @@ spawn(const Arg *arg)
+ sa.sa_handler = SIG_DFL;
+ sigaction(SIGCHLD, &sa, NULL);
+
+- execvp(((char **)arg->v)[0], (char **)arg->v);
+- die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]);
++ execvp(strarr[0], strarr);
++ die("dwm: execvp '%s' failed:", strarr[0]);
+ }
+ }
+
+--
+2.56.1
+
diff --git a/dwm.suckless.org/patches/bindtagrule/index.md b/dwm.suckless.org/patches/bindtagrule/index.md
@@ -0,0 +1,16 @@
+bindtagrule
+===========
+
+Description
+-----------
+This patch is very similar to [`switchtotags`](../switchtotags), but switches
+to that tag even when no window is opened (e.g. because it already exists), and
+does not switch to the window when no binding was pressed.
+
+Download
+--------
+* [dwm-bindtagrule-6.8.diff](dwm-bindtagrule-6.8.diff)
+
+Authors
+-------
+* Jaye Shovelton - <Beanie.github@proton.me>