Introduction
Introduction Statistics Contact Development Disclaimer Help
treplaced Nmacros with LENGTH(x) macro - dwm - [fork] customized build of dwm, …
git clone git://src.adamsgaard.dk/dwm
Log
Files
Refs
README
LICENSE
---
commit 34e7872c89613356293d554970d9d56adc4b0a4e
parent c36f7c3c5e5db297689765142c64977f6317a21c
Author: Anselm R. Garbe <[email protected]>
Date: Sun, 28 Oct 2007 12:52:16 +0100
replaced Nmacros with LENGTH(x) macro
Diffstat:
M config.def.h | 11 +++++------
M dwm.c | 42 ++++++++++++++++-------------…
2 files changed, 26 insertions(+), 27 deletions(-)
---
diff --git a/config.def.h b/config.def.h
t@@ -11,11 +11,13 @@
#define SELBGCOLOR "#0066ff"
#define SELFGCOLOR "#ffffff"
+/* convenience */
+#define LENGTH(x) (sizeof x / sizeof x[0])
+
/* tagging */
const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "www" };
-#define NTAGS (sizeof tags / sizeof tags[0])
-Bool seltags[NTAGS] = {[0] = True};
-Bool prevtags[NTAGS] = {[0] = True};
+Bool seltags[LENGTH(tags)] = {[0] = True};
+Bool prevtags[LENGTH(tags)] = {[0] = True};
Rule rules[] = {
/* class:instance:title regex tags regex isfloating */
{ "Firefox", "www", False },
t@@ -23,7 +25,6 @@ Rule rules[] = {
{ "MPlayer", NULL, True },
{ "Acroread", NULL, True },
};
-#define NRULES (sizeof rules / sizeof rules[0])
/* layout(s) */
#define MWFACT 0.6 /* master width factor [0.1 .…
t@@ -33,7 +34,6 @@ Layout layouts[] = {
{ "[]=", tile }, /* first entry is default */
{ "><>", floating },
};
-#define NLAYOUTS (sizeof layouts / sizeof layouts[0])
/* key definitions */
#define MODKEY Mod1Mask
t@@ -95,4 +95,3 @@ Key keys[] = { \
{ MODKEY|ControlMask|ShiftMask, XK_9, toggletag,…
{ MODKEY|ShiftMask, XK_q, quit, …
};
-#define NKEYS (sizeof keys / sizeof keys[0])
diff --git a/dwm.c b/dwm.c
t@@ -245,10 +245,10 @@ applyrules(Client *c) {
snprintf(buf, sizeof buf, "%s:%s:%s",
ch.res_class ? ch.res_class : "",
ch.res_name ? ch.res_name : "", c->name);
- for(i = 0; i < NRULES; i++)
+ for(i = 0; i < LENGTH(rules); i++)
if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &t…
c->isfloating = rules[i].isfloating;
- for(j = 0; regs[i].tagregex && j < NTAGS; j++) {
+ for(j = 0; regs[i].tagregex && j < LENGTH(tags); j++) {
if(!regexec(regs[i].tagregex, tags[j], 1, &tmp…
matched = True;
c->tags[j] = True;
t@@ -307,7 +307,7 @@ buttonpress(XEvent *e) {
if(barwin == ev->window) {
x = 0;
- for(i = 0; i < NTAGS; i++) {
+ for(i = 0; i < LENGTH(tags); i++) {
x += textw(tags[i]);
if(ev->x < x) {
if(ev->button == Button1) {
t@@ -400,8 +400,8 @@ compileregs(void) {
if(regs)
return;
- regs = emallocz(NRULES * sizeof(Regs));
- for(i = 0; i < NRULES; i++) {
+ regs = emallocz(LENGTH(rules) * sizeof(Regs));
+ for(i = 0; i < LENGTH(rules); i++) {
if(rules[i].prop) {
reg = emallocz(sizeof(regex_t));
if(regcomp(reg, rules[i].prop, REG_EXTENDED))
t@@ -530,7 +530,7 @@ drawbar(void) {
int i, x;
dc.x = dc.y = 0;
- for(i = 0; i < NTAGS; i++) {
+ for(i = 0; i < LENGTH(tags); i++) {
dc.w = textw(tags[i]);
if(seltags[i]) {
drawtext(tags[i], dc.sel);
t@@ -841,8 +841,8 @@ unsigned int
idxoftag(const char *tag) {
unsigned int i;
- for(i = 0; (i < NTAGS) && (tags[i] != tag); i++);
- return (i < NTAGS) ? i : 0;
+ for(i = 0; (i < LENGTH(tags)) && (tags[i] != tag); i++);
+ return (i < LENGTH(tags)) ? i : 0;
}
void
t@@ -916,7 +916,7 @@ Bool
isvisible(Client *c) {
unsigned int i;
- for(i = 0; i < NTAGS; i++)
+ for(i = 0; i < LENGTH(tags); i++)
if(c->tags[i] && seltags[i])
return True;
return False;
t@@ -932,7 +932,7 @@ keypress(XEvent *e) {
if(!e) { /* grabkeys */
XUngrabKey(dpy, AnyKey, AnyModifier, root);
- for(i = 0; i < NKEYS; i++) {
+ for(i = 0; i < LENGTH(keys); i++) {
code = XKeysymToKeycode(dpy, keys[i].keysym);
XGrabKey(dpy, code, keys[i].mod, root, True,
GrabModeAsync, GrabModeAsync);
t@@ -947,7 +947,7 @@ keypress(XEvent *e) {
}
ev = &e->xkey;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
- for(i = 0; i < NKEYS; i++)
+ for(i = 0; i < LENGTH(keys); i++)
if(keysym == keys[i].keysym
&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state))
{
t@@ -1366,14 +1366,14 @@ setlayout(const char *arg) {
unsigned int i;
if(!arg) {
- if(++layout == &layouts[NLAYOUTS])
+ if(++layout == &layouts[LENGTH(layouts)])
layout = &layouts[0];
}
else {
- for(i = 0; i < NLAYOUTS; i++)
+ for(i = 0; i < LENGTH(layouts); i++)
if(!strcmp(arg, layouts[i].symbol))
break;
- if(i == NLAYOUTS)
+ if(i == LENGTH(layouts))
return;
layout = &layouts[i];
}
t@@ -1469,7 +1469,7 @@ setup(void) {
/* init layouts */
mwfact = MWFACT;
layout = &layouts[0];
- for(blw = i = 0; i < NLAYOUTS; i++) {
+ for(blw = i = 0; i < LENGTH(layouts); i++) {
j = textw(layouts[i].symbol);
if(j > blw)
blw = j;
t@@ -1527,7 +1527,7 @@ tag(const char *arg) {
if(!sel)
return;
- for(i = 0; i < NTAGS; i++)
+ for(i = 0; i < LENGTH(tags); i++)
sel->tags[i] = (NULL == arg);
sel->tags[idxoftag(arg)] = True;
arrange();
t@@ -1649,8 +1649,8 @@ toggletag(const char *arg) {
return;
i = idxoftag(arg);
sel->tags[i] = !sel->tags[i];
- for(j = 0; j < NTAGS && !sel->tags[j]; j++);
- if(j == NTAGS)
+ for(j = 0; j < LENGTH(tags) && !sel->tags[j]; j++);
+ if(j == LENGTH(tags))
sel->tags[i] = True; /* at least one tag must be enabled */
arrange();
}
t@@ -1661,8 +1661,8 @@ toggleview(const char *arg) {
i = idxoftag(arg);
seltags[i] = !seltags[i];
- for(j = 0; j < NTAGS && !seltags[j]; j++);
- if(j == NTAGS)
+ for(j = 0; j < LENGTH(tags) && !seltags[j]; j++);
+ if(j == LENGTH(tags))
seltags[i] = True; /* at least one tag must be viewed */
arrange();
}
t@@ -1828,7 +1828,7 @@ view(const char *arg) {
unsigned int i;
memcpy(prevtags, seltags, sizeof seltags);
- for(i = 0; i < NTAGS; i++)
+ for(i = 0; i < LENGTH(tags); i++)
seltags[i] = (NULL == arg);
seltags[idxoftag(arg)] = True;
arrange();
You are viewing proxied material from mx1.adamsgaard.dk. 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.