replaced Nmacros with LENGTH(x) macro
34e7872c
2 file(s) · +26 −27
| 11 | 11 | #define SELBGCOLOR "#0066ff" |
|
| 12 | 12 | #define SELFGCOLOR "#ffffff" |
|
| 13 | 13 | ||
| 14 | + | /* convenience */ |
|
| 15 | + | #define LENGTH(x) (sizeof x / sizeof x[0]) |
|
| 16 | + | ||
| 14 | 17 | /* tagging */ |
|
| 15 | 18 | const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "www" }; |
|
| 16 | - | #define NTAGS (sizeof tags / sizeof tags[0]) |
|
| 17 | - | Bool seltags[NTAGS] = {[0] = True}; |
|
| 18 | - | Bool prevtags[NTAGS] = {[0] = True}; |
|
| 19 | + | Bool seltags[LENGTH(tags)] = {[0] = True}; |
|
| 20 | + | Bool prevtags[LENGTH(tags)] = {[0] = True}; |
|
| 19 | 21 | Rule rules[] = { |
|
| 20 | 22 | /* class:instance:title regex tags regex isfloating */ |
|
| 21 | 23 | { "Firefox", "www", False }, |
|
| 23 | 25 | { "MPlayer", NULL, True }, |
|
| 24 | 26 | { "Acroread", NULL, True }, |
|
| 25 | 27 | }; |
|
| 26 | - | #define NRULES (sizeof rules / sizeof rules[0]) |
|
| 27 | 28 | ||
| 28 | 29 | /* layout(s) */ |
|
| 29 | 30 | #define MWFACT 0.6 /* master width factor [0.1 .. 0.9] */ |
|
| 33 | 34 | { "[]=", tile }, /* first entry is default */ |
|
| 34 | 35 | { "><>", floating }, |
|
| 35 | 36 | }; |
|
| 36 | - | #define NLAYOUTS (sizeof layouts / sizeof layouts[0]) |
|
| 37 | 37 | ||
| 38 | 38 | /* key definitions */ |
|
| 39 | 39 | #define MODKEY Mod1Mask |
|
| 95 | 95 | { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, tags[8] }, \ |
|
| 96 | 96 | { MODKEY|ShiftMask, XK_q, quit, NULL }, \ |
|
| 97 | 97 | }; |
|
| 98 | - | #define NKEYS (sizeof keys / sizeof keys[0]) |
|
| 245 | 245 | snprintf(buf, sizeof buf, "%s:%s:%s", |
|
| 246 | 246 | ch.res_class ? ch.res_class : "", |
|
| 247 | 247 | ch.res_name ? ch.res_name : "", c->name); |
|
| 248 | - | for(i = 0; i < NRULES; i++) |
|
| 248 | + | for(i = 0; i < LENGTH(rules); i++) |
|
| 249 | 249 | if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) { |
|
| 250 | 250 | c->isfloating = rules[i].isfloating; |
|
| 251 | - | for(j = 0; regs[i].tagregex && j < NTAGS; j++) { |
|
| 251 | + | for(j = 0; regs[i].tagregex && j < LENGTH(tags); j++) { |
|
| 252 | 252 | if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) { |
|
| 253 | 253 | matched = True; |
|
| 254 | 254 | c->tags[j] = True; |
|
| 307 | 307 | ||
| 308 | 308 | if(barwin == ev->window) { |
|
| 309 | 309 | x = 0; |
|
| 310 | - | for(i = 0; i < NTAGS; i++) { |
|
| 310 | + | for(i = 0; i < LENGTH(tags); i++) { |
|
| 311 | 311 | x += textw(tags[i]); |
|
| 312 | 312 | if(ev->x < x) { |
|
| 313 | 313 | if(ev->button == Button1) { |
|
| 400 | 400 | ||
| 401 | 401 | if(regs) |
|
| 402 | 402 | return; |
|
| 403 | - | regs = emallocz(NRULES * sizeof(Regs)); |
|
| 404 | - | for(i = 0; i < NRULES; i++) { |
|
| 403 | + | regs = emallocz(LENGTH(rules) * sizeof(Regs)); |
|
| 404 | + | for(i = 0; i < LENGTH(rules); i++) { |
|
| 405 | 405 | if(rules[i].prop) { |
|
| 406 | 406 | reg = emallocz(sizeof(regex_t)); |
|
| 407 | 407 | if(regcomp(reg, rules[i].prop, REG_EXTENDED)) |
|
| 530 | 530 | int i, x; |
|
| 531 | 531 | ||
| 532 | 532 | dc.x = dc.y = 0; |
|
| 533 | - | for(i = 0; i < NTAGS; i++) { |
|
| 533 | + | for(i = 0; i < LENGTH(tags); i++) { |
|
| 534 | 534 | dc.w = textw(tags[i]); |
|
| 535 | 535 | if(seltags[i]) { |
|
| 536 | 536 | drawtext(tags[i], dc.sel); |
|
| 841 | 841 | idxoftag(const char *tag) { |
|
| 842 | 842 | unsigned int i; |
|
| 843 | 843 | ||
| 844 | - | for(i = 0; (i < NTAGS) && (tags[i] != tag); i++); |
|
| 845 | - | return (i < NTAGS) ? i : 0; |
|
| 844 | + | for(i = 0; (i < LENGTH(tags)) && (tags[i] != tag); i++); |
|
| 845 | + | return (i < LENGTH(tags)) ? i : 0; |
|
| 846 | 846 | } |
|
| 847 | 847 | ||
| 848 | 848 | void |
|
| 916 | 916 | isvisible(Client *c) { |
|
| 917 | 917 | unsigned int i; |
|
| 918 | 918 | ||
| 919 | - | for(i = 0; i < NTAGS; i++) |
|
| 919 | + | for(i = 0; i < LENGTH(tags); i++) |
|
| 920 | 920 | if(c->tags[i] && seltags[i]) |
|
| 921 | 921 | return True; |
|
| 922 | 922 | return False; |
|
| 932 | 932 | ||
| 933 | 933 | if(!e) { /* grabkeys */ |
|
| 934 | 934 | XUngrabKey(dpy, AnyKey, AnyModifier, root); |
|
| 935 | - | for(i = 0; i < NKEYS; i++) { |
|
| 935 | + | for(i = 0; i < LENGTH(keys); i++) { |
|
| 936 | 936 | code = XKeysymToKeycode(dpy, keys[i].keysym); |
|
| 937 | 937 | XGrabKey(dpy, code, keys[i].mod, root, True, |
|
| 938 | 938 | GrabModeAsync, GrabModeAsync); |
|
| 947 | 947 | } |
|
| 948 | 948 | ev = &e->xkey; |
|
| 949 | 949 | keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); |
|
| 950 | - | for(i = 0; i < NKEYS; i++) |
|
| 950 | + | for(i = 0; i < LENGTH(keys); i++) |
|
| 951 | 951 | if(keysym == keys[i].keysym |
|
| 952 | 952 | && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)) |
|
| 953 | 953 | { |
|
| 1366 | 1366 | unsigned int i; |
|
| 1367 | 1367 | ||
| 1368 | 1368 | if(!arg) { |
|
| 1369 | - | if(++layout == &layouts[NLAYOUTS]) |
|
| 1369 | + | if(++layout == &layouts[LENGTH(layouts)]) |
|
| 1370 | 1370 | layout = &layouts[0]; |
|
| 1371 | 1371 | } |
|
| 1372 | 1372 | else { |
|
| 1373 | - | for(i = 0; i < NLAYOUTS; i++) |
|
| 1373 | + | for(i = 0; i < LENGTH(layouts); i++) |
|
| 1374 | 1374 | if(!strcmp(arg, layouts[i].symbol)) |
|
| 1375 | 1375 | break; |
|
| 1376 | - | if(i == NLAYOUTS) |
|
| 1376 | + | if(i == LENGTH(layouts)) |
|
| 1377 | 1377 | return; |
|
| 1378 | 1378 | layout = &layouts[i]; |
|
| 1379 | 1379 | } |
|
| 1469 | 1469 | /* init layouts */ |
|
| 1470 | 1470 | mwfact = MWFACT; |
|
| 1471 | 1471 | layout = &layouts[0]; |
|
| 1472 | - | for(blw = i = 0; i < NLAYOUTS; i++) { |
|
| 1472 | + | for(blw = i = 0; i < LENGTH(layouts); i++) { |
|
| 1473 | 1473 | j = textw(layouts[i].symbol); |
|
| 1474 | 1474 | if(j > blw) |
|
| 1475 | 1475 | blw = j; |
|
| 1527 | 1527 | ||
| 1528 | 1528 | if(!sel) |
|
| 1529 | 1529 | return; |
|
| 1530 | - | for(i = 0; i < NTAGS; i++) |
|
| 1530 | + | for(i = 0; i < LENGTH(tags); i++) |
|
| 1531 | 1531 | sel->tags[i] = (NULL == arg); |
|
| 1532 | 1532 | sel->tags[idxoftag(arg)] = True; |
|
| 1533 | 1533 | arrange(); |
|
| 1649 | 1649 | return; |
|
| 1650 | 1650 | i = idxoftag(arg); |
|
| 1651 | 1651 | sel->tags[i] = !sel->tags[i]; |
|
| 1652 | - | for(j = 0; j < NTAGS && !sel->tags[j]; j++); |
|
| 1653 | - | if(j == NTAGS) |
|
| 1652 | + | for(j = 0; j < LENGTH(tags) && !sel->tags[j]; j++); |
|
| 1653 | + | if(j == LENGTH(tags)) |
|
| 1654 | 1654 | sel->tags[i] = True; /* at least one tag must be enabled */ |
|
| 1655 | 1655 | arrange(); |
|
| 1656 | 1656 | } |
|
| 1661 | 1661 | ||
| 1662 | 1662 | i = idxoftag(arg); |
|
| 1663 | 1663 | seltags[i] = !seltags[i]; |
|
| 1664 | - | for(j = 0; j < NTAGS && !seltags[j]; j++); |
|
| 1665 | - | if(j == NTAGS) |
|
| 1664 | + | for(j = 0; j < LENGTH(tags) && !seltags[j]; j++); |
|
| 1665 | + | if(j == LENGTH(tags)) |
|
| 1666 | 1666 | seltags[i] = True; /* at least one tag must be viewed */ |
|
| 1667 | 1667 | arrange(); |
|
| 1668 | 1668 | } |
|
| 1828 | 1828 | unsigned int i; |
|
| 1829 | 1829 | ||
| 1830 | 1830 | memcpy(prevtags, seltags, sizeof seltags); |
|
| 1831 | - | for(i = 0; i < NTAGS; i++) |
|
| 1831 | + | for(i = 0; i < LENGTH(tags); i++) |
|
| 1832 | 1832 | seltags[i] = (NULL == arg); |
|
| 1833 | 1833 | seltags[idxoftag(arg)] = True; |
|
| 1834 | 1834 | arrange(); |
|