dwm-taglabels+hide_vacant_tags-6.2.diff (3891B)
1 diff -pu dwm.git/config.def.h dwm.programtags+hidewithvacanttags/config.def.h 2 --- dwm.git/config.def.h 2021-02-27 20:04:32.030570909 -0600 3 +++ dwm.programtags+hidewithvacanttags/config.def.h 2021-03-15 16:32:37.586956549 -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+hidewithvacanttags/dwm.c 16 --- dwm.git/dwm.c 2021-02-27 20:04:32.030570909 -0600 17 +++ dwm.programtags+hidewithvacanttags/dwm.c 2021-03-15 16:32:23.693639390 -0500 18 @@ -20,6 +20,7 @@ 19 * 20 * To understand everything else, start reading main(). 21 */ 22 +#include <ctype.h> /* for tolower function, 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 @@ -417,7 +420,7 @@ attachstack(Client *c) 36 void 37 buttonpress(XEvent *e) 38 { 39 - unsigned int i, x, click; 40 + unsigned int i, x, click, occ = 0; 41 Arg arg = {0}; 42 Client *c; 43 Monitor *m; 44 @@ -432,9 +435,14 @@ buttonpress(XEvent *e) 45 } 46 if (ev->window == selmon->barwin) { 47 i = x = 0; 48 - do 49 - x += TEXTW(tags[i]); 50 - while (ev->x >= x && ++i < LENGTH(tags)); 51 + for (c = m->clients; c; c = c->next) 52 + occ |= c->tags == 255 ? 0 : c->tags; 53 + do { 54 + /* do not reserve space for vacant tags */ 55 + if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) 56 + continue; 57 + x += tagw[i]; 58 + } while (ev->x >= x && ++i < LENGTH(tags)); 59 if (i < LENGTH(tags)) { 60 click = ClkTagBar; 61 arg.ui = 1 << i; 62 @@ -701,6 +709,8 @@ drawbar(Monitor *m) 63 int boxw = drw->fonts->h / 6 + 2; 64 unsigned int i, occ = 0, urg = 0; 65 Client *c; 66 + char tagdisp[64]; 67 + char *masterclientontag[LENGTH(tags)]; 68 69 /* draw status first so it can be overdrawn by tags later */ 70 if (m == selmon) { /* status is only drawn on selected monitor */ 71 @@ -709,20 +719,36 @@ drawbar(Monitor *m) 72 drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0); 73 } 74 75 + for (i = 0; i < LENGTH(tags); i++) 76 + masterclientontag[i] = NULL; 77 + 78 for (c = m->clients; c; c = c->next) { 79 - occ |= c->tags; 80 + occ |= c->tags == 255 ? 0 : c->tags; 81 if (c->isurgent) 82 urg |= c->tags; 83 + for (i = 0; i < LENGTH(tags); i++) 84 + if (!masterclientontag[i] && c->tags & (1<<i)) { 85 + XClassHint ch = { NULL, NULL }; 86 + XGetClassHint(dpy, c->win, &ch); 87 + masterclientontag[i] = ch.res_class; 88 + if (lcaselbl) 89 + masterclientontag[i][0] = tolower(masterclientontag[i][0]); 90 + } 91 } 92 x = 0; 93 for (i = 0; i < LENGTH(tags); i++) { 94 - w = TEXTW(tags[i]); 95 + /* do not draw vacant tags */ 96 + if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) 97 + continue; 98 + 99 + if (masterclientontag[i]) 100 + snprintf(tagdisp, 64, ptagf, tags[i], masterclientontag[i]); 101 + else 102 + snprintf(tagdisp, 64, etagf, tags[i]); 103 + masterclientontag[i] = tagdisp; 104 + tagw[i] = w = TEXTW(masterclientontag[i]); 105 drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); 106 - drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); 107 - if (occ & 1 << i) 108 - drw_rect(drw, x + boxs, boxs, boxw, boxw, 109 - m == selmon && selmon->sel && selmon->sel->tags & 1 << i, 110 - urg & 1 << i); 111 + drw_text(drw, x, 0, w, bh, lrpad / 2, masterclientontag[i], urg & 1 << i); 112 x += w; 113 } 114 w = blw = TEXTW(m->ltsymbol);