sites

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

dwm-spawnonemptytag-spawnwindow-6.8.diff (2811B)


      1 From 6ecf97475394209f12607684b384023318a185af Mon Sep 17 00:00:00 2001
      2 From: Jaye Shovelton <Beanie.github@proton.me>
      3 Date: Sun, 29 Nov 2026 05:01:44 +0000
      4 Subject: [PATCH] Switch to the closest empty tag upon spawning a command
      5 
      6 ---
      7  config.def.h |  4 ++--
      8  dwm.c        | 26 ++++++++++++++++++++++++++
      9  2 files changed, 28 insertions(+), 2 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 81c3fc0..9022fe0 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -64,7 +64,7 @@ static const char *termcmd[]  = { "st", NULL };
     16  static const Key keys[] = {
     17  	/* modifier                     key        function        argument */
     18  	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
     19 -	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
     20 +	{ MODKEY|ShiftMask,             XK_Return, spawnwindow,    {.v = termcmd } },
     21  	{ MODKEY,                       XK_b,      togglebar,      {0} },
     22  	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
     23  	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
     24 @@ -105,7 +105,7 @@ static const Button buttons[] = {
     25  	{ ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
     26  	{ ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
     27  	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
     28 -	{ ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
     29 +	{ ClkStatusText,        0,              Button2,        spawnwindow,    {.v = termcmd } },
     30  	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
     31  	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
     32  	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
     33 diff --git a/dwm.c b/dwm.c
     34 index 53b393e..30996fc 100644
     35 --- a/dwm.c
     36 +++ b/dwm.c
     37 @@ -205,6 +205,7 @@ static void setup(void);
     38  static void seturgent(Client *c, int urg);
     39  static void showhide(Client *c);
     40  static void spawn(const Arg *arg);
     41 +static void spawnwindow(const Arg *arg);
     42  static void tag(const Arg *arg);
     43  static void tagmon(const Arg *arg);
     44  static void tile(Monitor *m);
     45 @@ -1666,6 +1667,31 @@ spawn(const Arg *arg)
     46  	}
     47  }
     48  
     49 +void
     50 +spawnwindow(const Arg *arg)
     51 +{
     52 +	unsigned int occ = 0;
     53 +	unsigned int tagset = selmon->tagset[selmon->seltags];
     54 +	Arg ct, t;
     55 +
     56 +	for(Client *c = selmon->clients; c; c=c->next)
     57 +		occ |= c->tags == TAGMASK ? 0 : c->tags;
     58 +	/* get earliest tag in tagset */
     59 +	ct.ui = tagset & -tagset;
     60 +	t = ct;
     61 +
     62 +	while (t.ui & occ) {
     63 +		unsigned int newt = ((t.ui << 1) & TAGMASK) | (t.ui >> (LENGTH(tags) - 1));
     64 +		occ ^= t.ui;
     65 +		t.ui = newt;
     66 +	}
     67 +
     68 +	if (t.ui != ct.ui)
     69 +			view(&t);
     70 +
     71 +	spawn(arg);
     72 +}
     73 +
     74  void
     75  tag(const Arg *arg)
     76  {
     77 -- 
     78 2.56.1
     79