summaryrefslogtreecommitdiffstats
path: root/layout.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@gmail.com>2007-08-10 18:16:05 +0200
committerAnselm R. Garbe <garbeam@gmail.com>2007-08-10 18:16:05 +0200
commitaa53e39ec0eb39949c5c03d56da08204d14d9ff9 (patch)
treec03becb10dbc847ec4eacfe6eb8a06cbad7b463b /layout.c
parentslight change of my color scheme (diff)
downloaddwm-aa53e39ec0eb39949c5c03d56da08204d14d9ff9.tar.gz
dwm-aa53e39ec0eb39949c5c03d56da08204d14d9ff9.zip
removed VRATIO, NMASTER, inc*(), renamed HRATIO into MASTER, see mailinglist for details
Diffstat (limited to '')
-rw-r--r--layout.c214
1 files changed, 66 insertions, 148 deletions
diff --git a/layout.c b/layout.c
index 7a7abae..0002397 100644
--- a/layout.c
+++ b/layout.c
@@ -8,131 +8,19 @@ Layout *lt = NULL;
8 8
9/* static */ 9/* static */
10 10
11static double hratio = HRATIO;
12static double vratio = VRATIO;
13static unsigned int nlayouts = 0; 11static unsigned int nlayouts = 0;
14static unsigned int nmaster = NMASTER;
15
16static double /* simple pow() */
17spow(double x, double y)
18{
19 if(y == 0)
20 return 1;
21 while(--y)
22 x *= x;
23 return x;
24}
25
26static void
27tile(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
110LAYOUTS 13LAYOUTS
111 14
112static void
113incratio(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
132void 17void
133floating(void) { 18floating(const char *arg) {
134 Client *c; 19 Client *c;
135 20
21 if(lt->arrange != floating)
22 return;
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);
@@ -169,35 +57,6 @@ focusclient(const char *arg) {
169} 57}
170 58
171void 59void
172inchratio(const char *arg) {
173 incratio(arg, &hratio, HRATIO);
174}
175
176void
177incvratio(const char *arg) {
178 incratio(arg, &vratio, VRATIO);
179}
180
181void
182incnmaster(const char *arg) {
183 int i;
184
185 if(!arg)
186 nmaster = NMASTER;
187 else {
188 i = atoi(arg);
189 if((lt->arrange != tile) || (nmaster + i < 1)
190 || (wah / (nmaster + i) <= 2 * BORDERPX))
191 return;
192 nmaster += i;
193 }
194 if(sel)
195 lt->arrange();
196 else
197 drawstatus();
198}
199
200void
201initlayouts(void) { 60initlayouts(void) {
202 unsigned int i, w; 61 unsigned int i, w;
203 62
@@ -261,19 +120,78 @@ setlayout(const char *arg) {
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();
267} 126}
268 127
269void 128void
129tile(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();
185}
186
187void
270togglebar(const char *arg) { 188togglebar(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
279void 197void
@@ -307,5 +225,5 @@ zoom(const char *arg) {
307 detach(c); 225 detach(c);
308 attach(c); 226 attach(c);
309 focus(c); 227 focus(c);
310 lt->arrange(); 228 lt->arrange(NULL);
311} 229}