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.

This commit is contained in:
Anselm R. Garbe 2007-10-28 12:41:14 +01:00
parent 3fd39feb41
commit c36f7c3c5e
2 changed files with 31 additions and 36 deletions

View file

@ -23,9 +23,9 @@ Rule rules[] = {
{ "MPlayer", NULL, True }, { "MPlayer", NULL, True },
{ "Acroread", NULL, True }, { "Acroread", NULL, True },
}; };
#define NRULES (sizeof rules / sizeof rules[0])
/* layout(s) */ /* layout(s) */
#define ISTILE isarrange(tile) /* || isarrange(<custom>) */
#define MWFACT 0.6 /* master width factor [0.1 .. 0.9] */ #define MWFACT 0.6 /* master width factor [0.1 .. 0.9] */
#define SNAP 32 /* snap pixel */ #define SNAP 32 /* snap pixel */
Layout layouts[] = { Layout layouts[] = {
@ -33,6 +33,7 @@ Layout layouts[] = {
{ "[]=", tile }, /* first entry is default */ { "[]=", tile }, /* first entry is default */
{ "><>", floating }, { "><>", floating },
}; };
#define NLAYOUTS (sizeof layouts / sizeof layouts[0])
/* key definitions */ /* key definitions */
#define MODKEY Mod1Mask #define MODKEY Mod1Mask
@ -94,3 +95,4 @@ Key keys[] = { \
{ MODKEY|ControlMask|ShiftMask, XK_9, toggletag, tags[8] }, \ { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, tags[8] }, \
{ MODKEY|ShiftMask, XK_q, quit, NULL }, \ { MODKEY|ShiftMask, XK_q, quit, NULL }, \
}; };
#define NKEYS (sizeof keys / sizeof keys[0])

63
dwm.c
View file

@ -145,7 +145,6 @@ Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
void grabbuttons(Client *c, Bool focused); void grabbuttons(Client *c, Bool focused);
unsigned int idxoftag(const char *tag); unsigned int idxoftag(const char *tag);
void initfont(const char *fontstr); void initfont(const char *fontstr);
Bool isarrange(void (*func)());
Bool isoccupied(unsigned int t); Bool isoccupied(unsigned int t);
Bool isprotodel(Client *c); Bool isprotodel(Client *c);
Bool isvisible(Client *c); Bool isvisible(Client *c);
@ -198,9 +197,6 @@ int screen, sx, sy, sw, sh, wax, way, waw, wah;
int (*xerrorxlib)(Display *, XErrorEvent *); int (*xerrorxlib)(Display *, XErrorEvent *);
unsigned int bh, bpos; unsigned int bh, bpos;
unsigned int blw = 0; unsigned int blw = 0;
unsigned int ltidx = 0; /* default */
unsigned int nlayouts = 0;
unsigned int nrules = 0;
unsigned int numlockmask = 0; unsigned int numlockmask = 0;
void (*handler[LASTEvent]) (XEvent *) = { void (*handler[LASTEvent]) (XEvent *) = {
[ButtonPress] = buttonpress, [ButtonPress] = buttonpress,
@ -217,6 +213,8 @@ void (*handler[LASTEvent]) (XEvent *) = {
[UnmapNotify] = unmapnotify [UnmapNotify] = unmapnotify
}; };
Atom wmatom[WMLast], netatom[NetLast]; Atom wmatom[WMLast], netatom[NetLast];
Bool domwfact = True;
Bool dozoom = True;
Bool otherwm, readin; Bool otherwm, readin;
Bool running = True; Bool running = True;
Bool selscreen = True; Bool selscreen = True;
@ -226,6 +224,7 @@ Client *stack = NULL;
Cursor cursor[CurLast]; Cursor cursor[CurLast];
Display *dpy; Display *dpy;
DC dc = {0}; DC dc = {0};
Layout *layout = NULL;
Window barwin, root; Window barwin, root;
Regs *regs = NULL; Regs *regs = NULL;
@ -246,7 +245,7 @@ applyrules(Client *c) {
snprintf(buf, sizeof buf, "%s:%s:%s", snprintf(buf, sizeof buf, "%s:%s:%s",
ch.res_class ? ch.res_class : "", ch.res_class ? ch.res_class : "",
ch.res_name ? ch.res_name : "", c->name); ch.res_name ? ch.res_name : "", c->name);
for(i = 0; i < nrules; i++) for(i = 0; i < NRULES; i++)
if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) { if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
c->isfloating = rules[i].isfloating; c->isfloating = rules[i].isfloating;
for(j = 0; regs[i].tagregex && j < NTAGS; j++) { for(j = 0; regs[i].tagregex && j < NTAGS; j++) {
@ -273,7 +272,7 @@ arrange(void) {
unban(c); unban(c);
else else
ban(c); ban(c);
layouts[ltidx].arrange(); layout->arrange();
focus(NULL); focus(NULL);
restack(); restack();
} }
@ -334,20 +333,20 @@ buttonpress(XEvent *e) {
if(CLEANMASK(ev->state) != MODKEY) if(CLEANMASK(ev->state) != MODKEY)
return; return;
if(ev->button == Button1) { if(ev->button == Button1) {
if(isarrange(floating) || c->isfloating) if((floating == layout->arrange) || c->isfloating)
restack(); restack();
else else
togglefloating(NULL); togglefloating(NULL);
movemouse(c); movemouse(c);
} }
else if(ev->button == Button2) { else if(ev->button == Button2) {
if((ISTILE) && !c->isfixed && c->isfloating) if((floating != layout->arrange) && !c->isfixed && c->isfloating)
togglefloating(NULL); togglefloating(NULL);
else else
zoom(NULL); zoom(NULL);
} }
else if(ev->button == Button3 && !c->isfixed) { else if(ev->button == Button3 && !c->isfixed) {
if(isarrange(floating) || c->isfloating) if((floating == layout->arrange) || c->isfloating)
restack(); restack();
else else
togglefloating(NULL); togglefloating(NULL);
@ -401,9 +400,8 @@ compileregs(void) {
if(regs) if(regs)
return; return;
nrules = sizeof rules / sizeof rules[0]; regs = emallocz(NRULES * sizeof(Regs));
regs = emallocz(nrules * sizeof(Regs)); for(i = 0; i < NRULES; i++) {
for(i = 0; i < nrules; i++) {
if(rules[i].prop) { if(rules[i].prop) {
reg = emallocz(sizeof(regex_t)); reg = emallocz(sizeof(regex_t));
if(regcomp(reg, rules[i].prop, REG_EXTENDED)) if(regcomp(reg, rules[i].prop, REG_EXTENDED))
@ -464,7 +462,7 @@ configurerequest(XEvent *e) {
c->ismax = False; c->ismax = False;
if(ev->value_mask & CWBorderWidth) if(ev->value_mask & CWBorderWidth)
c->border = ev->border_width; c->border = ev->border_width;
if(c->isfixed || c->isfloating || isarrange(floating)) { if(c->isfixed || c->isfloating || (floating == layout->arrange)) {
if(ev->value_mask & CWX) if(ev->value_mask & CWX)
c->x = ev->x; c->x = ev->x;
if(ev->value_mask & CWY) if(ev->value_mask & CWY)
@ -545,7 +543,7 @@ drawbar(void) {
dc.x += dc.w; dc.x += dc.w;
} }
dc.w = blw; dc.w = blw;
drawtext(layouts[ltidx].symbol, dc.norm); drawtext(layout->symbol, dc.norm);
x = dc.x + dc.w; x = dc.x + dc.w;
dc.w = textw(stext); dc.w = textw(stext);
dc.x = sw - dc.w; dc.x = sw - dc.w;
@ -676,6 +674,7 @@ void
floating(void) { /* default floating layout */ floating(void) { /* default floating layout */
Client *c; Client *c;
domwfact = dozoom = False;
for(c = clients; c; c = c->next) for(c = clients; c; c = c->next)
if(isvisible(c)) if(isvisible(c))
resize(c, c->x, c->y, c->w, c->h, True); resize(c, c->x, c->y, c->w, c->h, True);
@ -888,12 +887,6 @@ initfont(const char *fontstr) {
dc.font.height = dc.font.ascent + dc.font.descent; dc.font.height = dc.font.ascent + dc.font.descent;
} }
Bool
isarrange(void (*func)())
{
return func == layouts[ltidx].arrange;
}
Bool Bool
isoccupied(unsigned int t) { isoccupied(unsigned int t) {
Client *c; Client *c;
@ -932,7 +925,6 @@ isvisible(Client *c) {
void void
keypress(XEvent *e) { keypress(XEvent *e) {
KEYS KEYS
unsigned int len = sizeof keys / sizeof keys[0];
unsigned int i; unsigned int i;
KeyCode code; KeyCode code;
KeySym keysym; KeySym keysym;
@ -940,7 +932,7 @@ keypress(XEvent *e) {
if(!e) { /* grabkeys */ if(!e) { /* grabkeys */
XUngrabKey(dpy, AnyKey, AnyModifier, root); XUngrabKey(dpy, AnyKey, AnyModifier, root);
for(i = 0; i < len; i++) { for(i = 0; i < NKEYS; i++) {
code = XKeysymToKeycode(dpy, keys[i].keysym); code = XKeysymToKeycode(dpy, keys[i].keysym);
XGrabKey(dpy, code, keys[i].mod, root, True, XGrabKey(dpy, code, keys[i].mod, root, True,
GrabModeAsync, GrabModeAsync); GrabModeAsync, GrabModeAsync);
@ -955,7 +947,7 @@ keypress(XEvent *e) {
} }
ev = &e->xkey; ev = &e->xkey;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
for(i = 0; i < len; i++) for(i = 0; i < NKEYS; i++)
if(keysym == keys[i].keysym if(keysym == keys[i].keysym
&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)) && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state))
{ {
@ -1266,9 +1258,9 @@ restack(void) {
drawbar(); drawbar();
if(!sel) if(!sel)
return; return;
if(sel->isfloating || isarrange(floating)) if(sel->isfloating || (floating == layout->arrange))
XRaiseWindow(dpy, sel->win); XRaiseWindow(dpy, sel->win);
if(!isarrange(floating)) { if(floating != layout->arrange) {
wc.stack_mode = Below; wc.stack_mode = Below;
wc.sibling = barwin; wc.sibling = barwin;
if(!sel->isfloating) { if(!sel->isfloating) {
@ -1374,16 +1366,16 @@ setlayout(const char *arg) {
unsigned int i; unsigned int i;
if(!arg) { if(!arg) {
if(++ltidx == nlayouts) if(++layout == &layouts[NLAYOUTS])
ltidx = 0;; layout = &layouts[0];
} }
else { else {
for(i = 0; i < nlayouts; i++) for(i = 0; i < NLAYOUTS; i++)
if(!strcmp(arg, layouts[i].symbol)) if(!strcmp(arg, layouts[i].symbol))
break; break;
if(i == nlayouts) if(i == NLAYOUTS)
return; return;
ltidx = i; layout = &layouts[i];
} }
if(sel) if(sel)
arrange(); arrange();
@ -1395,7 +1387,7 @@ void
setmwfact(const char *arg) { setmwfact(const char *arg) {
double delta; double delta;
if(!(ISTILE)) if(!domwfact)
return; return;
/* arg handling, manipulate mwfact */ /* arg handling, manipulate mwfact */
if(NULL == arg) if(NULL == arg)
@ -1476,8 +1468,8 @@ setup(void) {
/* init layouts */ /* init layouts */
mwfact = MWFACT; mwfact = MWFACT;
nlayouts = sizeof layouts / sizeof layouts[0]; layout = &layouts[0];
for(blw = i = 0; i < nlayouts; i++) { for(blw = i = 0; i < NLAYOUTS; i++) {
j = textw(layouts[i].symbol); j = textw(layouts[i].symbol);
if(j > blw) if(j > blw)
blw = j; blw = j;
@ -1562,6 +1554,7 @@ tile(void) {
unsigned int i, n, nx, ny, nw, nh, mw, th; unsigned int i, n, nx, ny, nw, nh, mw, th;
Client *c, *mc; Client *c, *mc;
domwfact = dozoom = True;
for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
n++; n++;
@ -1627,7 +1620,7 @@ togglemax(const char *arg) {
if(!sel || sel->isfixed) if(!sel || sel->isfixed)
return; return;
if((sel->ismax = !sel->ismax)) { if((sel->ismax = !sel->ismax)) {
if(isarrange(floating) || sel->isfloating) if((floating == layout->arrange) || sel->isfloating)
sel->wasfloating = True; sel->wasfloating = True;
else { else {
togglefloating(NULL); togglefloating(NULL);
@ -1855,7 +1848,7 @@ void
zoom(const char *arg) { zoom(const char *arg) {
Client *c; Client *c;
if(!sel || !(ISTILE) || sel->isfloating) if(!sel || !dozoom || sel->isfloating)
return; return;
if((c = sel) == nexttiled(clients)) if((c = sel) == nexttiled(clients))
if(!(c = nexttiled(c->next))) if(!(c = nexttiled(c->next)))