dwm-status2d-extrabar-6.2.diff - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
dwm-status2d-extrabar-6.2.diff (9655B) | |
--- | |
1 From e741941428f60f2d8c8d1125c965dec4cfc2d1ba Mon Sep 17 00:00:00 2001 | |
2 From: klassiker <[email protected]> | |
3 Date: Tue, 14 Jul 2020 15:23:06 +0200 | |
4 Subject: [PATCH] status2d patched with the extrabar patch for dwm 6.2 | |
5 | |
6 --- | |
7 config.def.h | 2 +- | |
8 dwm.c | 188 +++++++++++++++++++++++++++++++++++++++++++++------ | |
9 2 files changed, 169 insertions(+), 21 deletions(-) | |
10 | |
11 diff --git a/config.def.h b/config.def.h | |
12 index 1c0b587..8ce3e96 100644 | |
13 --- a/config.def.h | |
14 +++ b/config.def.h | |
15 @@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* borde… | |
16 static const unsigned int snap = 32; /* snap pixel */ | |
17 static const int showbar = 1; /* 0 means no bar */ | |
18 static const int topbar = 1; /* 0 means bottom bar */ | |
19 +static const char statussep = ';'; /* separator between st… | |
20 static const char *fonts[] = { "monospace:size=10" }; | |
21 static const char dmenufont[] = "monospace:size=10"; | |
22 static const char col_gray1[] = "#222222"; | |
23 @@ -112,4 +113,3 @@ static Button buttons[] = { | |
24 { ClkTagBar, MODKEY, Button1, tag, … | |
25 { ClkTagBar, MODKEY, Button3, togglet… | |
26 }; | |
27 - | |
28 diff --git a/dwm.c b/dwm.c | |
29 index 4465af1..f3c97c4 100644 | |
30 --- a/dwm.c | |
31 +++ b/dwm.c | |
32 @@ -117,6 +117,7 @@ struct Monitor { | |
33 int nmaster; | |
34 int num; | |
35 int by; /* bar geometry */ | |
36 + int eby; /* extra bar geometry */ | |
37 int mx, my, mw, mh; /* screen size */ | |
38 int wx, wy, ww, wh; /* window area */ | |
39 unsigned int seltags; | |
40 @@ -129,6 +130,7 @@ struct Monitor { | |
41 Client *stack; | |
42 Monitor *next; | |
43 Window barwin; | |
44 + Window extrabarwin; | |
45 const Layout *lt[2]; | |
46 }; | |
47 | |
48 @@ -163,6 +165,7 @@ static void detachstack(Client *c); | |
49 static Monitor *dirtomon(int dir); | |
50 static void drawbar(Monitor *m); | |
51 static void drawbars(void); | |
52 +static int drawstatusbar(Monitor *m, int bh, int extra, char* text); | |
53 static void enternotify(XEvent *e); | |
54 static void expose(XEvent *e); | |
55 static void focus(Client *c); | |
56 @@ -236,7 +239,8 @@ static void zoom(const Arg *arg); | |
57 | |
58 /* variables */ | |
59 static const char broken[] = "broken"; | |
60 -static char stext[256]; | |
61 +static char stext[1024]; | |
62 +static char estext[1024]; | |
63 static int screen; | |
64 static int sw, sh; /* X display screen geometry width, height… | |
65 static int bh, blw = 0; /* bar geometry */ | |
66 @@ -484,7 +488,7 @@ cleanup(void) | |
67 cleanupmon(mons); | |
68 for (i = 0; i < CurLast; i++) | |
69 drw_cur_free(drw, cursor[i]); | |
70 - for (i = 0; i < LENGTH(colors); i++) | |
71 + for (i = 0; i < LENGTH(colors) + 1; i++) | |
72 free(scheme[i]); | |
73 XDestroyWindow(dpy, wmcheckwin); | |
74 drw_free(drw); | |
75 @@ -505,7 +509,9 @@ cleanupmon(Monitor *mon) | |
76 m->next = mon->next; | |
77 } | |
78 XUnmapWindow(dpy, mon->barwin); | |
79 + XUnmapWindow(dpy, mon->extrabarwin); | |
80 XDestroyWindow(dpy, mon->barwin); | |
81 + XDestroyWindow(dpy, mon->extrabarwin); | |
82 free(mon); | |
83 } | |
84 | |
85 @@ -568,6 +574,7 @@ configurenotify(XEvent *e) | |
86 if (c->isfullscreen) | |
87 resizeclient(c, m->mx, … | |
88 XMoveResizeWindow(dpy, m->barwin, m->wx… | |
89 + XMoveResizeWindow(dpy, m->extrabarwin, … | |
90 } | |
91 focus(NULL); | |
92 arrange(NULL); | |
93 @@ -692,6 +699,119 @@ dirtomon(int dir) | |
94 return m; | |
95 } | |
96 | |
97 +int | |
98 +drawstatusbar(Monitor *m, int bh, int extra, char* stext) { | |
99 + int ret, i, w, x, len; | |
100 + short isCode = 0; | |
101 + char *text; | |
102 + char *p; | |
103 + | |
104 + len = strlen(stext) + 1 ; | |
105 + if (!(text = (char*) malloc(sizeof(char)*len))) | |
106 + die("malloc"); | |
107 + p = text; | |
108 + memcpy(text, stext, len); | |
109 + | |
110 + /* compute width of the status text */ | |
111 + w = 0; | |
112 + i = -1; | |
113 + while (text[++i]) { | |
114 + if (text[i] == '^') { | |
115 + if (!isCode) { | |
116 + isCode = 1; | |
117 + text[i] = '\0'; | |
118 + w += TEXTW(text) - lrpad; | |
119 + text[i] = '^'; | |
120 + if (text[++i] == 'f') | |
121 + w += atoi(text + ++i); | |
122 + } else { | |
123 + isCode = 0; | |
124 + text = text + i + 1; | |
125 + i = -1; | |
126 + } | |
127 + } | |
128 + } | |
129 + if (!isCode) | |
130 + w += TEXTW(text) - lrpad; | |
131 + else | |
132 + isCode = 0; | |
133 + text = p; | |
134 + | |
135 + if (extra) { | |
136 + w = m->ww; | |
137 + ret = x = 1; | |
138 + } else { | |
139 + w += 2; /* 1px padding on both sides */ | |
140 + ret = x = m->ww - w; | |
141 + } | |
142 + | |
143 + drw_setscheme(drw, scheme[LENGTH(colors)]); | |
144 + drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; | |
145 + drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; | |
146 + drw_rect(drw, x, 0, w, bh, 1, 1); | |
147 + x++; | |
148 + | |
149 + /* process status text */ | |
150 + i = -1; | |
151 + while (text[++i]) { | |
152 + if (text[i] == '^' && !isCode) { | |
153 + isCode = 1; | |
154 + | |
155 + text[i] = '\0'; | |
156 + w = TEXTW(text) - lrpad; | |
157 + drw_text(drw, x, 0, w, bh, 0, text, 0); | |
158 + | |
159 + x += w; | |
160 + | |
161 + /* process code */ | |
162 + while (text[++i] != '^') { | |
163 + if (text[i] == 'c') { | |
164 + char buf[8]; | |
165 + memcpy(buf, (char*)text+i+1, 7); | |
166 + buf[7] = '\0'; | |
167 + drw_clr_create(drw, &drw->schem… | |
168 + i += 7; | |
169 + } else if (text[i] == 'b') { | |
170 + char buf[8]; | |
171 + memcpy(buf, (char*)text+i+1, 7); | |
172 + buf[7] = '\0'; | |
173 + drw_clr_create(drw, &drw->schem… | |
174 + i += 7; | |
175 + } else if (text[i] == 'd') { | |
176 + drw->scheme[ColFg] = scheme[Sch… | |
177 + drw->scheme[ColBg] = scheme[Sch… | |
178 + } else if (text[i] == 'r') { | |
179 + int rx = atoi(text + ++i); | |
180 + while (text[++i] != ','); | |
181 + int ry = atoi(text + ++i); | |
182 + while (text[++i] != ','); | |
183 + int rw = atoi(text + ++i); | |
184 + while (text[++i] != ','); | |
185 + int rh = atoi(text + ++i); | |
186 + | |
187 + drw_rect(drw, rx + x, ry, rw, r… | |
188 + } else if (text[i] == 'f') { | |
189 + x += atoi(text + ++i); | |
190 + } | |
191 + } | |
192 + | |
193 + text = text + i + 1; | |
194 + i=-1; | |
195 + isCode = 0; | |
196 + } | |
197 + } | |
198 + | |
199 + if (!isCode) { | |
200 + w = TEXTW(text) - lrpad; | |
201 + drw_text(drw, x, 0, w, bh, 0, text, 0); | |
202 + } | |
203 + | |
204 + drw_setscheme(drw, scheme[SchemeNorm]); | |
205 + free(p); | |
206 + | |
207 + return ret; | |
208 +} | |
209 + | |
210 void | |
211 drawbar(Monitor *m) | |
212 { | |
213 @@ -703,9 +823,7 @@ drawbar(Monitor *m) | |
214 | |
215 /* draw status first so it can be overdrawn by tags later */ | |
216 if (m == selmon) { /* status is only drawn on selected monitor … | |
217 - drw_setscheme(drw, scheme[SchemeNorm]); | |
218 - sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ | |
219 - drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0); | |
220 + sw = m->ww - drawstatusbar(m, bh, 0, stext); | |
221 } | |
222 | |
223 for (c = m->clients; c; c = c->next) { | |
224 @@ -740,6 +858,11 @@ drawbar(Monitor *m) | |
225 } | |
226 } | |
227 drw_map(drw, m->barwin, 0, 0, m->ww, bh); | |
228 + | |
229 + if (m == selmon) { /* extra status is only drawn on selected mo… | |
230 + sw = drawstatusbar(m, bh, 1, estext); | |
231 + drw_map(drw, m->extrabarwin, 0, 0, m->ww, bh); | |
232 + } | |
233 } | |
234 | |
235 void | |
236 @@ -1567,7 +1690,8 @@ setup(void) | |
237 cursor[CurResize] = drw_cur_create(drw, XC_sizing); | |
238 cursor[CurMove] = drw_cur_create(drw, XC_fleur); | |
239 /* init appearance */ | |
240 - scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); | |
241 + scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *)); | |
242 + scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3); | |
243 for (i = 0; i < LENGTH(colors); i++) | |
244 scheme[i] = drw_scm_create(drw, colors[i], 3); | |
245 /* init bars */ | |
246 @@ -1702,6 +1826,7 @@ togglebar(const Arg *arg) | |
247 selmon->showbar = !selmon->showbar; | |
248 updatebarpos(selmon); | |
249 XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, … | |
250 + XMoveResizeWindow(dpy, selmon->extrabarwin, selmon->wx, selmon-… | |
251 arrange(selmon); | |
252 } | |
253 | |
254 @@ -1809,14 +1934,22 @@ updatebars(void) | |
255 }; | |
256 XClassHint ch = {"dwm", "dwm"}; | |
257 for (m = mons; m; m = m->next) { | |
258 - if (m->barwin) | |
259 - continue; | |
260 - m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->w… | |
261 - CopyFromParent, DefaultVisual(dpy, scre… | |
262 - CWOverrideRedirect|CWBackPixmap|CWEvent… | |
263 - XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor… | |
264 - XMapRaised(dpy, m->barwin); | |
265 - XSetClassHint(dpy, m->barwin, &ch); | |
266 + if (!m->barwin) { | |
267 + m->barwin = XCreateWindow(dpy, root, m->wx, m->… | |
268 + CopyFromParent, DefaultVisual(d… | |
269 + CWOverrideRedirect|CWBackPixmap… | |
270 + XDefineCursor(dpy, m->barwin, cursor[CurNormal]… | |
271 + XMapRaised(dpy, m->barwin); | |
272 + XSetClassHint(dpy, m->barwin, &ch); | |
273 + } | |
274 + if (!m->extrabarwin) { | |
275 + m->extrabarwin = XCreateWindow(dpy, root, m->wx… | |
276 + CopyFromParent, DefaultVisual(d… | |
277 + CWOverrideRedirect|CWBackPixmap… | |
278 + XDefineCursor(dpy, m->extrabarwin, cursor[CurNo… | |
279 + XMapRaised(dpy, m->extrabarwin); | |
280 + XSetClassHint(dpy, m->extrabarwin, &ch); | |
281 + } | |
282 } | |
283 } | |
284 | |
285 @@ -1825,12 +1958,15 @@ updatebarpos(Monitor *m) | |
286 { | |
287 m->wy = m->my; | |
288 m->wh = m->mh; | |
289 + m->wh -= bh * m->showbar * 2; | |
290 + m->wy = m->showbar ? m->wy + bh : m->wy; | |
291 if (m->showbar) { | |
292 - m->wh -= bh; | |
293 - m->by = m->topbar ? m->wy : m->wy + m->wh; | |
294 - m->wy = m->topbar ? m->wy + bh : m->wy; | |
295 - } else | |
296 + m->by = m->topbar ? m->wy - bh : m->wy + m->wh; | |
297 + m->eby = m->topbar ? m->wy + m->wh : m->wy - bh; | |
298 + } else { | |
299 m->by = -bh; | |
300 + m->eby = -bh; | |
301 + } | |
302 } | |
303 | |
304 void | |
305 @@ -1987,8 +2123,20 @@ updatesizehints(Client *c) | |
306 void | |
307 updatestatus(void) | |
308 { | |
309 - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) | |
310 + char text[2048]; | |
311 + if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) { | |
312 strcpy(stext, "dwm-"VERSION); | |
313 + estext[0] = '\0'; | |
314 + } else { | |
315 + char *e = strchr(text, statussep); | |
316 + if (e) { | |
317 + *e = '\0'; e++; | |
318 + strncpy(estext, e, sizeof(estext) - 1); | |
319 + } else { | |
320 + estext[0] = '\0'; | |
321 + } | |
322 + strncpy(stext, text, sizeof(stext) - 1); | |
323 + } | |
324 drawbar(selmon); | |
325 } | |
326 | |
327 @@ -2067,7 +2215,7 @@ wintomon(Window w) | |
328 if (w == root && getrootptr(&x, &y)) | |
329 return recttomon(x, y, 1, 1); | |
330 for (m = mons; m; m = m->next) | |
331 - if (w == m->barwin) | |
332 + if (w == m->barwin || w == m->extrabarwin) | |
333 return m; | |
334 if ((c = wintoclient(w))) | |
335 return c->mon; | |
336 -- | |
337 2.27.0 | |
338 |