summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2022-01-29 00:42:46 -0500
committerMalfurious <m@lfurio.us>2023-06-03 22:28:40 -0400
commitf91dec9e023273b305537e867f641e124ad25475 (patch)
treeb6bf112b5333d18c3e8f6fadfc693c45cbc15ba4 /dwm.c
parent44040e4c78cafcaf7d1e8c857fec57c55473fb3f (diff)
downloaddwm-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.
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c24
1 files changed, 21 insertions, 3 deletions
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 <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]);