tremoved the string-based setgeom approach, introduced a new Geom type instead … | |
git clone git://src.adamsgaard.dk/dwm | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit aa2395b6a81475b44dd74618fb7f0b40305e10bb | |
parent dba22848c7d077c1a988a901c9390dc3c8cc9d64 | |
Author: Anselm R Garbe <[email protected]> | |
Date: Mon, 17 Mar 2008 14:56:11 +0000 | |
removed the string-based setgeom approach, introduced a new Geom type instead a… | |
Diffstat: | |
M config.def.h | 28 +++++++++++++--------------- | |
M dwm.c | 99 +++++++++--------------------… | |
2 files changed, 40 insertions(+), 87 deletions(-) | |
--- | |
diff --git a/config.def.h b/config.def.h | |
t@@ -9,19 +9,6 @@ | |
#define SELBORDERCOLOR "#0066ff" | |
#define SELBGCOLOR "#0066ff" | |
#define SELFGCOLOR "#ffffff" | |
-#define GEOMETRY "0 0 W B " \ | |
- "0 B W H-B " \ | |
- "0 B W*0.55 H-B " \ | |
- "W*0.55 B W*0.45 H-B " \ | |
- "0 B W H-B" | |
- | |
-/* Anselm's dual head geometry in the office */ | |
-#define DUALGEOMETRY "0 0 1280 B " \ | |
- "0 B W H-B " \ | |
- "0 B 1280 800-B " \ | |
- "1280 0 W-1280 H " \ | |
- "0 B 1280 800-B" | |
- | |
/* tagging */ | |
const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; | |
t@@ -34,6 +21,17 @@ Rule rules[] = { | |
{ NULL, NULL, "Acroread", NULL, … | |
}; | |
+/* geometries, s{x,y,w,h} and bh are already initualized here */ | |
+/* func name bx by bw wx wy ww wh mx my mw mh tx ty … | |
+DEFGEOM(single, 0, 0, sw, 0, bh, sw, sh-bh, wx, wy, 0.55*sw, wh, mx+mw, wy,… | |
+DEFGEOM(dual, 0, 0,1280, 0, bh, ww, wh-bh, wx, wy, 1280,800-bh, 1280, 0,… | |
+ | |
+Geom geoms[] = { | |
+ /* symbol function */ | |
+ { "[]", single }, /* first entry is default */ | |
+ { "[][]", dual }, | |
+}; | |
+ | |
/* layout(s) */ | |
#define RESIZEHINTS True /* False - respect size hints i… | |
#define SNAP 32 /* snap pixel */ | |
t@@ -50,8 +48,8 @@ Layout layouts[] = { | |
#define MODKEY Mod1Mask | |
Key keys[] = { | |
/* modifier key function … | |
- { MODKEY, XK_a, setgeom, … | |
- { MODKEY, XK_d, setgeom, … | |
+ { MODKEY, XK_a, setgeom, … | |
+ { MODKEY, XK_d, setgeom, … | |
{ MODKEY, XK_p, spawn, | |
"exec dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGC… | |
{ MODKEY|ShiftMask, XK_Return, spawn, "exec uxte… | |
diff --git a/dwm.c b/dwm.c | |
t@@ -46,6 +46,14 @@ | |
#define LENGTH(x) (sizeof x / sizeof x[0]) | |
#define MAXTAGLEN 16 | |
#define MOUSEMASK (BUTTONMASK|PointerMotionMask) | |
+#define DEFGEOM(GEONAME,BX,BY,BW,WX,WY,WW,WH,MX,MY,MW,MH,TX,TY,TW,TH,MOX,MOY,M… | |
+void GEONAME(void) { \ | |
+ bx = (BX); by = (BY); bw = (BW); \ | |
+ wx = (WX); wy = (WY); ww = (WW); wh = (WH); \ | |
+ mx = (MX); my = (MY); mw = (MW); mh = (MH); \ | |
+ tx = (TX); ty = (TY); tw = (TW); th = (TH); \ | |
+ mox = (MOX); moy = (MOY); mow = (MOW); moh = (MOH); \ | |
+} | |
/* enums */ | |
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ | |
t@@ -86,6 +94,11 @@ typedef struct { | |
} DC; /* draw context */ | |
typedef struct { | |
+ const char *symbol; | |
+ void (*apply)(void); | |
+} Geom; | |
+ | |
+typedef struct { | |
unsigned long mod; | |
KeySym keysym; | |
void (*func)(const char *arg); | |
t@@ -107,7 +120,6 @@ typedef struct { | |
} Rule; | |
/* function declarations */ | |
-void applygeom(const char *arg); | |
void applyrules(Client *c); | |
void arrange(void); | |
void attach(Client *c); | |
t@@ -137,7 +149,6 @@ void focusnext(const char *arg); | |
void focusprev(const char *arg); | |
Client *getclient(Window w); | |
unsigned long getcolor(const char *colstr); | |
-double getdouble(const char *s); | |
long getstate(Window w); | |
Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); | |
void grabbuttons(Client *c, Bool focused); | |
t@@ -226,6 +237,7 @@ Client *stack = NULL; | |
Cursor cursor[CurLast]; | |
Display *dpy; | |
DC dc = {0}; | |
+Geom *geom = NULL; | |
Layout *lt = NULL; | |
Window root, barwin; | |
t@@ -237,55 +249,6 @@ static Bool tmp[LENGTH(tags)]; | |
/* function implementations */ | |
void | |
-applygeometry(const char *arg) { | |
- static const char *lastArg = NULL; | |
- char delim, op, *s, *e, *p; | |
- double val; | |
- int i, *map[] = { &bx, &by, &bw, &bh, | |
- &wx, &wy, &ww, &wh, | |
- &mx, &my, &mw, &mh, | |
- &tx, &ty, &tw, &th, | |
- &mox, &moy, &mow, &moh }; | |
- | |
- if(!arg) | |
- arg = lastArg; | |
- else | |
- lastArg = arg; | |
- if(!lastArg) | |
- return; | |
- strncpy(buf, arg, sizeof buf); | |
- for(i = 0, e = s = buf; i < LENGTH(map) && e; e++) | |
- if(*e == ' ' || *e == 0) { | |
- delim = *e; | |
- *e = 0; | |
- op = 0; | |
- /* check if there is an operator */ | |
- for(p = s; p < e && *p != '-' && *p != '+' && *p != '*… | |
- if(*p) { | |
- op = *p; | |
- *p = 0; | |
- } | |
- val = getdouble(s); | |
- if(op && p > s) { /* intermediate operand, e.g. H-B */ | |
- *(map[i]) = (int)val; | |
- s = ++p; | |
- val = getdouble(s); | |
- } | |
- switch(op) { | |
- default: *(map[i]) = (int)val; break; | |
- case '-': *(map[i]) -= (int)val; break; | |
- case '+': *(map[i]) += (int)val; break; | |
- case '*': *(map[i]) = (int)(((double)*(map[i])) * val… | |
- } | |
- if(delim == 0) | |
- e = NULL; | |
- else | |
- s = ++e; | |
- i++; | |
- } | |
-} | |
- | |
-void | |
applyrules(Client *c) { | |
unsigned int i; | |
Bool matched = False; | |
t@@ -1438,27 +1401,17 @@ setclientstate(Client *c, long state) { | |
PropModeReplace, (unsigned char *)data, 2); | |
} | |
-double | |
-getdouble(const char *s) { | |
- char *endp; | |
- double result = 0; | |
- | |
- switch(*s) { | |
- default: | |
- result = strtod(s, &endp); | |
- if(s == endp || *endp != 0) | |
- result = strtol(s, &endp, 0); | |
- break; | |
- case 'B': result = dc.font.height + 2; break; | |
- case 'W': result = sw; break; | |
- case 'H': result = sh; break; | |
- } | |
- return result; | |
-} | |
- | |
void | |
setgeom(const char *arg) { | |
- applygeometry(arg); | |
+ unsigned int i; | |
+ | |
+ for(i = 0; arg && i < LENGTH(geoms); i++) | |
+ if(!strcmp(geoms[i].symbol, arg)) | |
+ break; | |
+ if(i == LENGTH(geoms)) | |
+ return; | |
+ geom = &geoms[i]; | |
+ geom->apply(); | |
updatebarpos(); | |
arrange(); | |
} | |
t@@ -1497,12 +1450,14 @@ setup(void) { | |
root = RootWindow(dpy, screen); | |
initfont(FONT); | |
- /* apply default dimensions */ | |
+ /* apply default geometry */ | |
sx = 0; | |
sy = 0; | |
sw = DisplayWidth(dpy, screen); | |
sh = DisplayHeight(dpy, screen); | |
- applygeometry(GEOMETRY); | |
+ bh = dc.font.height + 2; | |
+ geom = &geoms[0]; | |
+ geom->apply(); | |
/* init atoms */ | |
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |