X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=layout.c;h=eb64a3332a95aa4146160325b3259f3b6fa47c90;hb=b5eea45a316a897632578a74c909aa336557b1d6;hp=eeeb6285478be68b7b8725a593926a0cfa6ccb24;hpb=e461e60997f83d69561ad0ca4754c299145c00b8;p=dwm.git diff --git a/layout.c b/layout.c index eeeb628..eb64a33 100644 --- a/layout.c +++ b/layout.c @@ -8,95 +8,19 @@ Layout *lt = NULL; /* static */ -static double ratio = RATIO; static unsigned int nlayouts = 0; -static unsigned int nmaster = NMASTER; - -static double // simple pow() -spow(double x, double y) -{ - if(y == 0) - return 1; - while(--y) - x *= x; - return x; -} - -static void -tile(void) { - double mscale = 0, tscale = 0, sum = 0; - unsigned int i, n, nx, ny, nw, nh, mw, tw; - Client *c; - - for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) - n++; - - mw = (n <= nmaster) ? waw : waw / (1 + ratio); - tw = waw - mw; - - if(n > 0) { - if(n < nmaster) { - for(i = 0; i < n; i++) - sum += spow(ratio, i); - mscale = wah / sum; - } - else { - for(i = 0; i < nmaster; i++) - sum += spow(ratio, i); - mscale = wah / sum; - for(sum = 0, i = 0; i < (n - nmaster); i++) - sum += spow(ratio, i); - tscale = wah / sum; - } - } - nx = wax; - ny = way; - for(i = 0, c = clients; c; c = c->next) - if(isvisible(c)) { - unban(c); - if(c->isfloating) - continue; - c->ismax = False; - if(i < nmaster) { /* master window */ - nw = mw - 2 * c->border; - if(i + 1 == n || i + 1 == nmaster) - nh = (way + wah) - ny - (2 * c->border); - else - nh = (mscale * spow(ratio, i)) - (2 * c->border); - } - else { /* tile window */ - if(i == nmaster) { - ny = way; - nx = wax + mw; - } - nw = tw - 2 * c->border; - if(i + 1 == n) - nh = (way + wah) - ny - (2 * c->border); - else - nh = (tscale * spow(ratio, i - nmaster)) - (2 * c->border); - } - if(nh < bh) { - nh = bh; - ny = way + wah - nh; - } - resize(c, nx, ny, nw, nh, False); - ny += nh; - i++; - } - else - ban(c); - focus(NULL); - restack(); -} LAYOUTS /* extern */ void -floating(void) { +floating(const char *arg) { Client *c; + if(lt->arrange != floating) + return; + for(c = clients; c; c = c->next) if(isvisible(c)) { unban(c); @@ -133,43 +57,6 @@ focusclient(const char *arg) { } void -incratio(const char *arg) { - double delta; - - if(lt->arrange != tile) - return; - if(!arg) - ratio = RATIO; - else { - if(1 == sscanf(arg, "%lf", &delta)) { - if(delta + ratio < .1 || delta + ratio > 1.9) - return; - ratio += delta; - } - } - lt->arrange(); -} - -void -incnmaster(const char *arg) { - int i; - - if(!arg) - nmaster = NMASTER; - else { - i = atoi(arg); - if((lt->arrange != tile) || (nmaster + i < 1) - || (wah / (nmaster + i) <= 2 * BORDERPX)) - return; - nmaster += i; - } - if(sel) - lt->arrange(); - else - drawstatus(); -} - -void initlayouts(void) { unsigned int i, w; @@ -233,19 +120,78 @@ setlayout(const char *arg) { lt = &layout[i]; } if(sel) - lt->arrange(); + lt->arrange(NULL); else drawstatus(); } void +tile(const char *arg) { + static double master = MASTER; + double delta; + unsigned int i, n, nx, ny, nw, nh, mw, th; + Client *c; + + if(lt->arrange != tile) + return; + + /* arg handling, manipulate master */ + if(arg && (1 == sscanf(arg, "%lf", &delta))) { + if(delta + master > 0.1 && delta + master < 0.9) + master += delta; + } + + for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) + n++; + + /* window geoms */ + mw = (n == 1) ? waw : master * waw; + th = (n > 1) ? wah / (n - 1) : 0; + if(n > 1 && th < bh) + th = wah; + + nx = wax; + ny = way; + for(i = 0, c = clients; c; c = c->next) + if(isvisible(c)) { + unban(c); + if(c->isfloating) + continue; + c->ismax = False; + if(i == 0) { /* master */ + nw = mw - 2 * c->border; + nh = wah - 2 * c->border; + } + else { /* tile window */ + if(i == 1) { + ny = way; + nx += mw; + } + nw = waw - mw - 2 * c->border; + if(i + 1 == n) /* remainder */ + nh = (way + wah) - ny - 2 * c->border; + else + nh = th - 2 * c->border; + } + resize(c, nx, ny, nw, nh, False); + if(n > 1 && th != wah) + ny += nh + 2 * c->border; + i++; + } + else + ban(c); + focus(NULL); + restack(); +} + +void togglebar(const char *arg) { if(bpos == BarOff) bpos = (BARPOS == BarOff) ? BarTop : BARPOS; else bpos = BarOff; updatebarpos(); - lt->arrange(); + lt->arrange(NULL); } void @@ -279,5 +225,5 @@ zoom(const char *arg) { detach(c); attach(c); focus(c); - lt->arrange(); + lt->arrange(NULL); }