~kris/suckless

dwm

ref: 99a17f8a00f1d4c2de62b1115db338207ddce547 dwm/patch/bar_taglabels.c -rw-r--r-- 3.2 KiB
99a17f8a — Kris Yotam Rebind application keys to dmenu scripts and add reading mode layout 7 months ago
                                                                                
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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, a->y + 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;
	}
	#if BAR_TAGPREVIEW_PATCH
	if (selmon->previewshow != 0) {
		hidetagpreview(selmon);
	}
	#endif // BAR_TAGPREVIEW_PATCH
	return ClkTagBar;
}

int
hover_taglabels(Bar *bar, BarArg *a, XMotionEvent *ev)
{
	#if BAR_TAGPREVIEW_PATCH
	int i = 0, x = lrpad / 2;
	int px, py;
	Monitor *m = bar->mon;
	#if VANITYGAPS_PATCH
	int ov = gappov;
	int oh = gappoh;
	#else
	int ov = 0;
	int oh = 0;
	#endif // VANITYGAPS_PATCH

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

	if (i < NUMTAGS) {
		if ((i + 1) != selmon->previewshow && !(selmon->tagset[selmon->seltags] & 1 << i)) {
			if (bar->by > m->my + m->mh / 2) // bottom bar
				py = bar->by - m->mh / scalepreview - oh;
			else // top bar
				py = bar->by + bar->bh + oh;
			px = bar->bx + ev->x - m->mw / scalepreview / 2;
			if (px + m->mw / scalepreview > m->mx + m->mw)
				px = m->wx + m->ww - m->mw / scalepreview - ov;
			else if (px < bar->bx)
				px = m->wx + ov;
			selmon->previewshow = i + 1;
			showtagpreview(i, px, py);
		} else if (selmon->tagset[selmon->seltags] & 1 << i) {
			hidetagpreview(selmon);
		}
	} else if (selmon->previewshow != 0) {
		hidetagpreview(selmon);
	}
	#endif // BAR_TAGPREVIEW_PATCH

	return 1;
}