1 /* See LICENSE file for copyright and license details. */ |
1 /* See LICENSE file for copyright and license details. */ |
2 #include "dwm.h" |
2 #include "dwm.h" |
|
3 #include <stdio.h> |
3 #include <stdlib.h> |
4 #include <stdlib.h> |
4 |
5 |
5 unsigned int blw = 0; |
6 unsigned int blw = 0; |
6 Layout *lt = NULL; |
7 Layout *lt = NULL; |
7 |
8 |
8 /* static */ |
9 /* static */ |
9 |
10 |
|
11 static double ratio = RATIO; |
10 static unsigned int nlayouts = 0; |
12 static unsigned int nlayouts = 0; |
11 static unsigned int masterw = MASTERWIDTH; |
|
12 static unsigned int nmaster = NMASTER; |
13 static unsigned int nmaster = NMASTER; |
|
14 |
|
15 static double // simple pow() |
|
16 spow(double x, double y) |
|
17 { |
|
18 if(y == 0) |
|
19 return 1; |
|
20 while(--y) |
|
21 x *= x; |
|
22 return x; |
|
23 } |
13 |
24 |
14 static void |
25 static void |
15 tile(void) { |
26 tile(void) { |
16 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; |
27 double mscale = 0, tscale = 0, sum = 0; |
|
28 unsigned int i, n, nx, ny, nw, nh, mw, tw; |
17 Client *c; |
29 Client *c; |
18 |
30 |
19 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) |
31 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) |
20 n++; |
32 n++; |
21 /* window geoms */ |
33 |
22 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); |
34 mw = (n <= nmaster) ? waw : waw / (1 + ratio); |
23 mw = (n > nmaster) ? (waw * masterw) / 1000 : waw; |
|
24 th = (n > nmaster) ? wah / (n - nmaster) : 0; |
|
25 tw = waw - mw; |
35 tw = waw - mw; |
26 |
36 |
|
37 if(n > 0) { |
|
38 if(n < nmaster) { |
|
39 for(i = 0; i < n; i++) |
|
40 sum += spow(ratio, i); |
|
41 mscale = wah / sum; |
|
42 } |
|
43 else { |
|
44 for(i = 0; i < nmaster; i++) |
|
45 sum += spow(ratio, i); |
|
46 mscale = wah / sum; |
|
47 for(sum = 0, i = 0; i < (n - nmaster); i++) |
|
48 sum += spow(ratio, i); |
|
49 tscale = wah / sum; |
|
50 } |
|
51 } |
|
52 nx = wax; |
|
53 ny = way; |
27 for(i = 0, c = clients; c; c = c->next) |
54 for(i = 0, c = clients; c; c = c->next) |
28 if(isvisible(c)) { |
55 if(isvisible(c)) { |
29 unban(c); |
56 unban(c); |
30 if(c->isfloating) |
57 if(c->isfloating) |
31 continue; |
58 continue; |
32 c->ismax = False; |
59 c->ismax = False; |
33 nx = wax; |
60 if(i < nmaster) { /* master window */ |
34 ny = way; |
|
35 if(i < nmaster) { |
|
36 ny += i * mh; |
|
37 nw = mw - 2 * c->border; |
61 nw = mw - 2 * c->border; |
38 nh = mh; |
62 if(i + 1 == n || i + 1 == nmaster) |
39 if(i + 1 == (n < nmaster ? n : nmaster)) /* remainder */ |
63 nh = (way + wah) - ny - (2 * c->border); |
40 nh = wah - mh * i; |
64 else |
41 nh -= 2 * c->border; |
65 nh = (mscale * spow(ratio, i)) - (2 * c->border); |
42 } |
66 } |
43 else { /* tile window */ |
67 else { /* tile window */ |
44 nx += mw; |
68 if(i == nmaster) { |
|
69 ny = way; |
|
70 nx = wax + mw; |
|
71 } |
45 nw = tw - 2 * c->border; |
72 nw = tw - 2 * c->border; |
46 if(th > 2 * c->border) { |
73 if(i + 1 == n) |
47 ny += (i - nmaster) * th; |
74 nh = (way + wah) - ny - (2 * c->border); |
48 nh = th; |
75 else |
49 if(i + 1 == n) /* remainder */ |
76 nh = (tscale * spow(ratio, i - nmaster)) - (2 * c->border); |
50 nh = wah - th * (i - nmaster); |
77 } |
51 nh -= 2 * c->border; |
78 if(nh < bh) { |
52 } |
79 nh = bh; |
53 else /* fallback if th <= 2 * c->border */ |
80 ny = way + wah - nh; |
54 nh = wah - 2 * c->border; |
|
55 } |
81 } |
56 resize(c, nx, ny, nw, nh, False); |
82 resize(c, nx, ny, nw, nh, False); |
|
83 ny += nh; |
57 i++; |
84 i++; |
58 } |
85 } |
59 else |
86 else |
60 ban(c); |
87 ban(c); |
61 focus(NULL); |
88 focus(NULL); |