6 unsigned int blw = 0; |
6 unsigned int blw = 0; |
7 Layout *lt = NULL; |
7 Layout *lt = NULL; |
8 |
8 |
9 /* static */ |
9 /* static */ |
10 |
10 |
11 static double hratio = HRATIO; |
|
12 static double vratio = VRATIO; |
|
13 static unsigned int nlayouts = 0; |
11 static unsigned int nlayouts = 0; |
14 static unsigned int nmaster = NMASTER; |
|
15 |
|
16 static double /* simple pow() */ |
|
17 spow(double x, double y) |
|
18 { |
|
19 if(y == 0) |
|
20 return 1; |
|
21 while(--y) |
|
22 x *= x; |
|
23 return x; |
|
24 } |
|
25 |
|
26 static void |
|
27 tile(void) { |
|
28 Bool mmaxtile = False, smaxtile = False; /* fallback tiling */ |
|
29 double mscale = 0, sscale = 0, sum = 0; |
|
30 unsigned int i, n, nx, ny, nw, nh, mw, tw; |
|
31 Client *c; |
|
32 |
|
33 /* preparation */ |
|
34 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) |
|
35 n++; |
|
36 nx = wax; |
|
37 ny = way; |
|
38 mw = (n <= nmaster) ? waw : waw / (1 + hratio); |
|
39 tw = waw - mw; |
|
40 if(n > 0) { |
|
41 if(n <= nmaster) { |
|
42 for(i = 0; i < n; i++) |
|
43 sum += spow(vratio, i); |
|
44 mscale = wah / sum; |
|
45 if(vratio >= 1) |
|
46 mmaxtile = bh > mscale; |
|
47 else |
|
48 mmaxtile = bh > (mscale * spow(vratio, n - 1)); |
|
49 } |
|
50 else { |
|
51 for(i = 0; i < nmaster; i++) |
|
52 sum += spow(vratio, i); |
|
53 mscale = wah / sum; |
|
54 for(sum = 0, i = 0; i < (n - nmaster); i++) |
|
55 sum += spow(vratio, i); |
|
56 sscale = wah / sum; |
|
57 if(vratio >= 1) { |
|
58 mmaxtile = bh > mscale; |
|
59 smaxtile = bh > sscale; |
|
60 } |
|
61 else { |
|
62 mmaxtile = bh > (mscale * spow(vratio, nmaster - 1)); |
|
63 smaxtile = bh > (sscale * spow(vratio, n - nmaster - 1)); |
|
64 } |
|
65 } |
|
66 } |
|
67 /* tiling */ |
|
68 for(i = 0, c = clients; c; c = c->next) |
|
69 if(isvisible(c)) { |
|
70 unban(c); |
|
71 if(c->isfloating) |
|
72 continue; |
|
73 c->ismax = False; |
|
74 if(i < nmaster) { /* master window */ |
|
75 nw = mw - 2 * c->border; |
|
76 if(mmaxtile) { |
|
77 ny = way; |
|
78 nh = wah - 2 * c->border; |
|
79 } |
|
80 else if(i + 1 == (n < nmaster ? n : nmaster)) |
|
81 nh = (way + wah) - ny - 2 * c->border; |
|
82 else |
|
83 nh = (mscale * spow(vratio, i)) - 2 * c->border; |
|
84 } |
|
85 else { /* tile window */ |
|
86 nw = tw - 2 * c->border; |
|
87 if(i == nmaster) { |
|
88 ny = way; |
|
89 nx = wax + mw; |
|
90 } |
|
91 if(smaxtile) { |
|
92 ny = way; |
|
93 nh = wah - 2 * c->border; |
|
94 } |
|
95 else if(i + 1 == n) |
|
96 nh = (way + wah) - ny - 2 * c->border; |
|
97 else |
|
98 nh = (sscale * spow(vratio, i - nmaster)) - 2 * c->border; |
|
99 } |
|
100 resize(c, nx, ny, nw, nh, False); |
|
101 ny += nh; |
|
102 i++; |
|
103 } |
|
104 else |
|
105 ban(c); |
|
106 focus(NULL); |
|
107 restack(); |
|
108 } |
|
109 |
12 |
110 LAYOUTS |
13 LAYOUTS |
111 |
14 |
112 static void |
|
113 incratio(const char *arg, double *ratio, double def) { |
|
114 double delta; |
|
115 |
|
116 if(lt->arrange != tile) |
|
117 return; |
|
118 if(!arg) |
|
119 *ratio = def; |
|
120 else { |
|
121 if(1 == sscanf(arg, "%lf", &delta)) { |
|
122 if(delta + (*ratio) < .1 || delta + (*ratio) > 1.9) |
|
123 return; |
|
124 *ratio += delta; |
|
125 } |
|
126 } |
|
127 lt->arrange(); |
|
128 } |
|
129 |
|
130 /* extern */ |
15 /* extern */ |
131 |
16 |
132 void |
17 void |
133 floating(void) { |
18 floating(const char *arg) { |
134 Client *c; |
19 Client *c; |
|
20 |
|
21 if(lt->arrange != floating) |
|
22 return; |
135 |
23 |
136 for(c = clients; c; c = c->next) |
24 for(c = clients; c; c = c->next) |
137 if(isvisible(c)) { |
25 if(isvisible(c)) { |
138 unban(c); |
26 unban(c); |
139 resize(c, c->x, c->y, c->w, c->h, True); |
27 resize(c, c->x, c->y, c->w, c->h, True); |
259 if(i < 0 || i >= nlayouts) |
118 if(i < 0 || i >= nlayouts) |
260 return; |
119 return; |
261 lt = &layout[i]; |
120 lt = &layout[i]; |
262 } |
121 } |
263 if(sel) |
122 if(sel) |
264 lt->arrange(); |
123 lt->arrange(NULL); |
265 else |
124 else |
266 drawstatus(); |
125 drawstatus(); |
|
126 } |
|
127 |
|
128 void |
|
129 tile(const char *arg) { |
|
130 static double master = MASTER; |
|
131 double delta; |
|
132 unsigned int i, n, nx, ny, nw, nh, mw, th; |
|
133 Client *c; |
|
134 |
|
135 if(lt->arrange != tile) |
|
136 return; |
|
137 |
|
138 /* arg handling, manipulate master */ |
|
139 if(arg && (1 == sscanf(arg, "%lf", &delta))) { |
|
140 if(delta + master > 0.1 && delta + master < 0.9) |
|
141 master += delta; |
|
142 } |
|
143 |
|
144 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) |
|
145 n++; |
|
146 |
|
147 /* window geoms */ |
|
148 mw = (n == 1) ? waw : master * waw; |
|
149 th = (n > 1) ? wah / (n - 1) : 0; |
|
150 if(n > 1 && th < bh) |
|
151 th = wah; |
|
152 |
|
153 nx = wax; |
|
154 ny = way; |
|
155 for(i = 0, c = clients; c; c = c->next) |
|
156 if(isvisible(c)) { |
|
157 unban(c); |
|
158 if(c->isfloating) |
|
159 continue; |
|
160 c->ismax = False; |
|
161 if(i == 0) { /* master */ |
|
162 nw = mw - 2 * c->border; |
|
163 nh = wah - 2 * c->border; |
|
164 } |
|
165 else { /* tile window */ |
|
166 if(i == 1) { |
|
167 ny = way; |
|
168 nx += mw; |
|
169 } |
|
170 nw = waw - mw - 2 * c->border; |
|
171 if(i + 1 == n) /* remainder */ |
|
172 nh = (way + wah) - ny - 2 * c->border; |
|
173 else |
|
174 nh = th - 2 * c->border; |
|
175 } |
|
176 resize(c, nx, ny, nw, nh, False); |
|
177 if(n > 1 && th != wah) |
|
178 ny += nh; |
|
179 i++; |
|
180 } |
|
181 else |
|
182 ban(c); |
|
183 focus(NULL); |
|
184 restack(); |
267 } |
185 } |
268 |
186 |
269 void |
187 void |
270 togglebar(const char *arg) { |
188 togglebar(const char *arg) { |
271 if(bpos == BarOff) |
189 if(bpos == BarOff) |
272 bpos = (BARPOS == BarOff) ? BarTop : BARPOS; |
190 bpos = (BARPOS == BarOff) ? BarTop : BARPOS; |
273 else |
191 else |
274 bpos = BarOff; |
192 bpos = BarOff; |
275 updatebarpos(); |
193 updatebarpos(); |
276 lt->arrange(); |
194 lt->arrange(NULL); |
277 } |
195 } |
278 |
196 |
279 void |
197 void |
280 togglemax(const char *arg) { |
198 togglemax(const char *arg) { |
281 XEvent ev; |
199 XEvent ev; |