diff options
| author | Anselm R Garbe <garbeam@gmail.com> | 2008-03-15 14:17:42 +0000 |
|---|---|---|
| committer | Anselm R Garbe <garbeam@gmail.com> | 2008-03-15 14:17:42 +0000 |
| commit | dba22848c7d077c1a988a901c9390dc3c8cc9d64 (patch) | |
| tree | b3e91f7a977bbb9debd6120df8058f112cc883b2 /dwm.c | |
| parent | some experimental state DO NOT USE THIS, I plan to have a nicer interface to ... (diff) | |
| download | dwm-dba22848c7d077c1a988a901c9390dc3c8cc9d64.tar.gz dwm-dba22848c7d077c1a988a901c9390dc3c8cc9d64.zip | |
made the string-based setgeom working
Diffstat (limited to 'dwm.c')
| -rw-r--r-- | dwm.c | 125 |
1 files changed, 53 insertions, 72 deletions
| @@ -107,6 +107,7 @@ typedef struct { | |||
| 107 | } Rule; | 107 | } Rule; |
| 108 | 108 | ||
| 109 | /* function declarations */ | 109 | /* function declarations */ |
| 110 | void applygeom(const char *arg); | ||
| 110 | void applyrules(Client *c); | 111 | void applyrules(Client *c); |
| 111 | void arrange(void); | 112 | void arrange(void); |
| 112 | void attach(Client *c); | 113 | void attach(Client *c); |
| @@ -236,6 +237,55 @@ static Bool tmp[LENGTH(tags)]; | |||
| 236 | /* function implementations */ | 237 | /* function implementations */ |
| 237 | 238 | ||
| 238 | void | 239 | 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 | ||
| 239 | applyrules(Client *c) { | 289 | applyrules(Client *c) { |
| 240 | unsigned int i; | 290 | unsigned int i; |
| 241 | Bool matched = False; | 291 | Bool matched = False; |
| @@ -410,11 +460,8 @@ void | |||
| 410 | configurenotify(XEvent *e) { | 460 | configurenotify(XEvent *e) { |
| 411 | XConfigureEvent *ev = &e->xconfigure; | 461 | XConfigureEvent *ev = &e->xconfigure; |
| 412 | 462 | ||
| 413 | if(ev->window == root && (ev->width != sw || ev->height != sh)) { | 463 | if(ev->window == root && (ev->width != sw || ev->height != sh)) |
| 414 | setgeom(NULL); | 464 | setgeom(NULL); |
| 415 | updatebarpos(); | ||
| 416 | arrange(); | ||
| 417 | } | ||
| 418 | } | 465 | } |
| 419 | 466 | ||
| 420 | void | 467 | void |
| @@ -1391,31 +1438,11 @@ setclientstate(Client *c, long state) { | |||
| 1391 | PropModeReplace, (unsigned char *)data, 2); | 1438 | PropModeReplace, (unsigned char *)data, 2); |
| 1392 | } | 1439 | } |
| 1393 | 1440 | ||
| 1394 | /** | ||
| 1395 | * Idea: | ||
| 1396 | * | ||
| 1397 | * having a geom syntax as follows, which is interpreted as integer. | ||
| 1398 | * | ||
| 1399 | * [-,+][<0..n>|<W,H,B>] | ||
| 1400 | * | ||
| 1401 | * | ||
| 1402 | * B = bar height, W = DisplayWidth(), H = DisplayHeight() | ||
| 1403 | * | ||
| 1404 | * -/+/* /: is relative to current | ||
| 1405 | * | ||
| 1406 | * Then we would come down with <bx>,<by>,<bw>,<bh>,... | ||
| 1407 | * | ||
| 1408 | * "0 0 W B 0 0 W W N E B,W,B, | ||
| 1409 | * | ||
| 1410 | * | ||
| 1411 | */ | ||
| 1412 | |||
| 1413 | double | 1441 | double |
| 1414 | getdouble(const char *s) { | 1442 | getdouble(const char *s) { |
| 1415 | char *endp; | 1443 | char *endp; |
| 1416 | double result = 0; | 1444 | double result = 0; |
| 1417 | 1445 | ||
| 1418 | fprintf(stderr, "getdouble '%s'\n", s); | ||
| 1419 | switch(*s) { | 1446 | switch(*s) { |
| 1420 | default: | 1447 | default: |
| 1421 | result = strtod(s, &endp); | 1448 | result = strtod(s, &endp); |
| @@ -1426,58 +1453,12 @@ getdouble(const char *s) { | |||
| 1426 | case 'W': result = sw; break; | 1453 | case 'W': result = sw; break; |
| 1427 | case 'H': result = sh; break; | 1454 | case 'H': result = sh; break; |
| 1428 | } | 1455 | } |
| 1429 | fprintf(stderr, "getdouble returns '%f'\n", result); | ||
| 1430 | return result; | 1456 | return result; |
| 1431 | } | 1457 | } |
| 1432 | 1458 | ||
| 1433 | void | 1459 | void |
| 1434 | setgeom(const char *arg) { | 1460 | setgeom(const char *arg) { |
| 1435 | static const char *lastArg = NULL; | 1461 | applygeometry(arg); |
| 1436 | char op, *s, *e, *p; | ||
| 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 }; | ||
| 1443 | |||
| 1444 | if(!arg) | ||
| 1445 | arg = lastArg; | ||
| 1446 | else | ||
| 1447 | lastArg = arg; | ||
| 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(); | 1462 | updatebarpos(); |
| 1482 | arrange(); | 1463 | arrange(); |
| 1483 | } | 1464 | } |
| @@ -1521,7 +1502,7 @@ setup(void) { | |||
| 1521 | sy = 0; | 1502 | sy = 0; |
| 1522 | sw = DisplayWidth(dpy, screen); | 1503 | sw = DisplayWidth(dpy, screen); |
| 1523 | sh = DisplayHeight(dpy, screen); | 1504 | sh = DisplayHeight(dpy, screen); |
| 1524 | setgeom(GEOMETRY); | 1505 | applygeometry(GEOMETRY); |
| 1525 | 1506 | ||
| 1526 | /* init atoms */ | 1507 | /* init atoms */ |
| 1527 | wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); | 1508 | wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
