dwm-spawnonemptytag-6.8.diff (1247B)
1 From f944f440791746eaaaab41664d1231d9ce45e4d5 Mon Sep 17 00:00:00 2001 2 From: Jaye Shovelton <Beanie.github@proton.me> 3 Date: Sun, 29 Nov 2026 17:28:58 +0000 4 Subject: [PATCH] Switch to the closest empty tag upon spawning a command 5 6 --- 7 dwm.c | 21 +++++++++++++++++++++ 8 1 file changed, 21 insertions(+) 9 10 diff --git a/dwm.c b/dwm.c 11 index 53b393e..2e4787e 100644 12 --- a/dwm.c 13 +++ b/dwm.c 14 @@ -307,6 +307,27 @@ applyrules(Client *c) 15 XFree(ch.res_class); 16 if (ch.res_name) 17 XFree(ch.res_name); 18 + 19 + if (!c->isfloating) { 20 + /* find an empty tag */ 21 + unsigned int occ = 0; 22 + unsigned int tagset = c->mon->tagset[c->mon->seltags]; 23 + Arg ctag, tag; 24 + for(Client *ec = c->mon->clients; ec; ec = ec->next) 25 + occ |= ec->tags == TAGMASK || ec->isfloating ? 0 : ec->tags; 26 + ctag.ui = tagset & -tagset; /* get earliest tag in tagset */ 27 + tag = ctag; 28 + while (tag.ui & occ) { 29 + unsigned int newtag = ((tag.ui << 1) & TAGMASK) | (tag.ui >> (LENGTH(tags) - 1)); 30 + occ ^= tag.ui; 31 + tag.ui = newtag; 32 + } 33 + if (tag.ui != ctag.ui) 34 + /* NOTE: this uses selmon instead of c->mon, but it's assumed they're 35 + the same */ 36 + view(&tag); 37 + } 38 + 39 c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; 40 } 41 42 -- 43 2.56.1 44