dwm: Hide vacant tags

This patch prevents dwm from drawing tags with no clients (i.e. vacant)
on the bar.

It also makes sure that pressing a tag on the bar behaves accordingly by
not reserving reactive regions on the bar for vacant tags.

It also stops drawing empty rectangles on the bar for non-vacant tags as
there is no need anymore to distinguish vacant tags and it offers a more
visible contrast than if there were filled/empty rectangles.
This commit is contained in:
Sanchayan Maity 2020-10-15 15:22:18 +05:30
parent 7433d261b2
commit 7729d3e9c7

21
dwm.c
View file

@ -454,7 +454,7 @@ attachstack(Client *c)
void
buttonpress(XEvent *e)
{
unsigned int i, x, click;
unsigned int i, x, click, occ = 0;
Arg arg = {0};
Client *c;
Monitor *m;
@ -469,9 +469,14 @@ buttonpress(XEvent *e)
}
if (ev->window == selmon->barwin) {
i = x = 0;
do
for (c = m->clients; c; c = c->next)
occ |= c->tags == 255 ? 0 : c->tags;
do {
/* do not reserve space for vacant tags */
if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
continue;
x += TEXTW(tags[i]);
while (ev->x >= x && ++i < LENGTH(tags));
} while (ev->x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
click = ClkTagBar;
arg.ui = 1 << i;
@ -747,19 +752,19 @@ drawbar(Monitor *m)
}
for (c = m->clients; c; c = c->next) {
occ |= c->tags;
occ |= c->tags == 255 ? 0 : c->tags;
if (c->isurgent)
urg |= c->tags;
}
x = 0;
for (i = 0; i < LENGTH(tags); i++) {
/* do not draw vacant tags */
if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
continue;
w = TEXTW(tags[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);
if (occ & 1 << i)
drw_rect(drw, x + boxs, boxs, boxw, boxw,
m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
urg & 1 << i);
x += w;
}
w = blw = TEXTW(m->ltsymbol);