X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=layout.c;h=7a7abae20fc98815da1d93dc548e42c638169a70;hb=2cd16097708cf38ab668e9131a60d6dd937f246b;hp=eeeb6285478be68b7b8725a593926a0cfa6ccb24;hpb=e461e60997f83d69561ad0ca4754c299145c00b8;p=dwm.git diff --git a/layout.c b/layout.c index eeeb628..7a7abae 100644 --- a/layout.c +++ b/layout.c @@ -8,11 +8,12 @@ Layout *lt = NULL; /* static */ -static double ratio = RATIO; +static double hratio = HRATIO; +static double vratio = VRATIO; static unsigned int nlayouts = 0; static unsigned int nmaster = NMASTER; -static double // simple pow() +static double /* simple pow() */ spow(double x, double y) { if(y == 0) @@ -24,33 +25,46 @@ spow(double x, double y) static void tile(void) { - double mscale = 0, tscale = 0, sum = 0; + Bool mmaxtile = False, smaxtile = False; /* fallback tiling */ + double mscale = 0, sscale = 0, sum = 0; unsigned int i, n, nx, ny, nw, nh, mw, tw; Client *c; + /* preparation */ for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) n++; - - mw = (n <= nmaster) ? waw : waw / (1 + ratio); + nx = wax; + ny = way; + mw = (n <= nmaster) ? waw : waw / (1 + hratio); tw = waw - mw; - if(n > 0) { - if(n < nmaster) { + if(n <= nmaster) { for(i = 0; i < n; i++) - sum += spow(ratio, i); + sum += spow(vratio, i); mscale = wah / sum; + if(vratio >= 1) + mmaxtile = bh > mscale; + else + mmaxtile = bh > (mscale * spow(vratio, n - 1)); } else { for(i = 0; i < nmaster; i++) - sum += spow(ratio, i); + sum += spow(vratio, i); mscale = wah / sum; for(sum = 0, i = 0; i < (n - nmaster); i++) - sum += spow(ratio, i); - tscale = wah / sum; + sum += spow(vratio, i); + sscale = wah / sum; + if(vratio >= 1) { + mmaxtile = bh > mscale; + smaxtile = bh > sscale; + } + else { + mmaxtile = bh > (mscale * spow(vratio, nmaster - 1)); + smaxtile = bh > (sscale * spow(vratio, n - nmaster - 1)); + } } } - nx = wax; - ny = way; + /* tiling */ for(i = 0, c = clients; c; c = c->next) if(isvisible(c)) { unban(c); @@ -59,25 +73,29 @@ tile(void) { 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); + if(mmaxtile) { + ny = way; + nh = wah - 2 * c->border; + } + else if(i + 1 == (n < nmaster ? n : nmaster)) + nh = (way + wah) - ny - 2 * c->border; else - nh = (mscale * spow(ratio, i)) - (2 * c->border); + nh = (mscale * spow(vratio, i)) - 2 * c->border; } else { /* tile window */ + nw = tw - 2 * c->border; if(i == nmaster) { ny = way; nx = wax + mw; } - nw = tw - 2 * c->border; - if(i + 1 == n) - nh = (way + wah) - ny - (2 * c->border); + if(smaxtile) { + ny = way; + nh = wah - 2 * c->border; + } + else 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; + nh = (sscale * spow(vratio, i - nmaster)) - 2 * c->border; } resize(c, nx, ny, nw, nh, False); ny += nh; @@ -91,6 +109,24 @@ tile(void) { LAYOUTS +static void +incratio(const char *arg, double *ratio, double def) { + double delta; + + if(lt->arrange != tile) + return; + if(!arg) + *ratio = def; + else { + if(1 == sscanf(arg, "%lf", &delta)) { + if(delta + (*ratio) < .1 || delta + (*ratio) > 1.9) + return; + *ratio += delta; + } + } + lt->arrange(); +} + /* extern */ void @@ -133,21 +169,13 @@ focusclient(const char *arg) { } void -incratio(const char *arg) { - double delta; +inchratio(const char *arg) { + incratio(arg, &hratio, HRATIO); +} - 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 +incvratio(const char *arg) { + incratio(arg, &vratio, VRATIO); } void