1 /* See LICENSE file for copyright and license details. */
11 static double hratio = HRATIO;
12 static double vratio = VRATIO;
13 static unsigned int nlayouts = 0;
14 static unsigned int nmaster = NMASTER;
16 static double /* simple pow() */
17 spow(double x, double y)
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;
34 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
38 mw = (n <= nmaster) ? waw : waw / (1 + hratio);
42 for(i = 0; i < n; i++)
43 sum += spow(vratio, i);
46 mmaxtile = bh > (mscale * spow(vratio, 0));
48 mmaxtile = bh > (mscale * spow(vratio, n - 1));
51 for(i = 0; i < nmaster; i++)
52 sum += spow(vratio, i);
54 for(sum = 0, i = 0; i < (n - nmaster); i++)
55 sum += spow(vratio, i);
58 mmaxtile = bh > (mscale * spow(vratio, 0));
59 smaxtile = bh > (sscale * spow(vratio, 0));
62 mmaxtile = bh > (mscale * spow(vratio, nmaster - 1));
63 smaxtile = bh > (sscale * spow(vratio, n - nmaster - 1));
68 for(i = 0, c = clients; c; c = c->next)
74 if(i < nmaster) { /* master window */
75 nw = mw - 2 * c->border;
78 nh = wah - 2 * c->border;
80 else if(i + 1 == (n < nmaster ? n : nmaster))
81 nh = (way + wah) - ny - 2 * c->border;
83 nh = (mscale * spow(vratio, i)) - 2 * c->border;
85 else { /* tile window */
86 nw = tw - 2 * c->border;
93 nh = wah - 2 * c->border;
96 nh = (way + wah) - ny - 2 * c->border;
98 nh = (sscale * spow(vratio, i - nmaster)) - 2 * c->border;
100 resize(c, nx, ny, nw, nh, False);
113 incratio(const char *arg, double *ratio, double def) {
116 if(lt->arrange != tile)
121 if(1 == sscanf(arg, "%lf", &delta)) {
122 if(delta + (*ratio) < .1 || delta + (*ratio) > 1.9)
136 for(c = clients; c; c = c->next)
139 resize(c, c->x, c->y, c->w, c->h, True);
148 focusclient(const char *arg) {
154 for(c = sel->prev; c && !isvisible(c); c = c->prev);
156 for(c = clients; c && c->next; c = c->next);
157 for(; c && !isvisible(c); c = c->prev);
161 for(c = sel->next; c && !isvisible(c); c = c->next);
163 for(c = clients; c && !isvisible(c); c = c->next);
172 inchratio(const char *arg) {
173 incratio(arg, &hratio, HRATIO);
177 incvratio(const char *arg) {
178 incratio(arg, &vratio, VRATIO);
182 incnmaster(const char *arg) {
189 if((lt->arrange != tile) || (nmaster + i < 1)
190 || (wah / (nmaster + i) <= 2 * BORDERPX))
205 nlayouts = sizeof layout / sizeof layout[0];
206 for(blw = i = 0; i < nlayouts; i++) {
207 w = textw(layout[i].symbol);
214 nexttiled(Client *c) {
215 for(; c && (c->isfloating || !isvisible(c)); c = c->next);
228 if(sel->isfloating || lt->arrange == floating)
229 XRaiseWindow(dpy, sel->win);
230 if(lt->arrange != floating) {
231 wc.stack_mode = Below;
233 if(!sel->isfloating) {
234 XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
235 wc.sibling = sel->win;
237 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
240 XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
245 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
249 setlayout(const char *arg) {
254 if(lt == layout + nlayouts)
259 if(i < 0 || i >= nlayouts)
270 togglebar(const char *arg) {
272 bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
280 togglemax(const char *arg) {
283 if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
285 if((sel->ismax = !sel->ismax)) {
290 resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
293 resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
295 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
299 zoom(const char *arg) {
302 if(!sel || lt->arrange == floating || sel->isfloating)
304 if((c = sel) == nexttiled(clients))
305 if(!(c = nexttiled(c->next)))