-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathdwm-barmodules-status2d-6.3.diff
346 lines (342 loc) · 9.1 KB
/
dwm-barmodules-status2d-6.3.diff
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
From 0e8657c854a01ff5f6bc8e29f348a6a9217ecc4e Mon Sep 17 00:00:00 2001
From: Bakkeby <bakkeby@gmail.com>
Date: Mon, 24 Jun 2024 10:33:10 +0200
Subject: [PATCH 2/2] Adding status2d module
---
config.def.h | 2 +-
dwm.c | 7 +-
patch/bar_status2d.c | 225 +++++++++++++++++++++++++++++++++++++++++++
patch/bar_status2d.h | 13 +++
patch/include.c | 5 +-
patch/include.h | 5 +-
6 files changed, 249 insertions(+), 8 deletions(-)
create mode 100644 patch/bar_status2d.c
create mode 100644 patch/bar_status2d.h
diff --git a/config.def.h b/config.def.h
index f870c41..299974a 100644
--- a/config.def.h
+++ b/config.def.h
@@ -47,7 +47,7 @@ static const BarRule barrules[] = {
/* monitor bar alignment widthfunc drawfunc clickfunc name */
{ -1, 0, BAR_ALIGN_LEFT, width_tags, draw_tags, click_tags, "tags" },
{ -1, 0, BAR_ALIGN_LEFT, width_ltsymbol, draw_ltsymbol, click_ltsymbol, "layout" },
- { 'A', 0, BAR_ALIGN_RIGHT, width_status, draw_status, click_status, "status" },
+ { 'A', 0, BAR_ALIGN_RIGHT, width_status2d, draw_status2d, click_status2d, "status2d" },
{ -1, 0, BAR_ALIGN_NONE, width_wintitle, draw_wintitle, click_wintitle, "wintitle" },
};
diff --git a/dwm.c b/dwm.c
index 86763d8..10f9220 100644
--- a/dwm.c
+++ b/dwm.c
@@ -290,7 +290,7 @@ static void zoom(const Arg *arg);
#include "patch/include.h"
/* variables */
static const char broken[] = "broken";
-static char stext[256];
+static char stext[1024];
static int screen;
static int sw, sh; /* X display screen geometry width, height */
static int bh; /* bar geometry */
@@ -558,7 +558,7 @@ cleanup(void)
cleanupmon(mons);
for (i = 0; i < CurLast; i++)
drw_cur_free(drw, cursor[i]);
- for (i = 0; i < LENGTH(colors); i++)
+ for (i = 0; i < LENGTH(colors) + 1; i++)
free(scheme[i]);
XDestroyWindow(dpy, wmcheckwin);
drw_free(drw);
@@ -1727,7 +1727,8 @@ setup(void)
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
/* init appearance */
- scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
+ scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *));
+ scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3);
for (i = 0; i < LENGTH(colors); i++)
scheme[i] = drw_scm_create(drw, colors[i], 3);
/* init bars */
diff --git a/patch/bar_status2d.c b/patch/bar_status2d.c
new file mode 100644
index 0000000..5863d44
--- /dev/null
+++ b/patch/bar_status2d.c
@@ -0,0 +1,225 @@
+int
+width_status2d(Bar *bar, BarWidthArg *a)
+{
+ #if BAR_STATUSCMD_PATCH
+ return status2dtextlength(rawstext) + lrpad;
+ #else
+ return status2dtextlength(stext) + lrpad;
+ #endif // BAR_STATUSCMD_PATCH
+}
+
+#if BAR_EXTRASTATUS_PATCH
+int
+width_status2d_es(Bar *bar, BarWidthArg *a)
+{
+ #if BAR_STATUSCMD_PATCH
+ return status2dtextlength(rawestext);
+ #else
+ return status2dtextlength(estext);
+ #endif // BAR_STATUSCMD_PATCH
+}
+#endif // BAR_EXTRASTATUS_PATCH
+
+int
+draw_status2d(Bar *bar, BarDrawArg *a)
+{
+ #if BAR_STATUSCMD_PATCH
+ return drawstatusbar(a->x, rawstext);
+ #else
+ return drawstatusbar(a->x, stext);
+ #endif // BAR_STATUSCMD_PATCH
+}
+
+#if BAR_EXTRASTATUS_PATCH
+int
+draw_status2d_es(Bar *bar, BarDrawArg *a)
+{
+ #if BAR_STATUSCMD_PATCH
+ return drawstatusbar(a->x, rawestext);
+ #else
+ return drawstatusbar(a->x, estext);
+ #endif // BAR_STATUSCMD_PATCH
+}
+#endif // BAR_EXTRASTATUS_PATCH
+
+#if !BAR_STATUSCMD_PATCH
+int
+click_status2d(Bar *bar, Arg *arg, BarClickArg *a)
+{
+ return ClkStatusText;
+}
+#endif // BAR_STATUSCMD_PATCH
+
+int
+drawstatusbar(int x, char* stext)
+{
+ int i, w, len;
+ short isCode = 0;
+ char *text;
+ char *p;
+
+ len = strlen(stext);
+ if (!(text = (char*) malloc(sizeof(char)*(len + 1))))
+ die("malloc");
+ p = text;
+ #if BAR_STATUSCMD_PATCH
+ copyvalidchars(text, stext);
+ #else
+ memcpy(text, stext, len);
+ #endif // BAR_STATUSCMD_PATCH
+ text[len] = '\0';
+
+ x += lrpad / 2;
+ drw_setscheme(drw, scheme[LENGTH(colors)]);
+ drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
+ drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
+
+ /* process status text */
+ i = -1;
+ while (text[++i]) {
+ if (text[i] == '^' && !isCode) {
+ isCode = 1;
+
+ text[i] = '\0';
+ #if BAR_PANGO_PATCH
+ w = TEXTWM(text) - lrpad;
+ drw_text(drw, x, 0, w, bh, 0, text, 0, True);
+ #else
+ w = TEXTW(text) - lrpad;
+ drw_text(drw, x, 0, w, bh, 0, text, 0);
+ #endif // BAR_PANGO_PATCH
+
+ x += w;
+
+ /* process code */
+ while (text[++i] != '^') {
+ if (text[i] == 'c') {
+ char buf[8];
+ if (i + 7 > len - 1) {
+ i += 7;
+ len = 0;
+ break;
+ }
+ memcpy(buf, (char*)text+i+1, 7);
+ buf[7] = '\0';
+ #if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
+ drw_clr_create(drw, &drw->scheme[ColFg], buf, 0xff);
+ #elif BAR_ALPHA_PATCH
+ drw_clr_create(drw, &drw->scheme[ColFg], buf, alphas[SchemeNorm][ColFg]);
+ #else
+ drw_clr_create(drw, &drw->scheme[ColFg], buf);
+ #endif // BAR_ALPHA_PATCH
+ i += 7;
+ } else if (text[i] == 'b') {
+ char buf[8];
+ if (i + 7 > len - 1) {
+ i += 7;
+ len = 0;
+ break;
+ }
+ memcpy(buf, (char*)text+i+1, 7);
+ buf[7] = '\0';
+ #if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
+ drw_clr_create(drw, &drw->scheme[ColBg], buf, 0xff);
+ #elif BAR_ALPHA_PATCH
+ drw_clr_create(drw, &drw->scheme[ColBg], buf, alphas[SchemeNorm][ColBg]);
+ #else
+ drw_clr_create(drw, &drw->scheme[ColBg], buf);
+ #endif // BAR_ALPHA_PATCH
+ i += 7;
+ } else if (text[i] == 'd') {
+ drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
+ drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
+ } else if (text[i] == 'r') {
+ int rx = atoi(text + ++i);
+ while (text[++i] != ',');
+ int ry = atoi(text + ++i);
+ while (text[++i] != ',');
+ int rw = atoi(text + ++i);
+ while (text[++i] != ',');
+ int rh = atoi(text + ++i);
+
+ if (ry < 0)
+ ry = 0;
+ if (rx < 0)
+ rx = 0;
+
+ drw_rect(drw, rx + x, ry, rw, rh, 1, 0);
+ } else if (text[i] == 'f') {
+ x += atoi(text + ++i);
+ }
+ }
+
+ text = text + i + 1;
+ len -= i + 1;
+ i=-1;
+ isCode = 0;
+ }
+ }
+ if (!isCode && len) {
+ #if BAR_PANGO_PATCH
+ w = TEXTWM(text) - lrpad;
+ drw_text(drw, x, 0, w, bh, 0, text, 0, True);
+ #else
+ w = TEXTW(text) - lrpad;
+ drw_text(drw, x, 0, w, bh, 0, text, 0);
+ #endif // BAR_PANGO_PATCH
+ x += w;
+ }
+ free(p);
+
+ drw_setscheme(drw, scheme[SchemeNorm]);
+
+ return x;
+}
+
+int
+status2dtextlength(char* stext)
+{
+ int i, w, len;
+ short isCode = 0;
+ char *text;
+ char *p;
+
+ len = strlen(stext) + 1;
+ if (!(text = (char*) malloc(sizeof(char)*len)))
+ die("malloc");
+ p = text;
+ #if BAR_STATUSCMD_PATCH
+ copyvalidchars(text, stext);
+ #else
+ memcpy(text, stext, len);
+ #endif // BAR_STATUSCMD_PATCH
+
+ /* compute width of the status text */
+ w = 0;
+ i = -1;
+ while (text[++i]) {
+ if (text[i] == '^') {
+ if (!isCode) {
+ isCode = 1;
+ text[i] = '\0';
+ #if BAR_PANGO_PATCH
+ w += TEXTWM(text) - lrpad;
+ #else
+ w += TEXTW(text) - lrpad;
+ #endif // BAR_PANGO_PATCH
+ text[i] = '^';
+ if (text[++i] == 'f')
+ w += atoi(text + ++i);
+ } else {
+ isCode = 0;
+ text = text + i + 1;
+ i = -1;
+ }
+ }
+ }
+ if (!isCode)
+ #if BAR_PANGO_PATCH
+ w += TEXTWM(text) - lrpad;
+ #else
+ w += TEXTW(text) - lrpad;
+ #endif // BAR_PANGO_PATCH
+ free(p);
+ return w;
+}
\ No newline at end of file
diff --git a/patch/bar_status2d.h b/patch/bar_status2d.h
new file mode 100644
index 0000000..ea48dd3
--- /dev/null
+++ b/patch/bar_status2d.h
@@ -0,0 +1,13 @@
+static int width_status2d(Bar *bar, BarWidthArg *a);
+#if BAR_EXTRASTATUS_PATCH
+static int width_status2d_es(Bar *bar, BarWidthArg *a);
+#endif // BAR_EXTRASTATUS_PATCH
+static int draw_status2d(Bar *bar, BarDrawArg *a);
+#if BAR_EXTRASTATUS_PATCH
+static int draw_status2d_es(Bar *bar, BarDrawArg *a);
+#endif // BAR_EXTRASTATUS_PATCH
+#if !BAR_STATUSCMD_PATCH
+static int click_status2d(Bar *bar, Arg *arg, BarClickArg *a);
+#endif // BAR_STATUSCMD_PATCH
+static int drawstatusbar(int x, char *text);
+static int status2dtextlength(char *stext);
\ No newline at end of file
diff --git a/patch/include.c b/patch/include.c
index d422f56..77eafa3 100644
--- a/patch/include.c
+++ b/patch/include.c
@@ -1,5 +1,6 @@
/* Bar functionality */
#include "bar_ltsymbol.c"
-#include "bar_status.c"
+//#include "bar_status.c"
#include "bar_tags.c"
-#include "bar_wintitle.c"
\ No newline at end of file
+#include "bar_wintitle.c"
+#include "bar_status2d.c"
\ No newline at end of file
diff --git a/patch/include.h b/patch/include.h
index 5f9a3fe..2927238 100644
--- a/patch/include.h
+++ b/patch/include.h
@@ -1,5 +1,6 @@
/* Bar functionality */
#include "bar_ltsymbol.h"
-#include "bar_status.h"
+//#include "bar_status.h"
#include "bar_tags.h"
-#include "bar_wintitle.h"
\ No newline at end of file
+#include "bar_wintitle.h"
+#include "bar_status2d.h"
\ No newline at end of file
--
2.45.2