summaryrefslogtreecommitdiffhomepage
path: root/patch/bar_taglabels.c
blob: 9e6d4412b9c6e6eebb5f97e39c29e301184383b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
int
width_taglabels(Bar *bar, BarArg *a)
{
	int w, i;
	Client *c;
	Monitor *m = bar->mon;
	char *icon;
	unsigned int occ = 0;

	for (c = m->clients; c; c = c->next)
		occ |= c->tags == 255 ? 0 : c->tags;

	for (w = 0, i = 0; i < NUMTAGS; i++) {
		m->taglabel[i][0] = '\0';
		#if BAR_HIDEVACANTTAGS_PATCH
		if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
			continue;
		#endif // BAR_HIDEVACANTTAGS_PATCH
		icon = tagicon(m, i);
		XClassHint ch = { NULL, NULL };
		for (c = m->clients; c; c = c->next) {
			if (c->tags & (1 << i)) {
				XGetClassHint(dpy, c->win, &ch);
				break;
			}
		}
		if (ch.res_class) {
			if (lcaselbl)
				ch.res_class[0] = tolower(ch.res_class[0]);
			snprintf(m->taglabel[i], 64, ptagf, icon, ch.res_class);
		} else
			snprintf(m->taglabel[i], 64, etagf, icon);

		w += TEXTW(m->taglabel[i]);
	}
	return w;
}

int
draw_taglabels(Bar *bar, BarArg *a)
{
	int invert = 0;
	int w, x = a->x;
	unsigned int i, occ = 0, urg = 0;
	Client *c;
	Monitor *m = bar->mon;

	for (c = m->clients; c; c = c->next)
		if (c->isurgent)
			urg |= c->tags;

	for (i = 0; i < NUMTAGS; i++) {
		/* do not draw vacant tags */
		if (!m->taglabel[i][0])
			continue;
		drw_setscheme(drw, scheme[
			m->tagset[m->seltags] & 1 << i
			? SchemeTagsSel
			: urg & 1 << i
			? SchemeUrg
			: SchemeTagsNorm
		]);
		w = TEXTW(m->taglabel[i]);
		drw_text(drw, x, a->y, w, a->h, lrpad / 2, m->taglabel[i], invert, False);
		drawindicator(m, NULL, occ, x, a->y, w, a->h, i, -1, invert, tagindicatortype);
		#if BAR_UNDERLINETAGS_PATCH
		if (ulineall || m->tagset[m->seltags] & 1 << i)
			drw_rect(drw, x + ulinepad, bh - ulinestroke - ulinevoffset, w - (ulinepad * 2), ulinestroke, 1, 0);
		#endif // BAR_UNDERLINETAGS_PATCH
		x += w;
	}

	return 1;
}

int
click_taglabels(Bar *bar, Arg *arg, BarArg *a)
{
	int i = 0, x = lrpad / 2;
	Monitor *m = bar->mon;

	do {
		if (!m->taglabel[i][0])
			continue;
		x += TEXTW(m->taglabel[i]);
	} while (a->x >= x && ++i < NUMTAGS);
	if (i < NUMTAGS) {
		arg->ui = 1 << i;
	}
	return ClkTagBar;
}