sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-switchfromemptytag-6.8.diff (1173B)


      1 From ef57e1dae41c0c1661088dc922c18f31d2fa84d1 Mon Sep 17 00:00:00 2001
      2 From: Jaye Shovelton <Beanie.github@proton.me>
      3 Date: Mon, 30 Nov 2026 18:50:58 +0000
      4 Subject: [PATCH] Auto-switch to a previous full tag if current one is empty.
      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..59f247c 100644
     12 --- a/dwm.c
     13 +++ b/dwm.c
     14 @@ -1798,6 +1798,27 @@ unmanage(Client *c, int destroyed)
     15  	free(c);
     16  	focus(NULL);
     17  	updateclientlist();
     18 +
     19 +	/* switch to the previous full tag */
     20 +	unsigned int occ = 0;
     21 +	unsigned int empty;
     22 +	unsigned int tagset = selmon->tagset[selmon->seltags];
     23 +	Arg ctag, tag;
     24 +	for(c = selmon->clients; c; c = c->next)
     25 +		occ |= c->tags == TAGMASK || c->isfloating ? 0 : c->tags;
     26 +	empty = ~occ;
     27 +	ctag.ui = tagset & -tagset; /* get earliest tag in tagset */
     28 +	tag = ctag;
     29 +	while (tag.ui & empty) {
     30 +		unsigned int newtag = (tag.ui >> 1) | ((tag.ui << (LENGTH(tags) - 1)) & TAGMASK);
     31 +		empty ^= tag.ui;
     32 +		tag.ui = newtag;
     33 +	}
     34 +	if (tag.ui != ctag.ui)
     35 +		/* NOTE: this uses selmon instead of c->mon, but it's assumed they're
     36 +		   the same */
     37 +		view(&tag);
     38 +
     39  	arrange(m);
     40  }
     41  
     42 -- 
     43 2.56.1
     44