summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dwm.c134
1 files changed, 95 insertions, 39 deletions
diff --git a/dwm.c b/dwm.c
index 3f896dc..5d93d34 100644
--- a/dwm.c
+++ b/dwm.c
@@ -136,6 +136,7 @@ void focusnext(const char *arg);
136void focusprev(const char *arg); 136void focusprev(const char *arg);
137Client *getclient(Window w); 137Client *getclient(Window w);
138unsigned long getcolor(const char *colstr); 138unsigned long getcolor(const char *colstr);
139double getdouble(const char *s);
139long getstate(Window w); 140long getstate(Window w);
140Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); 141Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
141void grabbuttons(Client *c, Bool focused); 142void grabbuttons(Client *c, Bool focused);
@@ -163,7 +164,7 @@ void restack(void);
163void run(void); 164void run(void);
164void scan(void); 165void scan(void);
165void setclientstate(Client *c, long state); 166void setclientstate(Client *c, long state);
166void setdefgeoms(void); 167void setgeom(const char *arg);
167void setlayout(const char *arg); 168void setlayout(const char *arg);
168void setup(void); 169void setup(void);
169void spawn(const char *arg); 170void spawn(const char *arg);
@@ -410,7 +411,7 @@ configurenotify(XEvent *e) {
410 XConfigureEvent *ev = &e->xconfigure; 411 XConfigureEvent *ev = &e->xconfigure;
411 412
412 if(ev->window == root && (ev->width != sw || ev->height != sh)) { 413 if(ev->window == root && (ev->width != sw || ev->height != sh)) {
413 setgeoms(); 414 setgeom(NULL);
414 updatebarpos(); 415 updatebarpos();
415 arrange(); 416 arrange();
416 } 417 }
@@ -1390,44 +1391,95 @@ setclientstate(Client *c, long state) {
1390 PropModeReplace, (unsigned char *)data, 2); 1391 PropModeReplace, (unsigned char *)data, 2);
1391} 1392}
1392 1393
1393void 1394/**
1394setdefgeoms(void) { 1395 * Idea:
1395 1396 *
1396 /* screen dimensions */ 1397 * having a geom syntax as follows, which is interpreted as integer.
1397 sx = 0; 1398 *
1398 sy = 0; 1399 * [-,+][<0..n>|<W,H,B>]
1399 sw = DisplayWidth(dpy, screen); 1400 *
1400 sh = DisplayHeight(dpy, screen); 1401 *
1401 1402 * B = bar height, W = DisplayWidth(), H = DisplayHeight()
1402 /* bar position */ 1403 *
1403 bx = sx; 1404 * -/+/* /: is relative to current
1404 by = sy; 1405 *
1405 bw = sw; 1406 * Then we would come down with <bx>,<by>,<bw>,<bh>,...
1406 bh = dc.font.height + 2; 1407 *
1407 1408 * "0 0 W B 0 0 W W N E B,W,B,
1408 /* window area */ 1409 *
1409 wx = sx; 1410 *
1410 wy = sy + bh; 1411 */
1411 ww = sw;
1412 wh = sh - bh;
1413 1412
1414 /* master area */ 1413double
1415 mx = wx; 1414getdouble(const char *s) {
1416 my = wy; 1415 char *endp;
1417 mw = ((float)sw) * 0.55; 1416 double result = 0;
1418 mh = wh; 1417
1418 fprintf(stderr, "getdouble '%s'\n", s);
1419 switch(*s) {
1420 default:
1421 result = strtod(s, &endp);
1422 if(s == endp || *endp != 0)
1423 result = strtol(s, &endp, 0);
1424 break;
1425 case 'B': result = dc.font.height + 2; break;
1426 case 'W': result = sw; break;
1427 case 'H': result = sh; break;
1428 }
1429 fprintf(stderr, "getdouble returns '%f'\n", result);
1430 return result;
1431}
1419 1432
1420 /* tile area */ 1433void
1421 tx = mx + mw; 1434setgeom(const char *arg) {
1422 ty = wy; 1435 static const char *lastArg = NULL;
1423 tw = ww - mw; 1436 char op, *s, *e, *p;
1424 th = wh; 1437 double val;
1438 int i, *map[] = { &bx, &by, &bw, &bh,
1439 &wx, &wy, &ww, &wh,
1440 &mx, &my, &mw, &mh,
1441 &tx, &ty, &tw, &th,
1442 &mox, &moy, &mow, &moh };
1425 1443
1426 /* monocle area */ 1444 if(!arg)
1427 mox = wx; 1445 arg = lastArg;
1428 moy = wy; 1446 else
1429 mow = ww; 1447 lastArg = arg;
1430 moh = wh; 1448 if(!lastArg)
1449 return;
1450 strncpy(buf, arg, sizeof buf);
1451 for(i = 0, e = s = buf; e && *e; e++)
1452 if(*e == ' ') {
1453 *e = 0;
1454 fprintf(stderr, "next geom arg='%s'\n", s);
1455 op = 0;
1456 /* check if there is an operator */
1457 for(p = s; *p && *p != '-' && *p != '+' && *p != '*' && *p != ':'; p++);
1458 if(*p) {
1459 op = *p;
1460 *p = 0;
1461 }
1462 val = getdouble(s);
1463 fprintf(stderr, "val1: %d\n", val);
1464 if(p > s) { /* intermediate operand, e.g. H-B */
1465 *(map[i]) = val;
1466 s = ++p;
1467 val = getdouble(s);
1468 fprintf(stderr, "val2: %d\n", val);
1469 }
1470 switch(op) {
1471 default: *(map[i]) = val; break;
1472 case '-': *(map[i]) -= val; break;
1473 case '+': *(map[i]) += val; break;
1474 case '*': *(map[i]) *= val; break;
1475 case ':': if(val != 0) *(map[i]) /= val; break;
1476 }
1477 fprintf(stderr, "map[i]='%d'\n", val);
1478 s = ++e;
1479 i++;
1480 }
1481 updatebarpos();
1482 arrange();
1431} 1483}
1432 1484
1433void 1485void
@@ -1464,8 +1516,12 @@ setup(void) {
1464 root = RootWindow(dpy, screen); 1516 root = RootWindow(dpy, screen);
1465 initfont(FONT); 1517 initfont(FONT);
1466 1518
1467 /* apply default geometries */ 1519 /* apply default dimensions */
1468 setgeoms(); 1520 sx = 0;
1521 sy = 0;
1522 sw = DisplayWidth(dpy, screen);
1523 sh = DisplayHeight(dpy, screen);
1524 setgeom(GEOMETRY);
1469 1525
1470 /* init atoms */ 1526 /* init atoms */
1471 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 1527 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);