diff options
| -rw-r--r-- | config.def.h | 28 | ||||
| -rw-r--r-- | dwm.c | 99 |
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 */ |
| 27 | const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; | 14 | const 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 */ | ||
| 26 | DEFGEOM(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) | ||
| 27 | DEFGEOM(dual, 0, 0,1280, 0, bh, ww, wh-bh, wx, wy, 1280,800-bh, 1280, 0, ww-mw, sh, mx, my, mw, mh) | ||
| 28 | |||
| 29 | Geom 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 |
| 51 | Key keys[] = { | 49 | Key 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" }, |
| @@ -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) \ | ||
| 50 | void 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 */ |
| 51 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ | 59 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
| @@ -86,6 +94,11 @@ typedef struct { | |||
| 86 | } DC; /* draw context */ | 94 | } DC; /* draw context */ |
| 87 | 95 | ||
| 88 | typedef struct { | 96 | typedef struct { |
| 97 | const char *symbol; | ||
| 98 | void (*apply)(void); | ||
| 99 | } Geom; | ||
| 100 | |||
| 101 | typedef 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 */ |
| 110 | void applygeom(const char *arg); | ||
| 111 | void applyrules(Client *c); | 123 | void applyrules(Client *c); |
| 112 | void arrange(void); | 124 | void arrange(void); |
| 113 | void attach(Client *c); | 125 | void attach(Client *c); |
| @@ -137,7 +149,6 @@ void focusnext(const char *arg); | |||
| 137 | void focusprev(const char *arg); | 149 | void focusprev(const char *arg); |
| 138 | Client *getclient(Window w); | 150 | Client *getclient(Window w); |
| 139 | unsigned long getcolor(const char *colstr); | 151 | unsigned long getcolor(const char *colstr); |
| 140 | double getdouble(const char *s); | ||
| 141 | long getstate(Window w); | 152 | long getstate(Window w); |
| 142 | Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); | 153 | Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
| 143 | void grabbuttons(Client *c, Bool focused); | 154 | void grabbuttons(Client *c, Bool focused); |
| @@ -226,6 +237,7 @@ Client *stack = NULL; | |||
| 226 | Cursor cursor[CurLast]; | 237 | Cursor cursor[CurLast]; |
| 227 | Display *dpy; | 238 | Display *dpy; |
| 228 | DC dc = {0}; | 239 | DC dc = {0}; |
| 240 | Geom *geom = NULL; | ||
| 229 | Layout *lt = NULL; | 241 | Layout *lt = NULL; |
| 230 | Window root, barwin; | 242 | Window root, barwin; |
| 231 | 243 | ||
| @@ -237,55 +249,6 @@ static Bool tmp[LENGTH(tags)]; | |||
| 237 | /* function implementations */ | 249 | /* function implementations */ |
| 238 | 250 | ||
| 239 | void | 251 | void |
| 240 | applygeometry(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 | |||
| 288 | void | ||
| 289 | applyrules(Client *c) { | 252 | applyrules(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 | ||
| 1441 | double | ||
| 1442 | getdouble(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 | |||
| 1459 | void | 1404 | void |
| 1460 | setgeom(const char *arg) { | 1405 | setgeom(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); |
