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;
17 incratio(const char *arg, double *ratio, double def) {
20 if(lt->arrange != tile)
25 if(1 == sscanf(arg, "%lf", &delta)) {
26 if(delta + (*ratio) < .1 || delta + (*ratio) > 1.9)
34 static double /* simple pow() */
35 spow(double x, double y)
46 double mscale = 0, tscale = 0, sum = 0;
47 unsigned int i, n, nx, ny, nw, nh, mw, tw;
50 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
53 mw = (n <= nmaster) ? waw : waw / (1 + hratio);
58 for(i = 0; i < n; i++)
59 sum += spow(vratio, i);
63 for(i = 0; i < nmaster; i++)
64 sum += spow(vratio, i);
66 for(sum = 0, i = 0; i < (n - nmaster); i++)
67 sum += spow(vratio, i);
73 for(i = 0, c = clients; c; c = c->next)
79 if(i < nmaster) { /* master window */
80 nw = mw - 2 * c->border;
81 if(i + 1 == n || i + 1 == nmaster)
82 nh = (way + wah) - ny - (2 * c->border);
84 nh = (mscale * spow(vratio, i)) - (2 * c->border);
86 else { /* tile window */
91 nw = tw - 2 * c->border;
93 nh = (way + wah) - ny - (2 * c->border);
95 nh = (tscale * spow(vratio, i - nmaster)) - (2 * c->border);
101 resize(c, nx, ny, nw, nh, False);
119 for(c = clients; c; c = c->next)
122 resize(c, c->x, c->y, c->w, c->h, True);
131 focusclient(const char *arg) {
137 for(c = sel->prev; c && !isvisible(c); c = c->prev);
139 for(c = clients; c && c->next; c = c->next);
140 for(; c && !isvisible(c); c = c->prev);
144 for(c = sel->next; c && !isvisible(c); c = c->next);
146 for(c = clients; c && !isvisible(c); c = c->next);
155 inchratio(const char *arg) {
156 incratio(arg, &hratio, HRATIO);
160 incvratio(const char *arg) {
161 incratio(arg, &vratio, VRATIO);
165 incnmaster(const char *arg) {
172 if((lt->arrange != tile) || (nmaster + i < 1)
173 || (wah / (nmaster + i) <= 2 * BORDERPX))
188 nlayouts = sizeof layout / sizeof layout[0];
189 for(blw = i = 0; i < nlayouts; i++) {
190 w = textw(layout[i].symbol);
197 nexttiled(Client *c) {
198 for(; c && (c->isfloating || !isvisible(c)); c = c->next);
211 if(sel->isfloating || lt->arrange == floating)
212 XRaiseWindow(dpy, sel->win);
213 if(lt->arrange != floating) {
214 wc.stack_mode = Below;
216 if(!sel->isfloating) {
217 XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
218 wc.sibling = sel->win;
220 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
223 XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
228 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
232 setlayout(const char *arg) {
237 if(lt == layout + nlayouts)
242 if(i < 0 || i >= nlayouts)
253 togglebar(const char *arg) {
255 bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
263 togglemax(const char *arg) {
266 if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
268 if((sel->ismax = !sel->ismax)) {
273 resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
276 resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
278 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
282 zoom(const char *arg) {
285 if(!sel || lt->arrange == floating || sel->isfloating)
287 if((c = sel) == nexttiled(clients))
288 if(!(c = nexttiled(c->next)))