diff options
Diffstat (limited to 'dwm.c')
| -rw-r--r-- | dwm.c | 110 |
1 files changed, 9 insertions, 101 deletions
| @@ -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])) |
