summaryrefslogtreecommitdiffhomepage
path: root/patch/bar_statuscolors.c
blob: 7ecb0493d8bed24b7574e269c6e5834e81090ef7 (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
92
93
94
95
96
97
98
99
100
101
102
int
width_statuscolors(Bar *bar, BarArg *a)
{
	#if BAR_STATUSCMD_PATCH
	return textw_wosc(rawstext);
	#else
	return textw_wosc(stext);
	#endif // BAR_STATUSCMD_PATCH
}

#if BAR_EXTRASTATUS_PATCH
int
width_statuscolors_es(Bar *bar, BarArg *a)
{
	#if BAR_STATUSCMD_PATCH
	return textw_wosc(rawestext);
	#else
	return textw_wosc(estext);
	#endif // BAR_STATUSCMD_PATCH
}
#endif // BAR_EXTRASTATUS_PATCH

int
draw_statuscolors(Bar *bar, BarArg *a)
{
	#if BAR_STATUSCMD_PATCH
	return draw_wosc(bar, a, rawstext);
	#else
	return draw_wosc(bar, a, stext);
	#endif // BAR_STATUSCMD_PATCH
}

#if BAR_EXTRASTATUS_PATCH
int
draw_statuscolors_es(Bar *bar, BarArg *a)
{
	#if BAR_STATUSCMD_PATCH
	return draw_wosc(bar, a, rawestext);
	#else
	return draw_wosc(bar, a, estext);
	#endif // BAR_STATUSCMD_PATCH
}
#endif // BAR_EXTRASTATUS_PATCH

#if !BAR_STATUSCMD_PATCH
int
click_statuscolors(Bar *bar, Arg *arg, BarArg *a)
{
	return ClkStatusText;
}
#endif // BAR_STATUSCMD_PATCH

int
textw_wosc(char *s)
{
	char *ts = s;
	char *tp = s;
	int sw = 0;
	char ctmp;
	while (1) {
		if ((unsigned int)*ts > LENGTH(colors)) {
			ts++;
			continue;
		}
		ctmp = *ts;
		*ts = '\0';
		sw += drw_fontset_getwidth(drw, tp, True);
		*ts = ctmp;
		if (ctmp == '\0')
			break;
		tp = ++ts;
	}

	return sw;
}

int
draw_wosc(Bar *bar, BarArg *a, char *s)
{
	char *ts = s;
	char *tp = s;
	int tx = 0;
	char ctmp;

	while (1) {
		if ((unsigned int)*ts > LENGTH(colors)) {
			ts++;
			continue;
		}
		ctmp = *ts;
		*ts = '\0';
		drw_text(drw, a->x + tx, a->y, a->w - tx, a->h, 0, tp, 0, True);
		tx += TEXTW(tp) - lrpad;
		if (ctmp == '\0')
			break;
		drw_setscheme(drw, scheme[(unsigned int)(ctmp-1)]);
		*ts = ctmp;
		tp = ++ts;
	}

	return 1;
}