summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c110
1 files changed, 9 insertions, 101 deletions
diff --git a/dwm.c b/dwm.c
index 25bc926..d9e1c7f 100644
--- a/dwm.c
+++ b/dwm.c
@@ -97,6 +97,7 @@ typedef struct {
97typedef struct { 97typedef 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
102typedef struct { 103typedef struct {
@@ -152,7 +153,7 @@ void mappingnotify(XEvent *e);
152void maprequest(XEvent *e); 153void maprequest(XEvent *e);
153void monocle(void); 154void monocle(void);
154void movemouse(Client *c); 155void movemouse(Client *c);
155Client *nexttiled(Client *c); 156Client *nextunfloating(Client *c);
156void propertynotify(XEvent *e); 157void propertynotify(XEvent *e);
157void quit(const char *arg); 158void quit(const char *arg);
158void resize(Client *c, int x, int y, int w, int h, Bool sizehints); 159void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
@@ -161,14 +162,11 @@ void restack(void);
161void run(void); 162void run(void);
162void scan(void); 163void scan(void);
163void setclientstate(Client *c, long state); 164void setclientstate(Client *c, long state);
164void setmfact(const char *arg);
165void setup(void); 165void setup(void);
166void spawn(const char *arg); 166void spawn(const char *arg);
167void tag(const char *arg); 167void tag(const char *arg);
168unsigned int textnw(const char *text, unsigned int len); 168unsigned int textnw(const char *text, unsigned int len);
169unsigned int textw(const char *text); 169unsigned int textw(const char *text);
170void tileresize(Client *c, int x, int y, int w, int h);
171void tile(void);
172void togglefloating(const char *arg); 170void togglefloating(const char *arg);
173void togglelayout(const char *arg); 171void togglelayout(const char *arg);
174void toggletag(const char *arg); 172void toggletag(const char *arg);
@@ -192,9 +190,8 @@ void zoom(const char *arg);
192char stext[256]; 190char stext[256];
193int screen, sx, sy, sw, sh; 191int screen, sx, sy, sw, sh;
194int (*xerrorxlib)(Display *, XErrorEvent *); 192int (*xerrorxlib)(Display *, XErrorEvent *);
195int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh; 193int bx, by, bw, bh, blw, wx, wy, ww, wh;
196int seltags = 0; 194int seltags = 0;
197double mfact;
198unsigned int numlockmask = 0; 195unsigned int numlockmask = 0;
199void (*handler[LASTEvent]) (XEvent *) = { 196void (*handler[LASTEvent]) (XEvent *) = {
200 [ButtonPress] = buttonpress, 197 [ButtonPress] = buttonpress,
@@ -1072,7 +1069,7 @@ movemouse(Client *c) {
1072} 1069}
1073 1070
1074Client * 1071Client *
1075nexttiled(Client *c) { 1072nextunfloating(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 */
1341void
1342setmfact(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
1361void 1337void
1362setup(void) { 1338setup(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
1496void 1471void
1497tileresize(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
1504void
1505tile(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
1541void
1542togglefloating(const char *arg) { 1472togglefloating(const char *arg) {
1543 if(!sel) 1473 if(!sel)
1544 return; 1474 return;
@@ -1646,6 +1576,7 @@ updatebar(void) {
1646 1576
1647void 1577void
1648updategeom(void) { 1578updategeom(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
1674void 1598void
@@ -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 */
1793void
1794zoom(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
1808int 1716int
1809main(int argc, char *argv[]) { 1717main(int argc, char *argv[]) {
1810 if(argc == 2 && !strcmp("-v", argv[1])) 1718 if(argc == 2 && !strcmp("-v", argv[1]))