diff options
Diffstat (limited to 'dwm.c')
| -rw-r--r-- | dwm.c | 101 |
1 files changed, 100 insertions, 1 deletions
| @@ -53,7 +53,6 @@ | |||
| 53 | #define MOUSEMASK (BUTTONMASK|PointerMotionMask) | 53 | #define MOUSEMASK (BUTTONMASK|PointerMotionMask) |
| 54 | 54 | ||
| 55 | /* enums */ | 55 | /* enums */ |
| 56 | enum { BarTop, BarBot, BarOff, BarLast }; /* bar appearance */ | ||
| 57 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ | 56 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
| 58 | enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ | 57 | enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
| 59 | enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ | 58 | enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
| @@ -165,11 +164,14 @@ void restack(void); | |||
| 165 | void run(void); | 164 | void run(void); |
| 166 | void scan(void); | 165 | void scan(void); |
| 167 | void setclientstate(Client *c, long state); | 166 | void setclientstate(Client *c, long state); |
| 167 | void setmfact(const char *arg); | ||
| 168 | void setup(void); | 168 | void setup(void); |
| 169 | void spawn(const char *arg); | 169 | void spawn(const char *arg); |
| 170 | void tag(const char *arg); | 170 | void tag(const char *arg); |
| 171 | unsigned int textnw(const char *text, unsigned int len); | 171 | unsigned int textnw(const char *text, unsigned int len); |
| 172 | unsigned int textw(const char *text); | 172 | unsigned int textw(const char *text); |
| 173 | void tile(void); | ||
| 174 | void tileresize(Client *c, int x, int y, int w, int h); | ||
| 173 | void togglebar(const char *arg); | 175 | void togglebar(const char *arg); |
| 174 | void togglefloating(const char *arg); | 176 | void togglefloating(const char *arg); |
| 175 | void togglelayout(const char *arg); | 177 | void togglelayout(const char *arg); |
| @@ -181,6 +183,7 @@ void unmapnotify(XEvent *e); | |||
| 181 | void updatebar(void); | 183 | void updatebar(void); |
| 182 | void updategeom(void); | 184 | void updategeom(void); |
| 183 | void updatesizehints(Client *c); | 185 | void updatesizehints(Client *c); |
| 186 | void updatetilegeom(void); | ||
| 184 | void updatetitle(Client *c); | 187 | void updatetitle(Client *c); |
| 185 | void updatewmhints(Client *c); | 188 | void updatewmhints(Client *c); |
| 186 | void view(const char *arg); | 189 | void view(const char *arg); |
| @@ -194,6 +197,7 @@ void zoom(const char *arg); | |||
| 194 | char stext[256]; | 197 | char stext[256]; |
| 195 | int screen, sx, sy, sw, sh; | 198 | int screen, sx, sy, sw, sh; |
| 196 | int bx, by, bw, bh, blw, wx, wy, ww, wh; | 199 | int bx, by, bw, bh, blw, wx, wy, ww, wh; |
| 200 | int mx, my, mw, mh, tx, ty, tw, th; | ||
| 197 | int seltags = 0; | 201 | int seltags = 0; |
| 198 | int (*xerrorxlib)(Display *, XErrorEvent *); | 202 | int (*xerrorxlib)(Display *, XErrorEvent *); |
| 199 | unsigned int numlockmask = 0; | 203 | unsigned int numlockmask = 0; |
| @@ -1333,6 +1337,24 @@ setclientstate(Client *c, long state) { | |||
| 1333 | } | 1337 | } |
| 1334 | 1338 | ||
| 1335 | void | 1339 | void |
| 1340 | setmfact(const char *arg) { | ||
| 1341 | double d; | ||
| 1342 | |||
| 1343 | if(!arg || lt->arrange != tile) | ||
| 1344 | return; | ||
| 1345 | else { | ||
| 1346 | d = strtod(arg, NULL); | ||
| 1347 | if(arg[0] == '-' || arg[0] == '+') | ||
| 1348 | d += mfact; | ||
| 1349 | if(d < 0.1 || d > 0.9) | ||
| 1350 | return; | ||
| 1351 | mfact = d; | ||
| 1352 | } | ||
| 1353 | updatetilegeom(); | ||
| 1354 | arrange(); | ||
| 1355 | } | ||
| 1356 | |||
| 1357 | void | ||
| 1336 | setup(void) { | 1358 | setup(void) { |
| 1337 | unsigned int i, w; | 1359 | unsigned int i, w; |
| 1338 | XSetWindowAttributes wa; | 1360 | XSetWindowAttributes wa; |
| @@ -1467,6 +1489,53 @@ textw(const char *text) { | |||
| 1467 | } | 1489 | } |
| 1468 | 1490 | ||
| 1469 | void | 1491 | void |
| 1492 | tile(void) { | ||
| 1493 | int x, y, h, w; | ||
| 1494 | unsigned int i, n; | ||
| 1495 | Client *c; | ||
| 1496 | |||
| 1497 | for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++); | ||
| 1498 | if(n == 0) | ||
| 1499 | return; | ||
| 1500 | |||
| 1501 | /* master */ | ||
| 1502 | c = nextunfloating(clients); | ||
| 1503 | |||
| 1504 | if(n == 1) | ||
| 1505 | tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw); | ||
| 1506 | else | ||
| 1507 | tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw); | ||
| 1508 | |||
| 1509 | if(--n == 0) | ||
| 1510 | return; | ||
| 1511 | |||
| 1512 | /* tile stack */ | ||
| 1513 | x = (tx > c->x + c->w) ? c->x + c->w + 2 * c->bw : tw; | ||
| 1514 | y = ty; | ||
| 1515 | w = (tx > c->x + c->w) ? wx + ww - x : tw; | ||
| 1516 | h = th / n; | ||
| 1517 | if(h < bh) | ||
| 1518 | h = th; | ||
| 1519 | |||
| 1520 | for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) { | ||
| 1521 | if(i + 1 == n) /* remainder */ | ||
| 1522 | tileresize(c, x, y, w - 2 * c->bw, (ty + th) - y - 2 * c->bw); | ||
| 1523 | else | ||
| 1524 | tileresize(c, x, y, w - 2 * c->bw, h - 2 * c->bw); | ||
| 1525 | if(h != th) | ||
| 1526 | y = c->y + c->h + 2 * c->bw; | ||
| 1527 | } | ||
| 1528 | } | ||
| 1529 | |||
| 1530 | void | ||
| 1531 | tileresize(Client *c, int x, int y, int w, int h) { | ||
| 1532 | resize(c, x, y, w, h, resizehints); | ||
| 1533 | if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w))) | ||
| 1534 | /* client doesn't accept size constraints */ | ||
| 1535 | resize(c, x, y, w, h, False); | ||
| 1536 | } | ||
| 1537 | |||
| 1538 | void | ||
| 1470 | togglebar(const char *arg) { | 1539 | togglebar(const char *arg) { |
| 1471 | showbar = !showbar; | 1540 | showbar = !showbar; |
| 1472 | updategeom(); | 1541 | updategeom(); |
| @@ -1668,6 +1737,21 @@ updatesizehints(Client *c) { | |||
| 1668 | } | 1737 | } |
| 1669 | 1738 | ||
| 1670 | void | 1739 | void |
| 1740 | updatetilegeom(void) { | ||
| 1741 | /* master area geometry */ | ||
| 1742 | mx = wx; | ||
| 1743 | my = wy; | ||
| 1744 | mw = mfact * ww; | ||
| 1745 | mh = wh; | ||
| 1746 | |||
| 1747 | /* tile area geometry */ | ||
| 1748 | tx = mx + mw; | ||
| 1749 | ty = wy; | ||
| 1750 | tw = ww - mw; | ||
| 1751 | th = wh; | ||
| 1752 | } | ||
| 1753 | |||
| 1754 | void | ||
| 1671 | updatetitle(Client *c) { | 1755 | updatetitle(Client *c) { |
| 1672 | if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) | 1756 | if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) |
| 1673 | gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name); | 1757 | gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name); |
| @@ -1733,6 +1817,21 @@ xerrorstart(Display *dpy, XErrorEvent *ee) { | |||
| 1733 | return -1; | 1817 | return -1; |
| 1734 | } | 1818 | } |
| 1735 | 1819 | ||
| 1820 | void | ||
| 1821 | zoom(const char *arg) { | ||
| 1822 | Client *c = sel; | ||
| 1823 | |||
| 1824 | if(c == nextunfloating(clients)) | ||
| 1825 | if(!c || !(c = nextunfloating(c->next))) | ||
| 1826 | return; | ||
| 1827 | if(lt->arrange == tile && !sel->isfloating) { | ||
| 1828 | detach(c); | ||
| 1829 | attach(c); | ||
| 1830 | focus(c); | ||
| 1831 | } | ||
| 1832 | arrange(); | ||
| 1833 | } | ||
| 1834 | |||
| 1736 | int | 1835 | int |
| 1737 | main(int argc, char *argv[]) { | 1836 | main(int argc, char *argv[]) { |
| 1738 | if(argc == 2 && !strcmp("-v", argv[1])) | 1837 | if(argc == 2 && !strcmp("-v", argv[1])) |
