Xinqi Bao's Git

recent changes, introduced togglebar, changed some defines into variable declarations...
[dwm.git] / tile.c
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 updategeom();
24 arrange();
25 }
26
27 void
28 tile(void) {
29 int y, h;
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 y = ty;
50 h = th / n;
51 if(h < bh)
52 h = th;
53
54 for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) {
55 if(i + 1 == n) /* remainder */
56 tileresize(c, tx, y, tw - 2 * c->bw, (ty + th) - y - 2 * c->bw);
57 else
58 tileresize(c, tx, y, tw - 2 * c->bw, h - 2 * c->bw);
59 if(h != th)
60 y = c->y + c->h + 2 * c->bw;
61 }
62 }
63
64 void
65 tileresize(Client *c, int x, int y, int w, int h) {
66 resize(c, x, y, w, h, resizehints);
67 if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
68 /* client doesn't accept size constraints */
69 resize(c, x, y, w, h, False);
70 }
71
72 void
73 zoom(const char *arg) {
74 Client *c = sel;
75
76 if(c == nextunfloating(clients))
77 if(!c || !(c = nextunfloating(c->next)))
78 return;
79 if(lt->arrange == tile && !sel->isfloating) {
80 detach(c);
81 attach(c);
82 focus(c);
83 }
84 arrange();
85 }
86
87 void
88 updatetilegeom(void) {
89 #ifdef TILEGEOM /* define your own if you are Xinerama user */
90 TILEGEOM
91 #else
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 #endif
104 }