sites

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

dwm-default-tag-apps-20210327-61bb8b2.diff (3608B)


      1 From 2666387a3f50c21b0503e9a7291f012e70e92086 Mon Sep 17 00:00:00 2001
      2 From: NlGHT <night@nightmusic.net>
      3 Date: Sat, 27 Mar 2021 12:01:26 +0100
      4 Subject: [PATCH] Default tag apps - set application for each tag
      5 Then you can use the one keybind to spawn the default application of the tag you're on.
      6 
      7 ---
      8  config.def.h |  2 ++
      9  dwm.c        | 36 ++++++++++++++++++++++++++++++++++++
     10  2 files changed, 38 insertions(+)
     11 
     12 diff --git a/config.def.h b/config.def.h
     13 index 1c0b587..066c7cc 100644
     14 --- a/config.def.h
     15 +++ b/config.def.h
     16 @@ -20,6 +20,7 @@ static const char *colors[][3]      = {
     17 
     18  /* tagging */
     19  static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
     20 +static const char *defaulttagapps[] = { "st", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
     21 
     22  static const Rule rules[] = {
     23  	/* xprop(1):
     24 @@ -63,6 +64,7 @@ static Key keys[] = {
     25  	/* modifier                     key        function        argument */
     26  	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
     27  	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
     28 +	{ MODKEY,                       XK_s,      spawndefault,   {0} },
     29  	{ MODKEY,                       XK_b,      togglebar,      {0} },
     30  	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
     31  	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
     32 diff --git a/dwm.c b/dwm.c
     33 index 664c527..e0769ec 100644
     34 --- a/dwm.c
     35 +++ b/dwm.c
     36 @@ -200,6 +200,7 @@ static void sendmon(Client *c, Monitor *m);
     37  static void setclientstate(Client *c, long state);
     38  static void setfocus(Client *c);
     39  static void setfullscreen(Client *c, int fullscreen);
     40 +static void setlasttag(int tagbit);
     41  static void setlayout(const Arg *arg);
     42  static void setmfact(const Arg *arg);
     43  static void setup(void);
     44 @@ -207,6 +208,7 @@ static void seturgent(Client *c, int urg);
     45  static void showhide(Client *c);
     46  static void sigchld(int unused);
     47  static void spawn(const Arg *arg);
     48 +static void spawndefault();
     49  static void tag(const Arg *arg);
     50  static void tagmon(const Arg *arg);
     51  static void tile(Monitor *);
     52 @@ -269,6 +271,9 @@ static Drw *drw;
     53  static Monitor *mons, *selmon;
     54  static Window root, wmcheckwin;
     55 
     56 +static int lastchosentag[8];
     57 +static int previouschosentag[8];
     58 +
     59  /* configuration, allows nested code to access above variables */
     60  #include "config.h"
     61 
     62 @@ -1498,6 +1503,24 @@ setfullscreen(Client *c, int fullscreen)
     63  	}
     64  }
     65 
     66 +void
     67 +setlasttag(int tagbit) {
     68 +	const int mon = selmon->num;
     69 +	if (tagbit > 0) {
     70 +		int i = 1, pos = 0;
     71 +		while (!(i & tagbit)) {
     72 +			i = i << 1;
     73 +			++pos;
     74 +		}
     75 +		previouschosentag[mon] = lastchosentag[mon];
     76 +		lastchosentag[mon] = pos;
     77 +	} else {
     78 +		const int tempTag = lastchosentag[mon];
     79 +		lastchosentag[mon] = previouschosentag[mon];
     80 +		previouschosentag[mon] = tempTag;
     81 +	}
     82 +}
     83 +
     84  void
     85  setlayout(const Arg *arg)
     86  {
     87 @@ -1653,6 +1676,17 @@ spawn(const Arg *arg)
     88  	}
     89  }
     90 
     91 +void
     92 +spawndefault()
     93 +{
     94 +	const char *app = defaulttagapps[lastchosentag[selmon->num]];
     95 +	if (app) {
     96 +		const char *defaultcmd[] = {app, NULL};
     97 +		Arg a = {.v = defaultcmd};
     98 +		spawn(&a);
     99 +	}
    100 +}
    101 +
    102  void
    103  tag(const Arg *arg)
    104  {
    105 @@ -1744,6 +1778,7 @@ toggleview(const Arg *arg)
    106 
    107  	if (newtagset) {
    108  		selmon->tagset[selmon->seltags] = newtagset;
    109 +		setlasttag(newtagset);
    110  		focus(NULL);
    111  		arrange(selmon);
    112  	}
    113 @@ -2040,6 +2075,7 @@ view(const Arg *arg)
    114  {
    115  	if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
    116  		return;
    117 +	setlasttag(arg->ui);
    118  	selmon->seltags ^= 1; /* toggle sel tagset */
    119  	if (arg->ui & TAGMASK)
    120  		selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
    121 --
    122 2.31.0
    123