Introduction
Introduction Statistics Contact Development Disclaimer Help
dwm-awesomebar-statuscmd-signal-6.2.diff - sites - public wiki contents of suck…
git clone git://git.suckless.org/sites
Log
Files
Refs
---
dwm-awesomebar-statuscmd-signal-6.2.diff (12005B)
---
1 diff --git a/config.def.h b/config.def.h
2 index 1c0b587..ad25aee 100644
3 --- a/config.def.h
4 +++ b/config.def.h
5 @@ -16,6 +16,7 @@ static const char *colors[][3] = {
6 /* fg bg border */
7 [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
8 [SchemeSel] = { col_gray4, col_cyan, col_cyan },
9 + [SchemeHid] = { col_cyan, col_gray1, col_cyan },
10 };
11
12 /* tagging */
13 @@ -102,8 +103,11 @@ static Button buttons[] = {
14 /* click event mask button functio…
15 { ClkLtSymbol, 0, Button1, setlayo…
16 { ClkLtSymbol, 0, Button3, setlayo…
17 + { ClkWinTitle, 0, Button1, togglew…
18 { ClkWinTitle, 0, Button2, zoom, …
19 - { ClkStatusText, 0, Button2, spawn, …
20 + { ClkStatusText, 0, Button1, sigdwmb…
21 + { ClkStatusText, 0, Button2, sigdwmb…
22 + { ClkStatusText, 0, Button3, sigdwmb…
23 { ClkClientWin, MODKEY, Button1, movemou…
24 { ClkClientWin, MODKEY, Button2, togglef…
25 { ClkClientWin, MODKEY, Button3, resizem…
26 diff --git a/dwm.c b/dwm.c
27 index 4465af1..d99337e 100644
28 --- a/dwm.c
29 +++ b/dwm.c
30 @@ -50,6 +50,7 @@
31 #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - …
32 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - …
33 #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->selt…
34 +#define HIDDEN(C) ((getstate(C->win) == IconicState))
35 #define LENGTH(X) (sizeof X / sizeof X[0])
36 #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
37 #define WIDTH(X) ((X)->w + 2 * (X)->bw)
38 @@ -59,7 +60,7 @@
39
40 /* enums */
41 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
42 -enum { SchemeNorm, SchemeSel }; /* color schemes */
43 +enum { SchemeNorm, SchemeSel, SchemeHid }; /* color schemes */
44 enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
45 NetWMFullscreen, NetActiveWindow, NetWMWindowType,
46 NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
47 @@ -117,6 +118,8 @@ struct Monitor {
48 int nmaster;
49 int num;
50 int by; /* bar geometry */
51 + int btw; /* width of tasks portion of bar */
52 + int bt; /* number of tasks */
53 int mx, my, mw, mh; /* screen size */
54 int wx, wy, ww, wh; /* window area */
55 unsigned int seltags;
56 @@ -156,6 +159,7 @@ static void clientmessage(XEvent *e);
57 static void configure(Client *c);
58 static void configurenotify(XEvent *e);
59 static void configurerequest(XEvent *e);
60 +static void copyvalidchars(char *text, char *rawtext);
61 static Monitor *createmon(void);
62 static void destroynotify(XEvent *e);
63 static void detach(Client *c);
64 @@ -169,11 +173,13 @@ static void focus(Client *c);
65 static void focusin(XEvent *e);
66 static void focusmon(const Arg *arg);
67 static void focusstack(const Arg *arg);
68 +static int getdwmblockspid();
69 static int getrootptr(int *x, int *y);
70 static long getstate(Window w);
71 static int gettextprop(Window w, Atom atom, char *text, unsigned int si…
72 static void grabbuttons(Client *c, int focused);
73 static void grabkeys(void);
74 +static void hide(Client *c);
75 static void incnmaster(const Arg *arg);
76 static void keypress(XEvent *e);
77 static void killclient(const Arg *arg);
78 @@ -203,8 +209,10 @@ static void setlayout(const Arg *arg);
79 static void setmfact(const Arg *arg);
80 static void setup(void);
81 static void seturgent(Client *c, int urg);
82 +static void show(Client *c);
83 static void showhide(Client *c);
84 static void sigchld(int unused);
85 +static void sigdwmblocks(const Arg *arg);
86 static void spawn(const Arg *arg);
87 static void tag(const Arg *arg);
88 static void tagmon(const Arg *arg);
89 @@ -213,6 +221,7 @@ static void togglebar(const Arg *arg);
90 static void togglefloating(const Arg *arg);
91 static void toggletag(const Arg *arg);
92 static void toggleview(const Arg *arg);
93 +static void togglewin(const Arg *arg);
94 static void unfocus(Client *c, int setfocus);
95 static void unmanage(Client *c, int destroyed);
96 static void unmapnotify(XEvent *e);
97 @@ -237,6 +246,9 @@ static void zoom(const Arg *arg);
98 /* variables */
99 static const char broken[] = "broken";
100 static char stext[256];
101 +static char rawstext[256];
102 +static int dwmblockssig;
103 +pid_t dwmblockspid = 0;
104 static int screen;
105 static int sw, sh; /* X display screen geometry width, height…
106 static int bh, blw = 0; /* bar geometry */
107 @@ -439,10 +451,42 @@ buttonpress(XEvent *e)
108 arg.ui = 1 << i;
109 } else if (ev->x < x + blw)
110 click = ClkLtSymbol;
111 - else if (ev->x > selmon->ww - TEXTW(stext))
112 - click = ClkStatusText;
113 - else
114 - click = ClkWinTitle;
115 + /* 2px right padding */
116 + else if (ev->x > (selmon->ww - TEXTW(stext) + lrpad) - …
117 + x = selmon->ww - TEXTW(stext) + lrpad - 2;
118 + click = ClkStatusText;
119 + char *text = rawstext;
120 + int i = -1;
121 + char ch;
122 + dwmblockssig = 0;
123 + while (text[++i]) {
124 + if ((unsigned char)text[i] < ' ') {
125 + ch = text[i];
126 + text[i] = '\0';
127 + x += TEXTW(text) - lrpad;
128 + text[i] = ch;
129 + text += i+1;
130 + i = -1;
131 + if (x >= ev->x) break;
132 + dwmblockssig = ch;
133 + }
134 + }
135 + } else {
136 + x += blw;
137 + c = m->clients;
138 +
139 + if (c) {
140 + do {
141 + if (!ISVISIBLE(c))
142 + continue;
143 + else
144 + x += (1.0 / (double)m->…
145 + } while (ev->x > x && (c = c->next));
146 +
147 + click = ClkWinTitle;
148 + arg.v = c;
149 + }
150 + }
151 } else if ((c = wintoclient(ev->window))) {
152 focus(c);
153 restack(selmon);
154 @@ -452,7 +496,7 @@ buttonpress(XEvent *e)
155 for (i = 0; i < LENGTH(buttons); i++)
156 if (click == buttons[i].click && buttons[i].func && but…
157 && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
158 - buttons[i].func(click == ClkTagBar && buttons[i…
159 + buttons[i].func((click == ClkTagBar || click ==…
160 }
161
162 void
163 @@ -627,6 +671,19 @@ configurerequest(XEvent *e)
164 XSync(dpy, False);
165 }
166
167 +void
168 +copyvalidchars(char *text, char *rawtext)
169 +{
170 + int i = -1, j = 0;
171 +
172 + while(rawtext[++i]) {
173 + if ((unsigned char)rawtext[i] >= ' ') {
174 + text[j++] = rawtext[i];
175 + }
176 + }
177 + text[j] = '\0';
178 +}
179 +
180 Monitor *
181 createmon(void)
182 {
183 @@ -695,7 +752,7 @@ dirtomon(int dir)
184 void
185 drawbar(Monitor *m)
186 {
187 - int x, w, sw = 0;
188 + int x, w, sw = 0, n = 0, scm;
189 int boxs = drw->fonts->h / 9;
190 int boxw = drw->fonts->h / 6 + 2;
191 unsigned int i, occ = 0, urg = 0;
192 @@ -709,6 +766,8 @@ drawbar(Monitor *m)
193 }
194
195 for (c = m->clients; c; c = c->next) {
196 + if (ISVISIBLE(c))
197 + n++;
198 occ |= c->tags;
199 if (c->isurgent)
200 urg |= c->tags;
201 @@ -729,16 +788,37 @@ drawbar(Monitor *m)
202 x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
203
204 if ((w = m->ww - sw - x) > bh) {
205 - if (m->sel) {
206 - drw_setscheme(drw, scheme[m == selmon ? SchemeS…
207 - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->n…
208 - if (m->sel->isfloating)
209 - drw_rect(drw, x + boxs, boxs, boxw, box…
210 + if (n > 0) {
211 + int remainder = w % n;
212 + int tabw = (1.0 / (double)n) * w + 1;
213 + for (c = m->clients; c; c = c->next) {
214 + if (!ISVISIBLE(c))
215 + continue;
216 + if (m->sel == c)
217 + scm = SchemeSel;
218 + else if (HIDDEN(c))
219 + scm = SchemeHid;
220 + else
221 + scm = SchemeNorm;
222 + drw_setscheme(drw, scheme[scm]);
223 +
224 + if (remainder >= 0) {
225 + if (remainder == 0) {
226 + tabw--;
227 + }
228 + remainder--;
229 + }
230 + drw_text(drw, x, 0, tabw, bh, lrpad / 2…
231 + x += tabw;
232 + }
233 } else {
234 drw_setscheme(drw, scheme[SchemeNorm]);
235 drw_rect(drw, x, 0, w, bh, 1, 1);
236 }
237 }
238 +
239 + m->bt = n;
240 + m->btw = w;
241 drw_map(drw, m->barwin, 0, 0, m->ww, bh);
242 }
243
244 @@ -783,8 +863,8 @@ expose(XEvent *e)
245 void
246 focus(Client *c)
247 {
248 - if (!c || !ISVISIBLE(c))
249 - for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snex…
250 + if (!c || !ISVISIBLE(c) || HIDDEN(c))
251 + for (c = selmon->stack; c && (!ISVISIBLE(c) || HIDDEN(c…
252 if (selmon->sel && selmon->sel != c)
253 unfocus(selmon->sel, 0);
254 if (c) {
255 @@ -871,6 +951,18 @@ getatomprop(Client *c, Atom prop)
256 return atom;
257 }
258
259 +int
260 +getdwmblockspid()
261 +{
262 + char buf[16];
263 + FILE *fp = popen("pidof -s dwmblocks", "r");
264 + fgets(buf, sizeof(buf), fp);
265 + pid_t pid = strtoul(buf, NULL, 10);
266 + pclose(fp);
267 + dwmblockspid = pid;
268 + return pid != 0 ? 0 : -1;
269 +}
270 +
271 int
272 getrootptr(int *x, int *y)
273 {
274 @@ -963,6 +1055,31 @@ grabkeys(void)
275 }
276 }
277
278 +void
279 +hide(Client *c) {
280 + if (!c || HIDDEN(c))
281 + return;
282 +
283 + Window w = c->win;
284 + static XWindowAttributes ra, ca;
285 +
286 + // more or less taken directly from blackbox's hide() function
287 + XGrabServer(dpy);
288 + XGetWindowAttributes(dpy, root, &ra);
289 + XGetWindowAttributes(dpy, w, &ca);
290 + // prevent UnmapNotify events
291 + XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotif…
292 + XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
293 + XUnmapWindow(dpy, w);
294 + setclientstate(c, IconicState);
295 + XSelectInput(dpy, root, ra.your_event_mask);
296 + XSelectInput(dpy, w, ca.your_event_mask);
297 + XUngrabServer(dpy);
298 +
299 + focus(c->snext);
300 + arrange(c->mon);
301 +}
302 +
303 void
304 incnmaster(const Arg *arg)
305 {
306 @@ -1067,12 +1184,14 @@ manage(Window w, XWindowAttributes *wa)
307 XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 3…
308 (unsigned char *) &(c->win), 1);
309 XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h)…
310 - setclientstate(c, NormalState);
311 + if (!HIDDEN(c))
312 + setclientstate(c, NormalState);
313 if (c->mon == selmon)
314 unfocus(selmon->sel, 0);
315 c->mon->sel = c;
316 arrange(c->mon);
317 - XMapWindow(dpy, c->win);
318 + if (!HIDDEN(c))
319 + XMapWindow(dpy, c->win);
320 focus(NULL);
321 }
322
323 @@ -1195,7 +1314,7 @@ movemouse(const Arg *arg)
324 Client *
325 nexttiled(Client *c)
326 {
327 - for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
328 + for (; c && (c->isfloating || !ISVISIBLE(c) || HIDDEN(c)); c = …
329 return c;
330 }
331
332 @@ -1248,6 +1367,16 @@ propertynotify(XEvent *e)
333 void
334 quit(const Arg *arg)
335 {
336 + // fix: reloading dwm keeps all the hidden clients hidden
337 + Monitor *m;
338 + Client *c;
339 + for (m = mons; m; m = m->next) {
340 + if (m) {
341 + for (c = m->stack; c; c = c->next)
342 + if (c && HIDDEN(c)) show(c);
343 + }
344 + }
345 +
346 running = 0;
347 }
348
349 @@ -1610,6 +1739,17 @@ seturgent(Client *c, int urg)
350 XFree(wmh);
351 }
352
353 +void
354 +show(Client *c)
355 +{
356 + if (!c || !HIDDEN(c))
357 + return;
358 +
359 + XMapWindow(dpy, c->win);
360 + setclientstate(c, NormalState);
361 + arrange(c->mon);
362 +}
363 +
364 void
365 showhide(Client *c)
366 {
367 @@ -1636,6 +1776,23 @@ sigchld(int unused)
368 while (0 < waitpid(-1, NULL, WNOHANG));
369 }
370
371 +void
372 +sigdwmblocks(const Arg *arg)
373 +{
374 + union sigval sv;
375 + sv.sival_int = (dwmblockssig << 8) | arg->i;
376 + if (!dwmblockspid)
377 + if (getdwmblockspid() == -1)
378 + return;
379 +
380 + if (sigqueue(dwmblockspid, SIGUSR1, sv) == -1) {
381 + if (errno == ESRCH) {
382 + if (!getdwmblockspid())
383 + sigqueue(dwmblockspid, SIGUSR1, sv);
384 + }
385 + }
386 +}
387 +
388 void
389 spawn(const Arg *arg)
390 {
391 @@ -1746,6 +1903,20 @@ toggleview(const Arg *arg)
392 }
393 }
394
395 +void
396 +togglewin(const Arg *arg)
397 +{
398 + Client *c = (Client*)arg->v;
399 + if (c == selmon->sel)
400 + hide(c);
401 + else {
402 + if (HIDDEN(c))
403 + show(c);
404 + focus(c);
405 + restack(selmon);
406 + }
407 +}
408 +
409 void
410 unfocus(Client *c, int setfocus)
411 {
412 @@ -1987,8 +2158,10 @@ updatesizehints(Client *c)
413 void
414 updatestatus(void)
415 {
416 - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
417 + if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext)))
418 strcpy(stext, "dwm-"VERSION);
419 + else
420 + copyvalidchars(stext, rawstext);
421 drawbar(selmon);
422 }
423
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.