JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
moved all tile()-related stuff into tile.c which is included from config.def.h, the...
[dwm.git] / tile.c
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 }