equal
deleted
inserted
replaced
1 /* See LICENSE file for copyright and license details. */ |
1 /* See LICENSE file for copyright and license details. */ |
2 #include "dwm.h" |
2 #include "dwm.h" |
3 #include <regex.h> |
3 #include <regex.h> |
4 #include <stdio.h> |
4 #include <stdio.h> |
5 #include <stdlib.h> |
5 #include <stdlib.h> |
6 #include <string.h> |
|
7 #include <X11/Xatom.h> |
|
8 #include <X11/Xutil.h> |
6 #include <X11/Xutil.h> |
9 |
7 |
10 /* static */ |
8 /* static */ |
11 |
9 |
12 typedef struct { |
10 typedef struct { |
26 } Regs; |
24 } Regs; |
27 |
25 |
28 TAGS |
26 TAGS |
29 RULES |
27 RULES |
30 |
28 |
31 static char buf[512]; |
|
32 static unsigned int nrules = 0; |
29 static unsigned int nrules = 0; |
33 static unsigned int nlayouts = 0; |
30 static unsigned int nlayouts = 0; |
34 static unsigned int ltidx = 0; /* default */ |
31 static unsigned int ltidx = 0; /* default */ |
35 static Regs *regs = NULL; |
32 static Regs *regs = NULL; |
36 |
33 |
51 for(c = clients; c; c = c->next) |
48 for(c = clients; c; c = c->next) |
52 if(isvisible(c)) |
49 if(isvisible(c)) |
53 resize(c, c->x, c->y, c->w, c->h, True); |
50 resize(c, c->x, c->y, c->w, c->h, True); |
54 } |
51 } |
55 |
52 |
56 static void |
|
57 setdwmprops(void) { |
|
58 unsigned int i; |
|
59 |
|
60 for(i = 0; i < ntags && i < sizeof buf - 1; i++) |
|
61 buf[i] = seltags[i] ? '1' : '0'; |
|
62 if(i < sizeof buf - 1) |
|
63 buf[i++] = (char)ltidx + '0'; |
|
64 buf[i] = '\0'; |
|
65 XChangeProperty(dpy, root, dwmprops, XA_STRING, 8, |
|
66 PropModeReplace, (unsigned char *)buf, i); |
|
67 } |
|
68 |
|
69 LAYOUTS |
53 LAYOUTS |
70 |
54 |
71 /* extern */ |
55 /* extern */ |
72 |
56 |
73 unsigned int blw = 0; |
57 unsigned int blw = 0; |
74 |
58 |
75 void |
59 void |
76 applyrules(Client *c) { |
60 applyrules(Client *c) { |
|
61 static char buf[512]; |
77 unsigned int i, j; |
62 unsigned int i, j; |
78 regmatch_t tmp; |
63 regmatch_t tmp; |
79 Bool matched = False; |
64 Bool matched = False; |
80 XClassHint ch = { 0 }; |
65 XClassHint ch = { 0 }; |
81 |
66 |
213 if(c->tags[i] && seltags[i]) |
198 if(c->tags[i] && seltags[i]) |
214 return True; |
199 return True; |
215 return False; |
200 return False; |
216 } |
201 } |
217 |
202 |
218 void |
|
219 getdwmprops(void) { |
|
220 unsigned int i; |
|
221 |
|
222 if(gettextprop(root, dwmprops, buf, sizeof buf)) { |
|
223 for(i = 0; i < ntags && i < sizeof buf - 1 && buf[i] != '\0'; i++) |
|
224 seltags[i] = buf[i] == '1'; |
|
225 if(i < sizeof buf - 1 && buf[i] != '\0') { |
|
226 if((unsigned int)(buf[i] - '0') < nlayouts) |
|
227 ltidx = buf[i] - '0'; |
|
228 } |
|
229 } |
|
230 } |
|
231 |
|
232 Client * |
203 Client * |
233 nexttiled(Client *c) { |
204 nexttiled(Client *c) { |
234 for(; c && (c->isfloating || !isvisible(c)); c = c->next); |
205 for(; c && (c->isfloating || !isvisible(c)); c = c->next); |
235 return c; |
206 return c; |
236 } |
207 } |
264 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
235 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
265 } |
236 } |
266 |
237 |
267 void |
238 void |
268 setlayout(const char *arg) { |
239 setlayout(const char *arg) { |
269 int i; |
240 unsigned int i; |
270 |
241 |
271 if(!arg) { |
242 if(!arg) { |
272 if(++ltidx == nlayouts) |
243 if(++ltidx == nlayouts) |
273 ltidx = 0;; |
244 ltidx = 0;; |
274 } |
245 } |
275 else { |
246 else { |
276 i = atoi(arg); |
247 for(i = 0; i < nlayouts; i++) |
277 if(i < 0 || i >= nlayouts) |
248 if(arg == layouts[i].symbol) |
|
249 break; |
|
250 if(i == nlayouts) |
278 return; |
251 return; |
279 ltidx = i; |
252 ltidx = i; |
280 } |
253 } |
281 if(sel) |
254 if(sel) |
282 arrange(); |
255 arrange(); |
283 else |
256 else |
284 drawstatus(); |
257 drawstatus(); |
285 setdwmprops(); |
|
286 } |
258 } |
287 |
259 |
288 void |
260 void |
289 tag(const char *arg) { |
261 tag(const char *arg) { |
290 unsigned int i; |
262 unsigned int i; |
294 for(i = 0; i < ntags; i++) |
266 for(i = 0; i < ntags; i++) |
295 sel->tags[i] = arg == NULL; |
267 sel->tags[i] = arg == NULL; |
296 i = idxoftag(arg); |
268 i = idxoftag(arg); |
297 if(i >= 0 && i < ntags) |
269 if(i >= 0 && i < ntags) |
298 sel->tags[i] = True; |
270 sel->tags[i] = True; |
299 setprops(sel); |
|
300 arrange(); |
271 arrange(); |
301 } |
272 } |
302 |
273 |
303 void |
274 void |
304 togglebar(const char *arg) { |
275 togglebar(const char *arg) { |
313 void |
284 void |
314 togglefloating(const char *arg) { |
285 togglefloating(const char *arg) { |
315 if(!sel || isfloating()) |
286 if(!sel || isfloating()) |
316 return; |
287 return; |
317 sel->isfloating = !sel->isfloating; |
288 sel->isfloating = !sel->isfloating; |
318 if(sel->isfloating) { |
289 if(sel->isfloating) |
319 resize(sel, sel->x, sel->y, sel->w, sel->h, True); |
290 resize(sel, sel->x, sel->y, sel->w, sel->h, True); |
320 setprops(sel); |
|
321 } |
|
322 arrange(); |
291 arrange(); |
323 } |
292 } |
324 |
293 |
325 void |
294 void |
326 togglemax(const char *arg) { |
295 togglemax(const char *arg) { |
350 i = idxoftag(arg); |
319 i = idxoftag(arg); |
351 sel->tags[i] = !sel->tags[i]; |
320 sel->tags[i] = !sel->tags[i]; |
352 for(j = 0; j < ntags && !sel->tags[j]; j++); |
321 for(j = 0; j < ntags && !sel->tags[j]; j++); |
353 if(j == ntags) |
322 if(j == ntags) |
354 sel->tags[i] = True; |
323 sel->tags[i] = True; |
355 setprops(sel); |
|
356 arrange(); |
324 arrange(); |
357 } |
325 } |
358 |
326 |
359 void |
327 void |
360 toggleview(const char *arg) { |
328 toggleview(const char *arg) { |
363 i = idxoftag(arg); |
331 i = idxoftag(arg); |
364 seltags[i] = !seltags[i]; |
332 seltags[i] = !seltags[i]; |
365 for(j = 0; j < ntags && !seltags[j]; j++); |
333 for(j = 0; j < ntags && !seltags[j]; j++); |
366 if(j == ntags) |
334 if(j == ntags) |
367 seltags[i] = True; /* cannot toggle last view */ |
335 seltags[i] = True; /* cannot toggle last view */ |
368 setdwmprops(); |
|
369 arrange(); |
336 arrange(); |
370 } |
337 } |
371 |
338 |
372 void |
339 void |
373 updatebarpos(void) { |
340 updatebarpos(void) { |
402 for(i = 0; i < ntags; i++) |
369 for(i = 0; i < ntags; i++) |
403 seltags[i] = arg == NULL; |
370 seltags[i] = arg == NULL; |
404 i = idxoftag(arg); |
371 i = idxoftag(arg); |
405 if(i >= 0 && i < ntags) |
372 if(i >= 0 && i < ntags) |
406 seltags[i] = True; |
373 seltags[i] = True; |
407 setdwmprops(); |
374 arrange(); |
408 arrange(); |
375 } |
409 } |
|