summaryrefslogtreecommitdiffstats
path: root/dwl-patches/patches/barcolors/barcolors.patch
blob: b95f78ee7943576889a8242032a6baf05932d1e6 (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
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
142
143
144
From d2b529d9ebee6b2e625afd5c89c2ede5bb0ca91b Mon Sep 17 00:00:00 2001
From: Kerberoge <sjoerdenjh@gmail.com>
Date: Sun, 25 Aug 2024 22:41:55 +0200
Subject: [PATCH 1/1] updated barcolors

---
 dwl.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 87 insertions(+), 6 deletions(-)

diff --git a/dwl.c b/dwl.c
index ece537a..6663399 100644
--- a/dwl.c
+++ b/dwl.c
@@ -83,6 +83,7 @@
 #define LISTEN(E, L, H)         wl_signal_add((E), ((L)->notify = (H), (L)))
 #define LISTEN_STATIC(E, H)     do { static struct wl_listener _l = {.notify = (H)}; wl_signal_add((E), &_l); } while (0)
 #define TEXTW(mon, text)        (drwl_font_getwidth(mon->drw, text) + mon->lrpad)
+#define PREFIX(str, prefix)     !strncmp(str, prefix, strlen(prefix))
 
 /* enums */
 enum { SchemeNorm, SchemeSel, SchemeUrg }; /* color schemes */
@@ -318,6 +319,7 @@ static void destroykeyboardgroup(struct wl_listener *listener, void *data);
 static Monitor *dirtomon(enum wlr_direction dir);
 static void drawbar(Monitor *m);
 static void drawbars(void);
+static int drawstatus(Monitor *m);
 static void focusclient(Client *c, int lift);
 static void focusmon(const Arg *arg);
 static void focusstack(const Arg *arg);
@@ -448,7 +450,7 @@ static struct wlr_box sgeom;
 static struct wl_list mons;
 static Monitor *selmon;
 
-static char stext[256];
+static char stext[512];
 static struct wl_event_source *status_event_source;
 
 static const struct wlr_buffer_impl buffer_impl = {
@@ -1519,11 +1521,8 @@ drawbar(Monitor *m)
 		return;
 
 	/* draw status first so it can be overdrawn by tags later */
-	if (m == selmon) { /* status is only drawn on selected monitor */
-		drwl_setscheme(m->drw, colors[SchemeNorm]);
-		tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */
-		drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0);
-	}
+	if (m == selmon) /* status is only drawn on selected monitor */
+		tw = drawstatus(m);
 
 	wl_list_for_each(c, &clients, link) {
 		if (c->mon != m)
@@ -1577,6 +1576,88 @@ drawbars(void)
 		drawbar(m);
 }
 
+int
+drawstatus(Monitor *m)
+{
+	int x, tw, iw;
+	char rstext[512] = "";
+	char *p, *argstart, *argend, *itext;
+	uint32_t scheme[3], *color;
+
+	/* calculate real width of stext */
+	for (p = stext; *p; p++) {
+		if (PREFIX(p, "^^")) {
+			strncat(rstext, p, 2);
+			p++;
+		} else if (PREFIX(p, "^fg(") || PREFIX(p, "^bg(")) {
+			argend = strchr(p, ')');
+			if (!argend) { /* ignore this command */
+				argstart = strchr(p, '(') + 1;
+				strncat(rstext, p, argstart - p);
+				p = argstart - 1;
+			} else {
+				p = argend;
+			}
+		} else {
+			strncat(rstext, p, 1);
+		}
+	}
+	tw = TEXTW(m, rstext) - m->lrpad;
+
+	x = m->b.width - tw;
+	itext = stext;
+	scheme[0] = colors[SchemeNorm][0];
+	scheme[1] = colors[SchemeNorm][1];
+	drwl_setscheme(m->drw, scheme);
+	for (p = stext; *p; p++) {
+		if (PREFIX(p, "^^")) {
+			p++;
+		} else if (PREFIX(p, "^fg(") || PREFIX(p, "^bg(")) {
+			argstart = strchr(p, '(') + 1;
+			argend = strchr(argstart, ')');
+			if (!argend) { /* ignore this command */
+				p = argstart - 1;
+				continue;
+			}
+
+			*p = '\0';
+			iw = TEXTW(m, itext) - m->lrpad;
+			if (*itext) /* only draw text if there is something to draw */
+				x = drwl_text(m->drw, x, 0, iw, m->b.height, 0, itext, 0);
+			*p = '^';
+
+			if (PREFIX(p, "^fg("))
+				color = &scheme[0];
+			else
+				color = &scheme[1];
+
+			if (argend != argstart) {
+				*argend = '\0';
+				*color = strtoul(argstart, NULL, 16);
+				*color = *color << 8 | 0xff; /* add alpha channel */
+				*argend = ')';
+			} else {
+				*color = 0; /* reset */
+			}
+
+			/* reset color back to normal if none was provided */
+			if (!scheme[0])
+				scheme[0] = colors[SchemeNorm][0];
+			if (!scheme[1])
+				scheme[1] = colors[SchemeNorm][1];
+
+			itext = argend + 1;
+			drwl_setscheme(m->drw, scheme);
+			p = argend;
+		}
+	}
+	iw = TEXTW(m, itext) - m->lrpad;
+	if (*itext)
+		drwl_text(m->drw, x, 0, iw, m->b.height, 0, itext, 0);
+
+	return tw;
+}
+
 void
 focusclient(Client *c, int lift)
 {
-- 
2.48.1