diff options
author | Malfurious <m@lfurio.us> | 2022-01-29 00:42:46 -0500 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2023-06-03 22:28:40 -0400 |
commit | f91dec9e023273b305537e867f641e124ad25475 (patch) | |
tree | b6bf112b5333d18c3e8f6fadfc693c45cbc15ba4 | |
parent | 44040e4c78cafcaf7d1e8c857fec57c55473fb3f (diff) | |
download | dwm-f91dec9e023273b305537e867f641e124ad25475.tar.gz dwm-f91dec9e023273b305537e867f641e124ad25475.zip |
patch: taglabels
Displays the executable name of each tag's current master client after
the tag name in the dwm bar.
For example, if st is the master client on tag 1, then the bar
would display [1: st] as opposed to just 1.
The format of the label, for both non-empty and empty tags, is
configurable through the configuration variables ptagf and etagf
respectively. There is also a config variable, lcaselbl, that, when
enabled, makes the first letter lowercase (out of personal preference).
This is a modified version of the taglabels patch that, rather than
using the window class (executable name) of the master client, uses the
actual window title for each tag's label.
-rw-r--r-- | config.def.h | 4 | ||||
-rw-r--r-- | dwm.c | 24 |
2 files changed, 25 insertions, 3 deletions
diff --git a/config.def.h b/config.def.h index c5e8fd5..e92de44 100644 --- a/config.def.h +++ b/config.def.h @@ -27,6 +27,10 @@ static const unsigned int alphas[][3] = { /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }; +static const char ptagf[] = "[%s %s]"; /* format of a tag label */ +static const char etagf[] = "[%s]"; /* format of an empty tag */ +static const int lcaselbl = 0; /* 1 means make tag label lowercase */ + static const Rule rules[] = { /* xprop(1): * WM_CLASS(STRING) = instance, class @@ -20,6 +20,7 @@ * * To understand everything else, start reading main(). */ +#include <ctype.h> /* for making tab label lowercase, very tiny standard library */ #include <errno.h> #include <locale.h> #include <signal.h> @@ -312,6 +313,7 @@ struct Pertag { }; static unsigned int scratchtag = 1 << LENGTH(tags); +unsigned int tagw[LENGTH(tags)]; /* compile-time check if all tags fit into an unsigned int bit array. */ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; @@ -545,7 +547,7 @@ buttonpress(XEvent *e) /* do not reserve space for vacant tags */ if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) continue; - x += TEXTW(tags[i]); + x += tagw[i]; } while (ev->x >= x && ++i < LENGTH(tags)); if (i < LENGTH(tags)) { click = ClkTagBar; @@ -829,6 +831,8 @@ drawbar(Monitor *m) int boxw = drw->fonts->h / 6 + 2; unsigned int i, occ = 0, urg = 0; Client *c; + char taglabel[64]; + char *masterclientontag[LENGTH(tags)]; w = blw = TEXTW(m->ltsymbol); /* clear bar from last draw */ @@ -845,10 +849,19 @@ drawbar(Monitor *m) drw_text(drw, m->ww - w, 0, w, bh, lrpad / 2, m->ltsymbol, 0); } + for (i = 0; i < LENGTH(tags); i++) + masterclientontag[i] = NULL; + for (c = m->clients; c; c = c->next) { occ |= c->tags == 255 ? 0 : c->tags; if (c->isurgent) urg |= c->tags; + for (i = 0; i < LENGTH(tags); i++) + if (!masterclientontag[i] && c->tags & (1<<i)) { + masterclientontag[i] = c->name; + if (lcaselbl) + masterclientontag[i][0] = tolower(masterclientontag[i][0]); + } } x = 0; for (i = 0; i < LENGTH(tags); i++) { @@ -856,9 +869,14 @@ drawbar(Monitor *m) if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) continue; - w = TEXTW(tags[i]); + if (masterclientontag[i]) + snprintf(taglabel, 64, ptagf, tags[i], masterclientontag[i]); + else + snprintf(taglabel, 64, etagf, tags[i]); + masterclientontag[i] = taglabel; + tagw[i] = w = TEXTW(masterclientontag[i]); drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); + drw_text(drw, x, 0, w, bh, lrpad / 2, masterclientontag[i], urg & 1 << i); x += w; } drw_setscheme(drw, scheme[SchemeNorm]); |