JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
s/tilegeom/updatetilegeom/
[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 tileresize(Client *c, int x, int y, int w, int h);
8 void updatetilegeom(void);
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 tileresize(Client *c, int x, int y, int w, int h) {
69         resize(c, x, y, w, h, RESIZEHINTS);
70         if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
71                 /* client doesn't accept size constraints */
72                 resize(c, x, y, w, h, False);
73 }
74
75 void
76 zoom(const char *arg) {
77         Client *c = sel;
78
79         if(c == nextunfloating(clients))
80                 if(!c || !(c = nextunfloating(c->next)))
81                         return;
82         if(lt->arrange == tile && !sel->isfloating) {
83                 detach(c);
84                 attach(c);
85                 focus(c);
86         }
87         arrange();
88 }
89
90 void
91 updatetilegeom(void) {
92         /* master area geometry */
93         mx = wx;
94         my = wy;
95         mw = mfact * ww;
96         mh = wh;
97
98         /* tile area geometry */
99         tx = mx + mw;
100         ty = wy;
101         tw = ww - mw;
102         th = wh;
103 }