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. --- dwm.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'dwm.c') 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