speedwm-personal/bar/tags.c

68 lines
1.2 KiB
C
Raw Normal View History

int
width_tags(Bar *bar, BarWidthArg *a)
{
2022-12-04 22:20:17 +01:00
if (selmon->hidetags) {
2022-12-04 22:03:42 +01:00
return 0;
2022-12-04 22:20:17 +01:00
}
2022-12-04 22:03:42 +01:00
int w, i;
for (w = 0, i = 0; i < LENGTH(tags); i++) {
w += TEXTW(tags[i]);
}
return w;
}
int
draw_tags(Bar *bar, BarDrawArg *a)
{
2022-12-04 22:20:17 +01:00
if (selmon->hidetags) {
2022-12-04 22:03:42 +01:00
return 0;
2022-12-04 22:20:17 +01:00
}
2022-12-04 22:03:42 +01:00
int invert;
int w, x = a->x;
2022-12-03 23:12:58 +01:00
int boxs = drw->font->h / 9;
int boxw = drw->font->h / 6 + 2;
unsigned int i, occ = 0, urg = 0;
Client *c;
Monitor *m = bar->mon;
2022-12-03 23:12:58 +01:00
for (c = m->clients; c; c = c->next) {
occ |= c->tags;
if (c->isurgent)
urg |= c->tags;
}
for (i = 0; i < LENGTH(tags); i++) {
invert = urg & 1 << i;
w = TEXTW(tags[i]);
drw_setscheme(drw, (m->tagset[m->seltags] & 1 << i ? tagscheme[i] : scheme[SchemeBar]));
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], invert, False);
if (occ & 1 << i)
drw_rect(drw, x + boxs, boxs, boxw, boxw,
m == selmon && selmon->sel && selmon->sel->tags & 1 << i, invert);
x += w;
}
2022-12-03 23:12:58 +01:00
return x;
}
int
click_tags(Bar *bar, Arg *arg, BarClickArg *a)
{
2022-12-04 22:20:17 +01:00
if (selmon->hidetags) {
2022-12-04 22:03:42 +01:00
return 0;
2022-12-04 22:20:17 +01:00
}
2022-12-04 22:03:42 +01:00
int i = 0, x = lrpad / 2;
do {
x += TEXTW(tags[i]);
} while (a->rel_x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
arg->ui = 1 << i;
}
return ClkTagBar;
}