summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--config.def.h28
-rw-r--r--dwm.c99
2 files changed, 40 insertions, 87 deletions
diff --git a/config.def.h b/config.def.h
index f6d90d8..8130909 100644
--- a/config.def.h
+++ b/config.def.h
@@ -9,19 +9,6 @@
9#define SELBORDERCOLOR "#0066ff" 9#define SELBORDERCOLOR "#0066ff"
10#define SELBGCOLOR "#0066ff" 10#define SELBGCOLOR "#0066ff"
11#define SELFGCOLOR "#ffffff" 11#define SELFGCOLOR "#ffffff"
12#define GEOMETRY "0 0 W B " \
13 "0 B W H-B " \
14 "0 B W*0.55 H-B " \
15 "W*0.55 B W*0.45 H-B " \
16 "0 B W H-B"
17
18/* Anselm's dual head geometry in the office */
19#define DUALGEOMETRY "0 0 1280 B " \
20 "0 B W H-B " \
21 "0 B 1280 800-B " \
22 "1280 0 W-1280 H " \
23 "0 B 1280 800-B"
24
25 12
26/* tagging */ 13/* tagging */
27const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; 14const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
@@ -34,6 +21,17 @@ Rule rules[] = {
34 { NULL, NULL, "Acroread", NULL, True }, 21 { NULL, NULL, "Acroread", NULL, True },
35}; 22};
36 23
24/* geometries, s{x,y,w,h} and bh are already initualized here */
25/* func name bx by bw wx wy ww wh mx my mw mh tx ty tw th mox moy mow moh */
26DEFGEOM(single, 0, 0, sw, 0, bh, sw, sh-bh, wx, wy, 0.55*sw, wh, mx+mw, wy, ww-mw, wh, wx, wy, ww, wh)
27DEFGEOM(dual, 0, 0,1280, 0, bh, ww, wh-bh, wx, wy, 1280,800-bh, 1280, 0, ww-mw, sh, mx, my, mw, mh)
28
29Geom geoms[] = {
30 /* symbol function */
31 { "[]", single }, /* first entry is default */
32 { "[][]", dual },
33};
34
37/* layout(s) */ 35/* layout(s) */
38#define RESIZEHINTS True /* False - respect size hints in tiled resizals */ 36#define RESIZEHINTS True /* False - respect size hints in tiled resizals */
39#define SNAP 32 /* snap pixel */ 37#define SNAP 32 /* snap pixel */
@@ -50,8 +48,8 @@ Layout layouts[] = {
50#define MODKEY Mod1Mask 48#define MODKEY Mod1Mask
51Key keys[] = { 49Key keys[] = {
52 /* modifier key function argument */ 50 /* modifier key function argument */
53 { MODKEY, XK_a, setgeom, DUALGEOMETRY }, 51 { MODKEY, XK_a, setgeom, "[][]" },
54 { MODKEY, XK_d, setgeom, GEOMETRY }, 52 { MODKEY, XK_d, setgeom, "[]" },
55 { MODKEY, XK_p, spawn, 53 { MODKEY, XK_p, spawn,
56 "exec dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb '"SELBGCOLOR"' -sf '"SELFGCOLOR"'" }, 54 "exec dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb '"SELBGCOLOR"' -sf '"SELFGCOLOR"'" },
57 { MODKEY|ShiftMask, XK_Return, spawn, "exec uxterm" }, 55 { MODKEY|ShiftMask, XK_Return, spawn, "exec uxterm" },
diff --git a/dwm.c b/dwm.c
index 4a9ca82..f83e800 100644
--- a/dwm.c
+++ b/dwm.c
@@ -46,6 +46,14 @@
46#define LENGTH(x) (sizeof x / sizeof x[0]) 46#define LENGTH(x) (sizeof x / sizeof x[0])
47#define MAXTAGLEN 16 47#define MAXTAGLEN 16
48#define MOUSEMASK (BUTTONMASK|PointerMotionMask) 48#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
49#define DEFGEOM(GEONAME,BX,BY,BW,WX,WY,WW,WH,MX,MY,MW,MH,TX,TY,TW,TH,MOX,MOY,MOW,MOH) \
50void GEONAME(void) { \
51 bx = (BX); by = (BY); bw = (BW); \
52 wx = (WX); wy = (WY); ww = (WW); wh = (WH); \
53 mx = (MX); my = (MY); mw = (MW); mh = (MH); \
54 tx = (TX); ty = (TY); tw = (TW); th = (TH); \
55 mox = (MOX); moy = (MOY); mow = (MOW); moh = (MOH); \
56}
49 57
50/* enums */ 58/* enums */
51enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 59enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
@@ -86,6 +94,11 @@ typedef struct {
86} DC; /* draw context */ 94} DC; /* draw context */
87 95
88typedef struct { 96typedef struct {
97 const char *symbol;
98 void (*apply)(void);
99} Geom;
100
101typedef struct {
89 unsigned long mod; 102 unsigned long mod;
90 KeySym keysym; 103 KeySym keysym;
91 void (*func)(const char *arg); 104 void (*func)(const char *arg);
@@ -107,7 +120,6 @@ typedef struct {
107} Rule; 120} Rule;
108 121
109/* function declarations */ 122/* function declarations */
110void applygeom(const char *arg);
111void applyrules(Client *c); 123void applyrules(Client *c);
112void arrange(void); 124void arrange(void);
113void attach(Client *c); 125void attach(Client *c);
@@ -137,7 +149,6 @@ void focusnext(const char *arg);
137void focusprev(const char *arg); 149void focusprev(const char *arg);
138Client *getclient(Window w); 150Client *getclient(Window w);
139unsigned long getcolor(const char *colstr); 151unsigned long getcolor(const char *colstr);
140double getdouble(const char *s);
141long getstate(Window w); 152long getstate(Window w);
142Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); 153Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
143void grabbuttons(Client *c, Bool focused); 154void grabbuttons(Client *c, Bool focused);
@@ -226,6 +237,7 @@ Client *stack = NULL;
226Cursor cursor[CurLast]; 237Cursor cursor[CurLast];
227Display *dpy; 238Display *dpy;
228DC dc = {0}; 239DC dc = {0};
240Geom *geom = NULL;
229Layout *lt = NULL; 241Layout *lt = NULL;
230Window root, barwin; 242Window root, barwin;
231 243
@@ -237,55 +249,6 @@ static Bool tmp[LENGTH(tags)];
237/* function implementations */ 249/* function implementations */
238 250
239void 251void
240applygeometry(const char *arg) {
241 static const char *lastArg = NULL;
242 char delim, op, *s, *e, *p;
243 double val;
244 int i, *map[] = { &bx, &by, &bw, &bh,
245 &wx, &wy, &ww, &wh,
246 &mx, &my, &mw, &mh,
247 &tx, &ty, &tw, &th,
248 &mox, &moy, &mow, &moh };
249
250 if(!arg)
251 arg = lastArg;
252 else
253 lastArg = arg;
254 if(!lastArg)
255 return;
256 strncpy(buf, arg, sizeof buf);
257 for(i = 0, e = s = buf; i < LENGTH(map) && e; e++)
258 if(*e == ' ' || *e == 0) {
259 delim = *e;
260 *e = 0;
261 op = 0;
262 /* check if there is an operator */
263 for(p = s; p < e && *p != '-' && *p != '+' && *p != '*'; p++);
264 if(*p) {
265 op = *p;
266 *p = 0;
267 }
268 val = getdouble(s);
269 if(op && p > s) { /* intermediate operand, e.g. H-B */
270 *(map[i]) = (int)val;
271 s = ++p;
272 val = getdouble(s);
273 }
274 switch(op) {
275 default: *(map[i]) = (int)val; break;
276 case '-': *(map[i]) -= (int)val; break;
277 case '+': *(map[i]) += (int)val; break;
278 case '*': *(map[i]) = (int)(((double)*(map[i])) * val); break;
279 }
280 if(delim == 0)
281 e = NULL;
282 else
283 s = ++e;
284 i++;
285 }
286}
287
288void
289applyrules(Client *c) { 252applyrules(Client *c) {
290 unsigned int i; 253 unsigned int i;
291 Bool matched = False; 254 Bool matched = False;
@@ -1438,27 +1401,17 @@ setclientstate(Client *c, long state) {
1438 PropModeReplace, (unsigned char *)data, 2); 1401 PropModeReplace, (unsigned char *)data, 2);
1439} 1402}
1440 1403
1441double
1442getdouble(const char *s) {
1443 char *endp;
1444 double result = 0;
1445
1446 switch(*s) {
1447 default:
1448 result = strtod(s, &endp);
1449 if(s == endp || *endp != 0)
1450 result = strtol(s, &endp, 0);
1451 break;
1452 case 'B': result = dc.font.height + 2; break;
1453 case 'W': result = sw; break;
1454 case 'H': result = sh; break;
1455 }
1456 return result;
1457}
1458
1459void 1404void
1460setgeom(const char *arg) { 1405setgeom(const char *arg) {
1461 applygeometry(arg); 1406 unsigned int i;
1407
1408 for(i = 0; arg && i < LENGTH(geoms); i++)
1409 if(!strcmp(geoms[i].symbol, arg))
1410 break;
1411 if(i == LENGTH(geoms))
1412 return;
1413 geom = &geoms[i];
1414 geom->apply();
1462 updatebarpos(); 1415 updatebarpos();
1463 arrange(); 1416 arrange();
1464} 1417}
@@ -1497,12 +1450,14 @@ setup(void) {
1497 root = RootWindow(dpy, screen); 1450 root = RootWindow(dpy, screen);
1498 initfont(FONT); 1451 initfont(FONT);
1499 1452
1500 /* apply default dimensions */ 1453 /* apply default geometry */
1501 sx = 0; 1454 sx = 0;
1502 sy = 0; 1455 sy = 0;
1503 sw = DisplayWidth(dpy, screen); 1456 sw = DisplayWidth(dpy, screen);
1504 sh = DisplayHeight(dpy, screen); 1457 sh = DisplayHeight(dpy, screen);
1505 applygeometry(GEOMETRY); 1458 bh = dc.font.height + 2;
1459 geom = &geoms[0];
1460 geom->apply();
1506 1461
1507 /* init atoms */ 1462 /* init atoms */
1508 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 1463 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);