1 /* See LICENSE file for copyright and license details. */
11 static double ratio = RATIO;
12 static unsigned int nlayouts = 0;
13 static unsigned int nmaster = NMASTER;
15 static double // simple pow()
16 spow(double x, double y)
27 double mscale = 0, tscale = 0, sum = 0;
28 unsigned int i, n, nx, ny, nw, nh, mw, tw;
31 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
34 mw = (n <= nmaster) ? waw : waw / (1 + ratio);
39 for(i = 0; i < n; i++)
40 sum += spow(ratio, i);
44 for(i = 0; i < nmaster; i++)
45 sum += spow(ratio, i);
47 for(sum = 0, i = 0; i < (n - nmaster); i++)
48 sum += spow(ratio, i);
54 for(i = 0, c = clients; c; c = c->next)
60 if(i < nmaster) { /* master window */
61 nw = mw - 2 * c->border;
62 if(i + 1 == n || i + 1 == nmaster)
63 nh = (way + wah) - ny - (2 * c->border);
65 nh = (mscale * spow(ratio, i)) - (2 * c->border);
67 else { /* tile window */
72 nw = tw - 2 * c->border;
74 nh = (way + wah) - ny - (2 * c->border);
76 nh = (tscale * spow(ratio, i - nmaster)) - (2 * c->border);
82 resize(c, nx, ny, nw, nh, False);
100 for(c = clients; c; c = c->next)
103 resize(c, c->x, c->y, c->w, c->h, True);
112 focusclient(const char *arg) {
118 for(c = sel->prev; c && !isvisible(c); c = c->prev);
120 for(c = clients; c && c->next; c = c->next);
121 for(; c && !isvisible(c); c = c->prev);
125 for(c = sel->next; c && !isvisible(c); c = c->next);
127 for(c = clients; c && !isvisible(c); c = c->next);
136 incratio(const char *arg) {
139 if(lt->arrange != tile)
144 if(1 == sscanf(arg, "%lf", &delta)) {
145 if(delta + ratio < .1 || delta + ratio > 1.9)
154 incnmaster(const char *arg) {
161 if((lt->arrange != tile) || (nmaster + i < 1)
162 || (wah / (nmaster + i) <= 2 * BORDERPX))
177 nlayouts = sizeof layout / sizeof layout[0];
178 for(blw = i = 0; i < nlayouts; i++) {
179 w = textw(layout[i].symbol);
186 nexttiled(Client *c) {
187 for(; c && (c->isfloating || !isvisible(c)); c = c->next);
200 if(sel->isfloating || lt->arrange == floating)
201 XRaiseWindow(dpy, sel->win);
202 if(lt->arrange != floating) {
203 wc.stack_mode = Below;
205 if(!sel->isfloating) {
206 XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
207 wc.sibling = sel->win;
209 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
212 XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
217 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
221 setlayout(const char *arg) {
226 if(lt == layout + nlayouts)
231 if(i < 0 || i >= nlayouts)
242 togglebar(const char *arg) {
244 bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
252 togglemax(const char *arg) {
255 if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
257 if((sel->ismax = !sel->ismax)) {
262 resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
265 resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
267 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
271 zoom(const char *arg) {
274 if(!sel || lt->arrange == floating || sel->isfloating)
276 if((c = sel) == nexttiled(clients))
277 if(!(c = nexttiled(c->next)))