merged tile.c again into dwm.c
822101dd
3 file(s) · +101 −106
| 25 | 25 | double mfact = 0.55; |
|
| 26 | 26 | Bool resizehints = True; /* False means respect size hints in tiled resizals */ |
|
| 27 | 27 | ||
| 28 | - | #include "tile.c" |
|
| 29 | - | ||
| 30 | 28 | Layout layouts[] = { |
|
| 31 | 29 | /* symbol arrange geom */ |
|
| 32 | 30 | { "[]=", tile, updatetilegeom }, /* first entry is default */ |
|
| 33 | - | { "><>", NULL, }, /* no layout function means floating behavior */ |
|
| 31 | + | { "><>", NULL, NULL }, /* no layout function means floating behavior */ |
|
| 34 | 32 | }; |
|
| 35 | 33 | ||
| 36 | 34 | /* key definitions */ |
| 53 | 53 | #define MOUSEMASK (BUTTONMASK|PointerMotionMask) |
|
| 54 | 54 | ||
| 55 | 55 | /* enums */ |
|
| 56 | - | enum { BarTop, BarBot, BarOff, BarLast }; /* bar appearance */ |
|
| 57 | 56 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
|
| 58 | 57 | enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
|
| 59 | 58 | enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
|
| 165 | 164 | void run(void); |
|
| 166 | 165 | void scan(void); |
|
| 167 | 166 | void setclientstate(Client *c, long state); |
|
| 167 | + | void setmfact(const char *arg); |
|
| 168 | 168 | void setup(void); |
|
| 169 | 169 | void spawn(const char *arg); |
|
| 170 | 170 | void tag(const char *arg); |
|
| 171 | 171 | unsigned int textnw(const char *text, unsigned int len); |
|
| 172 | 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 | 175 | void togglebar(const char *arg); |
|
| 174 | 176 | void togglefloating(const char *arg); |
|
| 175 | 177 | void togglelayout(const char *arg); |
|
| 181 | 183 | void updatebar(void); |
|
| 182 | 184 | void updategeom(void); |
|
| 183 | 185 | void updatesizehints(Client *c); |
|
| 186 | + | void updatetilegeom(void); |
|
| 184 | 187 | void updatetitle(Client *c); |
|
| 185 | 188 | void updatewmhints(Client *c); |
|
| 186 | 189 | void view(const char *arg); |
|
| 194 | 197 | char stext[256]; |
|
| 195 | 198 | int screen, sx, sy, sw, sh; |
|
| 196 | 199 | int bx, by, bw, bh, blw, wx, wy, ww, wh; |
|
| 200 | + | int mx, my, mw, mh, tx, ty, tw, th; |
|
| 197 | 201 | int seltags = 0; |
|
| 198 | 202 | int (*xerrorxlib)(Display *, XErrorEvent *); |
|
| 199 | 203 | unsigned int numlockmask = 0; |
|
| 1333 | 1337 | } |
|
| 1334 | 1338 | ||
| 1335 | 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 | 1358 | setup(void) { |
|
| 1337 | 1359 | unsigned int i, w; |
|
| 1338 | 1360 | XSetWindowAttributes wa; |
|
| 1467 | 1489 | } |
|
| 1468 | 1490 | ||
| 1469 | 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 | 1539 | togglebar(const char *arg) { |
|
| 1471 | 1540 | showbar = !showbar; |
|
| 1472 | 1541 | updategeom(); |
|
| 1668 | 1737 | } |
|
| 1669 | 1738 | ||
| 1670 | 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 | 1755 | updatetitle(Client *c) { |
|
| 1672 | 1756 | if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) |
|
| 1673 | 1757 | gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name); |
|
| 1731 | 1815 | xerrorstart(Display *dpy, XErrorEvent *ee) { |
|
| 1732 | 1816 | otherwm = True; |
|
| 1733 | 1817 | return -1; |
|
| 1818 | + | } |
|
| 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(); |
|
| 1734 | 1833 | } |
|
| 1735 | 1834 | ||
| 1736 | 1835 | int |
|
| 1 | - | /* See LICENSE file for copyright and license details. */ |
|
| 2 | - | int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh; |
|
| 3 | - | ||
| 4 | - | void setmfact(const char *arg); |
|
| 5 | - | void tile(void); |
|
| 6 | - | void tileresize(Client *c, int x, int y, int w, int h); |
|
| 7 | - | void updatetilegeom(void); |
|
| 8 | - | ||
| 9 | - | void |
|
| 10 | - | setmfact(const char *arg) { |
|
| 11 | - | double d; |
|
| 12 | - | ||
| 13 | - | if(!arg || lt->arrange != tile) |
|
| 14 | - | return; |
|
| 15 | - | else { |
|
| 16 | - | d = strtod(arg, NULL); |
|
| 17 | - | if(arg[0] == '-' || arg[0] == '+') |
|
| 18 | - | d += mfact; |
|
| 19 | - | if(d < 0.1 || d > 0.9) |
|
| 20 | - | return; |
|
| 21 | - | mfact = d; |
|
| 22 | - | } |
|
| 23 | - | updatetilegeom(); |
|
| 24 | - | arrange(); |
|
| 25 | - | } |
|
| 26 | - | ||
| 27 | - | void |
|
| 28 | - | tile(void) { |
|
| 29 | - | int x, y, h, w; |
|
| 30 | - | unsigned int i, n; |
|
| 31 | - | Client *c; |
|
| 32 | - | ||
| 33 | - | for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++); |
|
| 34 | - | if(n == 0) |
|
| 35 | - | return; |
|
| 36 | - | ||
| 37 | - | /* master */ |
|
| 38 | - | c = nextunfloating(clients); |
|
| 39 | - | ||
| 40 | - | if(n == 1) |
|
| 41 | - | tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw); |
|
| 42 | - | else |
|
| 43 | - | tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw); |
|
| 44 | - | ||
| 45 | - | if(--n == 0) |
|
| 46 | - | return; |
|
| 47 | - | ||
| 48 | - | /* tile stack */ |
|
| 49 | - | x = (tx > c->x + c->w) ? c->x + c->w + 2 * c->bw : tw; |
|
| 50 | - | y = ty; |
|
| 51 | - | w = (tx > c->x + c->w) ? wx + ww - x : tw; |
|
| 52 | - | h = th / n; |
|
| 53 | - | if(h < bh) |
|
| 54 | - | h = th; |
|
| 55 | - | ||
| 56 | - | for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) { |
|
| 57 | - | if(i + 1 == n) /* remainder */ |
|
| 58 | - | tileresize(c, x, y, w - 2 * c->bw, (ty + th) - y - 2 * c->bw); |
|
| 59 | - | else |
|
| 60 | - | tileresize(c, x, y, w - 2 * c->bw, h - 2 * c->bw); |
|
| 61 | - | if(h != th) |
|
| 62 | - | y = c->y + c->h + 2 * c->bw; |
|
| 63 | - | } |
|
| 64 | - | } |
|
| 65 | - | ||
| 66 | - | void |
|
| 67 | - | tileresize(Client *c, int x, int y, int w, int h) { |
|
| 68 | - | resize(c, x, y, w, h, resizehints); |
|
| 69 | - | if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w))) |
|
| 70 | - | /* client doesn't accept size constraints */ |
|
| 71 | - | resize(c, x, y, w, h, False); |
|
| 72 | - | } |
|
| 73 | - | ||
| 74 | - | void |
|
| 75 | - | zoom(const char *arg) { |
|
| 76 | - | Client *c = sel; |
|
| 77 | - | ||
| 78 | - | if(c == nextunfloating(clients)) |
|
| 79 | - | if(!c || !(c = nextunfloating(c->next))) |
|
| 80 | - | return; |
|
| 81 | - | if(lt->arrange == tile && !sel->isfloating) { |
|
| 82 | - | detach(c); |
|
| 83 | - | attach(c); |
|
| 84 | - | focus(c); |
|
| 85 | - | } |
|
| 86 | - | arrange(); |
|
| 87 | - | } |
|
| 88 | - | ||
| 89 | - | void |
|
| 90 | - | updatetilegeom(void) { |
|
| 91 | - | /* master area geometry */ |
|
| 92 | - | mx = wx; |
|
| 93 | - | my = wy; |
|
| 94 | - | mw = mfact * ww; |
|
| 95 | - | mh = wh; |
|
| 96 | - | ||
| 97 | - | /* tile area geometry */ |
|
| 98 | - | tx = mx + mw; |
|
| 99 | - | ty = wy; |
|
| 100 | - | tw = ww - mw; |
|
| 101 | - | th = wh; |
|
| 102 | - | } |