From f91dec9e023273b305537e867f641e124ad25475 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Sat, 29 Jan 2022 00:42:46 -0500 Subject: 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. --- config.def.h | 4 ++++ 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 diff --git a/dwm.c b/dwm.c index 38ffb86..8b925a6 100644 --- a/dwm.c +++ b/dwm.c @@ -20,6 +20,7 @@ * * To understand everything else, start reading main(). */ +#include /* for making tab label lowercase, very tiny standard library */ #include #include #include @@ -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<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]); -- cgit v1.2.3