diff options
| -rw-r--r-- | config.def.h | 14 | ||||
| -rw-r--r-- | dwm.c | 110 | ||||
| -rw-r--r-- | tile.c | 103 |
3 files changed, 119 insertions, 108 deletions
diff --git a/config.def.h b/config.def.h index 8bd6b69..f35769c 100644 --- a/config.def.h +++ b/config.def.h | |||
| @@ -9,6 +9,7 @@ | |||
| 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 SNAP 32 /* snap pixel */ | ||
| 12 | 13 | ||
| 13 | /* tagging */ | 14 | /* tagging */ |
| 14 | const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; | 15 | const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; |
| @@ -19,15 +20,14 @@ Rule rules[] = { | |||
| 19 | }; | 20 | }; |
| 20 | 21 | ||
| 21 | /* layout(s) */ | 22 | /* layout(s) */ |
| 22 | #define MFACT 0.55 /* master factor [0.1 .. 0.9] */ | ||
| 23 | #define RESIZEHINTS True /* False - respect size hints in tiled resizals */ | 23 | #define RESIZEHINTS True /* False - respect size hints in tiled resizals */ |
| 24 | #define SNAP 32 /* snap pixel */ | 24 | #define MFACT 0.55 /* master factor [0.1 .. 0.9] */ |
| 25 | 25 | #include "tile.c" | |
| 26 | Layout layouts[] = { | 26 | Layout layouts[] = { |
| 27 | /* symbol function */ | 27 | /* symbol arrange geom */ |
| 28 | { "[]=", tile }, /* first entry is default */ | 28 | { "[]=", tile, tilegeom }, /* first entry is default */ |
| 29 | { "><>", NULL }, /* no layout function means floating behavior */ | 29 | { "><>", NULL, }, /* no layout function means floating behavior */ |
| 30 | { "<M>", monocle }, /* TODO: remove this */ | 30 | { "<M>", monocle, NULL }, /* TODO: remove this */ |
| 31 | }; | 31 | }; |
| 32 | 32 | ||
| 33 | /* key definitions */ | 33 | /* key definitions */ |
| @@ -97,6 +97,7 @@ typedef struct { | |||
| 97 | typedef struct { | 97 | typedef struct { |
| 98 | const char *symbol; | 98 | const char *symbol; |
| 99 | void (*arrange)(void); | 99 | void (*arrange)(void); |
| 100 | void (*updategeom)(void); | ||
| 100 | } Layout; | 101 | } Layout; |
| 101 | 102 | ||
| 102 | typedef struct { | 103 | typedef struct { |
| @@ -152,7 +153,7 @@ void mappingnotify(XEvent *e); | |||
| 152 | void maprequest(XEvent *e); | 153 | void maprequest(XEvent *e); |
| 153 | void monocle(void); | 154 | void monocle(void); |
| 154 | void movemouse(Client *c); | 155 | void movemouse(Client *c); |
| 155 | Client *nexttiled(Client *c); | 156 | Client *nextunfloating(Client *c); |
| 156 | void propertynotify(XEvent *e); | 157 | void propertynotify(XEvent *e); |
| 157 | void quit(const char *arg); | 158 | void quit(const char *arg); |
| 158 | void resize(Client *c, int x, int y, int w, int h, Bool sizehints); | 159 | void resize(Client *c, int x, int y, int w, int h, Bool sizehints); |
| @@ -161,14 +162,11 @@ void restack(void); | |||
| 161 | void run(void); | 162 | void run(void); |
| 162 | void scan(void); | 163 | void scan(void); |
| 163 | void setclientstate(Client *c, long state); | 164 | void setclientstate(Client *c, long state); |
| 164 | void setmfact(const char *arg); | ||
| 165 | void setup(void); | 165 | void setup(void); |
| 166 | void spawn(const char *arg); | 166 | void spawn(const char *arg); |
| 167 | void tag(const char *arg); | 167 | void tag(const char *arg); |
| 168 | unsigned int textnw(const char *text, unsigned int len); | 168 | unsigned int textnw(const char *text, unsigned int len); |
| 169 | unsigned int textw(const char *text); | 169 | unsigned int textw(const char *text); |
| 170 | void tileresize(Client *c, int x, int y, int w, int h); | ||
| 171 | void tile(void); | ||
| 172 | void togglefloating(const char *arg); | 170 | void togglefloating(const char *arg); |
| 173 | void togglelayout(const char *arg); | 171 | void togglelayout(const char *arg); |
| 174 | void toggletag(const char *arg); | 172 | void toggletag(const char *arg); |
| @@ -192,9 +190,8 @@ void zoom(const char *arg); | |||
| 192 | char stext[256]; | 190 | char stext[256]; |
| 193 | int screen, sx, sy, sw, sh; | 191 | int screen, sx, sy, sw, sh; |
| 194 | int (*xerrorxlib)(Display *, XErrorEvent *); | 192 | int (*xerrorxlib)(Display *, XErrorEvent *); |
| 195 | int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh; | 193 | int bx, by, bw, bh, blw, wx, wy, ww, wh; |
| 196 | int seltags = 0; | 194 | int seltags = 0; |
| 197 | double mfact; | ||
| 198 | unsigned int numlockmask = 0; | 195 | unsigned int numlockmask = 0; |
| 199 | void (*handler[LASTEvent]) (XEvent *) = { | 196 | void (*handler[LASTEvent]) (XEvent *) = { |
| 200 | [ButtonPress] = buttonpress, | 197 | [ButtonPress] = buttonpress, |
| @@ -1072,7 +1069,7 @@ movemouse(Client *c) { | |||
| 1072 | } | 1069 | } |
| 1073 | 1070 | ||
| 1074 | Client * | 1071 | Client * |
| 1075 | nexttiled(Client *c) { | 1072 | nextunfloating(Client *c) { |
| 1076 | for(; c && (c->isfloating || !isvisible(c, NULL)); c = c->next); | 1073 | for(; c && (c->isfloating || !isvisible(c, NULL)); c = c->next); |
| 1077 | return c; | 1074 | return c; |
| 1078 | } | 1075 | } |
| @@ -1337,27 +1334,6 @@ setclientstate(Client *c, long state) { | |||
| 1337 | PropModeReplace, (unsigned char *)data, 2); | 1334 | PropModeReplace, (unsigned char *)data, 2); |
| 1338 | } | 1335 | } |
| 1339 | 1336 | ||
| 1340 | /* TODO: move this into tile.c */ | ||
| 1341 | void | ||
| 1342 | setmfact(const char *arg) { | ||
| 1343 | double d; | ||
| 1344 | |||
| 1345 | if(!lt->arrange) /* TODO: check this against the actual tile() function */ | ||
| 1346 | return; | ||
| 1347 | if(!arg) | ||
| 1348 | mfact = MFACT; | ||
| 1349 | else { | ||
| 1350 | d = strtod(arg, NULL); | ||
| 1351 | if(arg[0] == '-' || arg[0] == '+') | ||
| 1352 | d += mfact; | ||
| 1353 | if(d < 0.1 || d > 0.9) | ||
| 1354 | return; | ||
| 1355 | mfact = d; | ||
| 1356 | } | ||
| 1357 | updategeom(); | ||
| 1358 | arrange(); | ||
| 1359 | } | ||
| 1360 | |||
| 1361 | void | 1337 | void |
| 1362 | setup(void) { | 1338 | setup(void) { |
| 1363 | unsigned int i, w; | 1339 | unsigned int i, w; |
| @@ -1372,7 +1348,6 @@ setup(void) { | |||
| 1372 | sw = DisplayWidth(dpy, screen); | 1348 | sw = DisplayWidth(dpy, screen); |
| 1373 | sh = DisplayHeight(dpy, screen); | 1349 | sh = DisplayHeight(dpy, screen); |
| 1374 | bh = dc.font.height + 2; | 1350 | bh = dc.font.height + 2; |
| 1375 | mfact = MFACT; | ||
| 1376 | updategeom(); | 1351 | updategeom(); |
| 1377 | 1352 | ||
| 1378 | /* init atoms */ | 1353 | /* init atoms */ |
| @@ -1494,51 +1469,6 @@ textw(const char *text) { | |||
| 1494 | } | 1469 | } |
| 1495 | 1470 | ||
| 1496 | void | 1471 | void |
| 1497 | tileresize(Client *c, int x, int y, int w, int h) { | ||
| 1498 | resize(c, x, y, w, h, RESIZEHINTS); | ||
| 1499 | if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w))) | ||
| 1500 | /* client doesn't accept size constraints */ | ||
| 1501 | resize(c, x, y, w, h, False); | ||
| 1502 | } | ||
| 1503 | |||
| 1504 | void | ||
| 1505 | tile(void) { | ||
| 1506 | int y, h; | ||
| 1507 | unsigned int i, n; | ||
| 1508 | Client *c; | ||
| 1509 | |||
| 1510 | for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++); | ||
| 1511 | if(n == 0) | ||
| 1512 | return; | ||
| 1513 | |||
| 1514 | /* master */ | ||
| 1515 | c = nexttiled(clients); | ||
| 1516 | |||
| 1517 | if(n == 1) | ||
| 1518 | tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw); | ||
| 1519 | else | ||
| 1520 | tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw); | ||
| 1521 | |||
| 1522 | if(--n == 0) | ||
| 1523 | return; | ||
| 1524 | |||
| 1525 | /* tile stack */ | ||
| 1526 | y = ty; | ||
| 1527 | h = th / n; | ||
| 1528 | if(h < bh) | ||
| 1529 | h = th; | ||
| 1530 | |||
| 1531 | for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { | ||
| 1532 | if(i + 1 == n) /* remainder */ | ||
| 1533 | tileresize(c, tx, y, tw - 2 * c->bw, (ty + th) - y - 2 * c->bw); | ||
| 1534 | else | ||
| 1535 | tileresize(c, tx, y, tw - 2 * c->bw, h - 2 * c->bw); | ||
| 1536 | if(h != th) | ||
| 1537 | y = c->y + c->h + 2 * c->bw; | ||
| 1538 | } | ||
| 1539 | } | ||
| 1540 | |||
| 1541 | void | ||
| 1542 | togglefloating(const char *arg) { | 1472 | togglefloating(const char *arg) { |
| 1543 | if(!sel) | 1473 | if(!sel) |
| 1544 | return; | 1474 | return; |
| @@ -1646,6 +1576,7 @@ updatebar(void) { | |||
| 1646 | 1576 | ||
| 1647 | void | 1577 | void |
| 1648 | updategeom(void) { | 1578 | updategeom(void) { |
| 1579 | unsigned int i; | ||
| 1649 | 1580 | ||
| 1650 | /* bar geometry */ | 1581 | /* bar geometry */ |
| 1651 | bx = 0; | 1582 | bx = 0; |
| @@ -1658,17 +1589,10 @@ updategeom(void) { | |||
| 1658 | ww = sw; | 1589 | ww = sw; |
| 1659 | wh = sh - bh; | 1590 | wh = sh - bh; |
| 1660 | 1591 | ||
| 1661 | /* master area geometry */ | 1592 | /* update layout geometries */ |
| 1662 | mx = wx; | 1593 | for(i = 0; i < LENGTH(layouts); i++) |
| 1663 | my = wy; | 1594 | if(layouts[i].updategeom) |
| 1664 | mw = mfact * ww; | 1595 | layouts[i].updategeom(); |
| 1665 | mh = wh; | ||
| 1666 | |||
| 1667 | /* tile area geometry */ | ||
| 1668 | tx = mx + mw; | ||
| 1669 | ty = wy; | ||
| 1670 | tw = ww - mw; | ||
| 1671 | th = wh; | ||
| 1672 | } | 1596 | } |
| 1673 | 1597 | ||
| 1674 | void | 1598 | void |
| @@ -1789,22 +1713,6 @@ xerrorstart(Display *dpy, XErrorEvent *ee) { | |||
| 1789 | return -1; | 1713 | return -1; |
| 1790 | } | 1714 | } |
| 1791 | 1715 | ||
| 1792 | /* TODO: move this into tile.c */ | ||
| 1793 | void | ||
| 1794 | zoom(const char *arg) { | ||
| 1795 | Client *c = sel; | ||
| 1796 | |||
| 1797 | if(c == nexttiled(clients)) | ||
| 1798 | if(!c || !(c = nexttiled(c->next))) | ||
| 1799 | return; | ||
| 1800 | if(lt->arrange && !sel->isfloating) { /* TODO: check this against tile() */ | ||
| 1801 | detach(c); | ||
| 1802 | attach(c); | ||
| 1803 | focus(c); | ||
| 1804 | } | ||
| 1805 | arrange(); | ||
| 1806 | } | ||
| 1807 | |||
| 1808 | int | 1716 | int |
| 1809 | main(int argc, char *argv[]) { | 1717 | main(int argc, char *argv[]) { |
| 1810 | if(argc == 2 && !strcmp("-v", argv[1])) | 1718 | if(argc == 2 && !strcmp("-v", argv[1])) |
| @@ -0,0 +1,103 @@ | |||
| 1 | /* See LICENSE file for copyright and license details. */ | ||
| 2 | double mfact = MFACT; | ||
| 3 | int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh; | ||
| 4 | |||
| 5 | void setmfact(const char *arg); | ||
| 6 | void tile(void); | ||
| 7 | void tilegeom(void); | ||
| 8 | void tileresize(Client *c, int x, int y, int w, int h); | ||
| 9 | |||
| 10 | void | ||
| 11 | setmfact(const char *arg) { | ||
| 12 | double d; | ||
| 13 | |||
| 14 | if(lt->arrange != tile) | ||
| 15 | return; | ||
| 16 | if(!arg) | ||
| 17 | mfact = MFACT; | ||
| 18 | else { | ||
| 19 | d = strtod(arg, NULL); | ||
| 20 | if(arg[0] == '-' || arg[0] == '+') | ||
| 21 | d += mfact; | ||
| 22 | if(d < 0.1 || d > 0.9) | ||
| 23 | return; | ||
| 24 | mfact = d; | ||
| 25 | } | ||
| 26 | updategeom(); | ||
| 27 | arrange(); | ||
| 28 | } | ||
| 29 | |||
| 30 | void | ||
| 31 | tile(void) { | ||
| 32 | int y, h; | ||
| 33 | unsigned int i, n; | ||
| 34 | Client *c; | ||
| 35 | |||
| 36 | for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++); | ||
| 37 | if(n == 0) | ||
| 38 | return; | ||
| 39 | |||
| 40 | /* master */ | ||
| 41 | c = nextunfloating(clients); | ||
| 42 | |||
| 43 | if(n == 1) | ||
| 44 | tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw); | ||
| 45 | else | ||
| 46 | tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw); | ||
| 47 | |||
| 48 | if(--n == 0) | ||
| 49 | return; | ||
| 50 | |||
| 51 | /* tile stack */ | ||
| 52 | y = ty; | ||
| 53 | h = th / n; | ||
| 54 | if(h < bh) | ||
| 55 | h = th; | ||
| 56 | |||
| 57 | for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) { | ||
| 58 | if(i + 1 == n) /* remainder */ | ||
| 59 | tileresize(c, tx, y, tw - 2 * c->bw, (ty + th) - y - 2 * c->bw); | ||
| 60 | else | ||
| 61 | tileresize(c, tx, y, tw - 2 * c->bw, h - 2 * c->bw); | ||
| 62 | if(h != th) | ||
| 63 | y = c->y + c->h + 2 * c->bw; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | void | ||
| 68 | tilegeom(void) { | ||
| 69 | /* master area geometry */ | ||
| 70 | mx = wx; | ||
| 71 | my = wy; | ||
| 72 | mw = mfact * ww; | ||
| 73 | mh = wh; | ||
| 74 | |||
| 75 | /* tile area geometry */ | ||
| 76 | tx = mx + mw; | ||
| 77 | ty = wy; | ||
| 78 | tw = ww - mw; | ||
| 79 | th = wh; | ||
| 80 | } | ||
| 81 | |||
| 82 | void | ||
| 83 | tileresize(Client *c, int x, int y, int w, int h) { | ||
| 84 | resize(c, x, y, w, h, RESIZEHINTS); | ||
| 85 | if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w))) | ||
| 86 | /* client doesn't accept size constraints */ | ||
| 87 | resize(c, x, y, w, h, False); | ||
| 88 | } | ||
| 89 | |||
| 90 | void | ||
| 91 | zoom(const char *arg) { | ||
| 92 | Client *c = sel; | ||
| 93 | |||
| 94 | if(c == nextunfloating(clients)) | ||
| 95 | if(!c || !(c = nextunfloating(c->next))) | ||
| 96 | return; | ||
| 97 | if(lt->arrange == tile && !sel->isfloating) { | ||
| 98 | detach(c); | ||
| 99 | attach(c); | ||
| 100 | focus(c); | ||
| 101 | } | ||
| 102 | arrange(); | ||
| 103 | } | ||
