summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@gmail.com>2007-10-28 12:41:14 +0100
committerAnselm R. Garbe <garbeam@gmail.com>2007-10-28 12:41:14 +0100
commitc36f7c3c5e5db297689765142c64977f6317a21c (patch)
treee11ceb2515ae858a42f3c4606fda7872ec05a26c /dwm.c
parentsome sanity changes (diff)
downloaddwm-c36f7c3c5e5db297689765142c64977f6317a21c.tar.gz
dwm-c36f7c3c5e5db297689765142c64977f6317a21c.zip
replaced ISTILE with domwfact/dozoom bools, removed nrules, nlayouts and ltidx, added NRULES, NLAYOUTS and Layout *layout as alternatives, removed isarrange(), checking against layout->arrange instead.
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c63
1 files changed, 28 insertions, 35 deletions
diff --git a/dwm.c b/dwm.c
index a4deccf..5bd7221 100644
--- a/dwm.c
+++ b/dwm.c
@@ -145,7 +145,6 @@ Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
145void grabbuttons(Client *c, Bool focused); 145void grabbuttons(Client *c, Bool focused);
146unsigned int idxoftag(const char *tag); 146unsigned int idxoftag(const char *tag);
147void initfont(const char *fontstr); 147void initfont(const char *fontstr);
148Bool isarrange(void (*func)());
149Bool isoccupied(unsigned int t); 148Bool isoccupied(unsigned int t);
150Bool isprotodel(Client *c); 149Bool isprotodel(Client *c);
151Bool isvisible(Client *c); 150Bool isvisible(Client *c);
@@ -198,9 +197,6 @@ int screen, sx, sy, sw, sh, wax, way, waw, wah;
198int (*xerrorxlib)(Display *, XErrorEvent *); 197int (*xerrorxlib)(Display *, XErrorEvent *);
199unsigned int bh, bpos; 198unsigned int bh, bpos;
200unsigned int blw = 0; 199unsigned int blw = 0;
201unsigned int ltidx = 0; /* default */
202unsigned int nlayouts = 0;
203unsigned int nrules = 0;
204unsigned int numlockmask = 0; 200unsigned int numlockmask = 0;
205void (*handler[LASTEvent]) (XEvent *) = { 201void (*handler[LASTEvent]) (XEvent *) = {
206 [ButtonPress] = buttonpress, 202 [ButtonPress] = buttonpress,
@@ -217,6 +213,8 @@ void (*handler[LASTEvent]) (XEvent *) = {
217 [UnmapNotify] = unmapnotify 213 [UnmapNotify] = unmapnotify
218}; 214};
219Atom wmatom[WMLast], netatom[NetLast]; 215Atom wmatom[WMLast], netatom[NetLast];
216Bool domwfact = True;
217Bool dozoom = True;
220Bool otherwm, readin; 218Bool otherwm, readin;
221Bool running = True; 219Bool running = True;
222Bool selscreen = True; 220Bool selscreen = True;
@@ -226,6 +224,7 @@ Client *stack = NULL;
226Cursor cursor[CurLast]; 224Cursor cursor[CurLast];
227Display *dpy; 225Display *dpy;
228DC dc = {0}; 226DC dc = {0};
227Layout *layout = NULL;
229Window barwin, root; 228Window barwin, root;
230Regs *regs = NULL; 229Regs *regs = NULL;
231 230
@@ -246,7 +245,7 @@ applyrules(Client *c) {
246 snprintf(buf, sizeof buf, "%s:%s:%s", 245 snprintf(buf, sizeof buf, "%s:%s:%s",
247 ch.res_class ? ch.res_class : "", 246 ch.res_class ? ch.res_class : "",
248 ch.res_name ? ch.res_name : "", c->name); 247 ch.res_name ? ch.res_name : "", c->name);
249 for(i = 0; i < nrules; i++) 248 for(i = 0; i < NRULES; i++)
250 if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) { 249 if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
251 c->isfloating = rules[i].isfloating; 250 c->isfloating = rules[i].isfloating;
252 for(j = 0; regs[i].tagregex && j < NTAGS; j++) { 251 for(j = 0; regs[i].tagregex && j < NTAGS; j++) {
@@ -273,7 +272,7 @@ arrange(void) {
273 unban(c); 272 unban(c);
274 else 273 else
275 ban(c); 274 ban(c);
276 layouts[ltidx].arrange(); 275 layout->arrange();
277 focus(NULL); 276 focus(NULL);
278 restack(); 277 restack();
279} 278}
@@ -334,20 +333,20 @@ buttonpress(XEvent *e) {
334 if(CLEANMASK(ev->state) != MODKEY) 333 if(CLEANMASK(ev->state) != MODKEY)
335 return; 334 return;
336 if(ev->button == Button1) { 335 if(ev->button == Button1) {
337 if(isarrange(floating) || c->isfloating) 336 if((floating == layout->arrange) || c->isfloating)
338 restack(); 337 restack();
339 else 338 else
340 togglefloating(NULL); 339 togglefloating(NULL);
341 movemouse(c); 340 movemouse(c);
342 } 341 }
343 else if(ev->button == Button2) { 342 else if(ev->button == Button2) {
344 if((ISTILE) && !c->isfixed && c->isfloating) 343 if((floating != layout->arrange) && !c->isfixed && c->isfloating)
345 togglefloating(NULL); 344 togglefloating(NULL);
346 else 345 else
347 zoom(NULL); 346 zoom(NULL);
348 } 347 }
349 else if(ev->button == Button3 && !c->isfixed) { 348 else if(ev->button == Button3 && !c->isfixed) {
350 if(isarrange(floating) || c->isfloating) 349 if((floating == layout->arrange) || c->isfloating)
351 restack(); 350 restack();
352 else 351 else
353 togglefloating(NULL); 352 togglefloating(NULL);
@@ -401,9 +400,8 @@ compileregs(void) {
401 400
402 if(regs) 401 if(regs)
403 return; 402 return;
404 nrules = sizeof rules / sizeof rules[0]; 403 regs = emallocz(NRULES * sizeof(Regs));
405 regs = emallocz(nrules * sizeof(Regs)); 404 for(i = 0; i < NRULES; i++) {
406 for(i = 0; i < nrules; i++) {
407 if(rules[i].prop) { 405 if(rules[i].prop) {
408 reg = emallocz(sizeof(regex_t)); 406 reg = emallocz(sizeof(regex_t));
409 if(regcomp(reg, rules[i].prop, REG_EXTENDED)) 407 if(regcomp(reg, rules[i].prop, REG_EXTENDED))
@@ -464,7 +462,7 @@ configurerequest(XEvent *e) {
464 c->ismax = False; 462 c->ismax = False;
465 if(ev->value_mask & CWBorderWidth) 463 if(ev->value_mask & CWBorderWidth)
466 c->border = ev->border_width; 464 c->border = ev->border_width;
467 if(c->isfixed || c->isfloating || isarrange(floating)) { 465 if(c->isfixed || c->isfloating || (floating == layout->arrange)) {
468 if(ev->value_mask & CWX) 466 if(ev->value_mask & CWX)
469 c->x = ev->x; 467 c->x = ev->x;
470 if(ev->value_mask & CWY) 468 if(ev->value_mask & CWY)
@@ -545,7 +543,7 @@ drawbar(void) {
545 dc.x += dc.w; 543 dc.x += dc.w;
546 } 544 }
547 dc.w = blw; 545 dc.w = blw;
548 drawtext(layouts[ltidx].symbol, dc.norm); 546 drawtext(layout->symbol, dc.norm);
549 x = dc.x + dc.w; 547 x = dc.x + dc.w;
550 dc.w = textw(stext); 548 dc.w = textw(stext);
551 dc.x = sw - dc.w; 549 dc.x = sw - dc.w;
@@ -676,6 +674,7 @@ void
676floating(void) { /* default floating layout */ 674floating(void) { /* default floating layout */
677 Client *c; 675 Client *c;
678 676
677 domwfact = dozoom = False;
679 for(c = clients; c; c = c->next) 678 for(c = clients; c; c = c->next)
680 if(isvisible(c)) 679 if(isvisible(c))
681 resize(c, c->x, c->y, c->w, c->h, True); 680 resize(c, c->x, c->y, c->w, c->h, True);
@@ -889,12 +888,6 @@ initfont(const char *fontstr) {
889} 888}
890 889
891Bool 890Bool
892isarrange(void (*func)())
893{
894 return func == layouts[ltidx].arrange;
895}
896
897Bool
898isoccupied(unsigned int t) { 891isoccupied(unsigned int t) {
899 Client *c; 892 Client *c;
900 893
@@ -932,7 +925,6 @@ isvisible(Client *c) {
932void 925void
933keypress(XEvent *e) { 926keypress(XEvent *e) {
934 KEYS 927 KEYS
935 unsigned int len = sizeof keys / sizeof keys[0];
936 unsigned int i; 928 unsigned int i;
937 KeyCode code; 929 KeyCode code;
938 KeySym keysym; 930 KeySym keysym;
@@ -940,7 +932,7 @@ keypress(XEvent *e) {
940 932
941 if(!e) { /* grabkeys */ 933 if(!e) { /* grabkeys */
942 XUngrabKey(dpy, AnyKey, AnyModifier, root); 934 XUngrabKey(dpy, AnyKey, AnyModifier, root);
943 for(i = 0; i < len; i++) { 935 for(i = 0; i < NKEYS; i++) {
944 code = XKeysymToKeycode(dpy, keys[i].keysym); 936 code = XKeysymToKeycode(dpy, keys[i].keysym);
945 XGrabKey(dpy, code, keys[i].mod, root, True, 937 XGrabKey(dpy, code, keys[i].mod, root, True,
946 GrabModeAsync, GrabModeAsync); 938 GrabModeAsync, GrabModeAsync);
@@ -955,7 +947,7 @@ keypress(XEvent *e) {
955 } 947 }
956 ev = &e->xkey; 948 ev = &e->xkey;
957 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); 949 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
958 for(i = 0; i < len; i++) 950 for(i = 0; i < NKEYS; i++)
959 if(keysym == keys[i].keysym 951 if(keysym == keys[i].keysym
960 && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)) 952 && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state))
961 { 953 {
@@ -1266,9 +1258,9 @@ restack(void) {
1266 drawbar(); 1258 drawbar();
1267 if(!sel) 1259 if(!sel)
1268 return; 1260 return;
1269 if(sel->isfloating || isarrange(floating)) 1261 if(sel->isfloating || (floating == layout->arrange))
1270 XRaiseWindow(dpy, sel->win); 1262 XRaiseWindow(dpy, sel->win);
1271 if(!isarrange(floating)) { 1263 if(floating != layout->arrange) {
1272 wc.stack_mode = Below; 1264 wc.stack_mode = Below;
1273 wc.sibling = barwin; 1265 wc.sibling = barwin;
1274 if(!sel->isfloating) { 1266 if(!sel->isfloating) {
@@ -1374,16 +1366,16 @@ setlayout(const char *arg) {
1374 unsigned int i; 1366 unsigned int i;
1375 1367
1376 if(!arg) { 1368 if(!arg) {
1377 if(++ltidx == nlayouts) 1369 if(++layout == &layouts[NLAYOUTS])
1378 ltidx = 0;; 1370 layout = &layouts[0];
1379 } 1371 }
1380 else { 1372 else {
1381 for(i = 0; i < nlayouts; i++) 1373 for(i = 0; i < NLAYOUTS; i++)
1382 if(!strcmp(arg, layouts[i].symbol)) 1374 if(!strcmp(arg, layouts[i].symbol))
1383 break; 1375 break;
1384 if(i == nlayouts) 1376 if(i == NLAYOUTS)
1385 return; 1377 return;
1386 ltidx = i; 1378 layout = &layouts[i];
1387 } 1379 }
1388 if(sel) 1380 if(sel)
1389 arrange(); 1381 arrange();
@@ -1395,7 +1387,7 @@ void
1395setmwfact(const char *arg) { 1387setmwfact(const char *arg) {
1396 double delta; 1388 double delta;
1397 1389
1398 if(!(ISTILE)) 1390 if(!domwfact)
1399 return; 1391 return;
1400 /* arg handling, manipulate mwfact */ 1392 /* arg handling, manipulate mwfact */
1401 if(NULL == arg) 1393 if(NULL == arg)
@@ -1476,8 +1468,8 @@ setup(void) {
1476 1468
1477 /* init layouts */ 1469 /* init layouts */
1478 mwfact = MWFACT; 1470 mwfact = MWFACT;
1479 nlayouts = sizeof layouts / sizeof layouts[0]; 1471 layout = &layouts[0];
1480 for(blw = i = 0; i < nlayouts; i++) { 1472 for(blw = i = 0; i < NLAYOUTS; i++) {
1481 j = textw(layouts[i].symbol); 1473 j = textw(layouts[i].symbol);
1482 if(j > blw) 1474 if(j > blw)
1483 blw = j; 1475 blw = j;
@@ -1562,6 +1554,7 @@ tile(void) {
1562 unsigned int i, n, nx, ny, nw, nh, mw, th; 1554 unsigned int i, n, nx, ny, nw, nh, mw, th;
1563 Client *c, *mc; 1555 Client *c, *mc;
1564 1556
1557 domwfact = dozoom = True;
1565 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) 1558 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
1566 n++; 1559 n++;
1567 1560
@@ -1627,7 +1620,7 @@ togglemax(const char *arg) {
1627 if(!sel || sel->isfixed) 1620 if(!sel || sel->isfixed)
1628 return; 1621 return;
1629 if((sel->ismax = !sel->ismax)) { 1622 if((sel->ismax = !sel->ismax)) {
1630 if(isarrange(floating) || sel->isfloating) 1623 if((floating == layout->arrange) || sel->isfloating)
1631 sel->wasfloating = True; 1624 sel->wasfloating = True;
1632 else { 1625 else {
1633 togglefloating(NULL); 1626 togglefloating(NULL);
@@ -1855,7 +1848,7 @@ void
1855zoom(const char *arg) { 1848zoom(const char *arg) {
1856 Client *c; 1849 Client *c;
1857 1850
1858 if(!sel || !(ISTILE) || sel->isfloating) 1851 if(!sel || !dozoom || sel->isfloating)
1859 return; 1852 return;
1860 if((c = sel) == nexttiled(clients)) 1853 if((c = sel) == nexttiled(clients))
1861 if(!(c = nexttiled(c->next))) 1854 if(!(c = nexttiled(c->next)))