dwm-taglabels-6.2.diff - sites - public wiki contents of suckless.org
HTML git clone git://git.suckless.org/sites
DIR Log
DIR Files
DIR Refs
---
dwm-taglabels-6.2.diff (3149B)
---
1 diff -pu dwm.git/config.def.h dwm.programtags/config.def.h
2 --- dwm.git/config.def.h 2021-02-27 20:04:32.030570909 -0600
3 +++ dwm.programtags/config.def.h 2021-03-15 16:24:23.620864957 -0500
4 @@ -21,6 +21,10 @@ static const char *colors[][3] = {
5 /* tagging */
6 static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
7
8 +static const char ptagf[] = "[%s %s]"; /* format of a tag label */
9 +static const char etagf[] = "[%s]"; /* format of an empty tag */
10 +static const int lcaselbl = 0; /* 1 means make tag label lowercase */
11 +
12 static const Rule rules[] = {
13 /* xprop(1):
14 * WM_CLASS(STRING) = instance, class
15 diff -pu dwm.git/dwm.c dwm.programtags/dwm.c
16 --- dwm.git/dwm.c 2021-02-27 20:04:32.030570909 -0600
17 +++ dwm.programtags/dwm.c 2021-03-15 16:30:13.580457535 -0500
18 @@ -20,6 +20,7 @@
19 *
20 * To understand everything else, start reading main().
21 */
22 +#include <ctype.h> /* for making tab label lowercase, very tiny standard library */
23 #include <errno.h>
24 #include <locale.h>
25 #include <signal.h>
26 @@ -272,6 +273,8 @@ static Window root, wmcheckwin;
27 /* configuration, allows nested code to access above variables */
28 #include "config.h"
29
30 +unsigned int tagw[LENGTH(tags)];
31 +
32 /* compile-time check if all tags fit into an unsigned int bit array. */
33 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
34
35 @@ -433,7 +436,7 @@ buttonpress(XEvent *e)
36 if (ev->window == selmon->barwin) {
37 i = x = 0;
38 do
39 - x += TEXTW(tags[i]);
40 + x += tagw[i];
41 while (ev->x >= x && ++i < LENGTH(tags));
42 if (i < LENGTH(tags)) {
43 click = ClkTagBar;
44 @@ -701,6 +704,8 @@ drawbar(Monitor *m)
45 int boxw = drw->fonts->h / 6 + 2;
46 unsigned int i, occ = 0, urg = 0;
47 Client *c;
48 + char taglabel[64];
49 + char *masterclientontag[LENGTH(tags)];
50
51 /* draw status first so it can be overdrawn by tags later */
52 if (m == selmon) { /* status is only drawn on selected monitor */
53 @@ -709,16 +714,32 @@ drawbar(Monitor *m)
54 drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
55 }
56
57 + for (i = 0; i < LENGTH(tags); i++)
58 + masterclientontag[i] = NULL;
59 +
60 for (c = m->clients; c; c = c->next) {
61 occ |= c->tags;
62 if (c->isurgent)
63 urg |= c->tags;
64 + for (i = 0; i < LENGTH(tags); i++)
65 + if (!masterclientontag[i] && c->tags & (1<<i)) {
66 + XClassHint ch = { NULL, NULL };
67 + XGetClassHint(dpy, c->win, &ch);
68 + masterclientontag[i] = ch.res_class;
69 + if (lcaselbl)
70 + masterclientontag[i][0] = tolower(masterclientontag[i][0]);
71 + }
72 }
73 x = 0;
74 for (i = 0; i < LENGTH(tags); i++) {
75 - w = TEXTW(tags[i]);
76 + if (masterclientontag[i])
77 + snprintf(taglabel, 64, ptagf, tags[i], masterclientontag[i]);
78 + else
79 + snprintf(taglabel, 64, etagf, tags[i]);
80 + masterclientontag[i] = taglabel;
81 + tagw[i] = w = TEXTW(masterclientontag[i]);
82 drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
83 - drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
84 + drw_text(drw, x, 0, w, bh, lrpad / 2, masterclientontag[i], urg & 1 << i);
85 if (occ & 1 << i)
86 drw_rect(drw, x + boxs, boxs, boxw, boxw,
87 m == selmon && selmon->sel && selmon->sel->tags & 1 << i,