diff options
Diffstat (limited to 'layout.c')
| -rw-r--r-- | layout.c | 94 |
1 files changed, 61 insertions, 33 deletions
| @@ -1,5 +1,6 @@ | |||
| 1 | /* See LICENSE file for copyright and license details. */ | 1 | /* See LICENSE file for copyright and license details. */ |
| 2 | #include "dwm.h" | 2 | #include "dwm.h" |
| 3 | #include <stdio.h> | ||
| 3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
| 4 | 5 | ||
| 5 | unsigned int blw = 0; | 6 | unsigned int blw = 0; |
| @@ -7,53 +8,79 @@ Layout *lt = NULL; | |||
| 7 | 8 | ||
| 8 | /* static */ | 9 | /* static */ |
| 9 | 10 | ||
| 11 | static double ratio = RATIO; | ||
| 10 | static unsigned int nlayouts = 0; | 12 | static unsigned int nlayouts = 0; |
| 11 | static unsigned int masterw = MASTERWIDTH; | ||
| 12 | static unsigned int nmaster = NMASTER; | 13 | static unsigned int nmaster = NMASTER; |
| 13 | 14 | ||
| 15 | static double // simple pow() | ||
| 16 | spow(double x, double y) | ||
| 17 | { | ||
| 18 | if(y == 0) | ||
| 19 | return 1; | ||
| 20 | while(--y) | ||
| 21 | x *= x; | ||
| 22 | return x; | ||
| 23 | } | ||
| 24 | |||
| 14 | static void | 25 | static void |
| 15 | tile(void) { | 26 | tile(void) { |
| 16 | unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; | 27 | double mscale = 0, tscale = 0, sum = 0; |
| 28 | unsigned int i, n, nx, ny, nw, nh, mw, tw; | ||
| 17 | Client *c; | 29 | Client *c; |
| 18 | 30 | ||
| 19 | for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) | 31 | for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) |
| 20 | n++; | 32 | n++; |
| 21 | /* window geoms */ | 33 | |
| 22 | mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); | 34 | mw = (n <= nmaster) ? waw : waw / (1 + ratio); |
| 23 | mw = (n > nmaster) ? (waw * masterw) / 1000 : waw; | ||
| 24 | th = (n > nmaster) ? wah / (n - nmaster) : 0; | ||
| 25 | tw = waw - mw; | 35 | tw = waw - mw; |
| 26 | 36 | ||
| 37 | if(n > 0) { | ||
| 38 | if(n < nmaster) { | ||
| 39 | for(i = 0; i < n; i++) | ||
| 40 | sum += spow(ratio, i); | ||
| 41 | mscale = wah / sum; | ||
| 42 | } | ||
| 43 | else { | ||
| 44 | for(i = 0; i < nmaster; i++) | ||
| 45 | sum += spow(ratio, i); | ||
| 46 | mscale = wah / sum; | ||
| 47 | for(sum = 0, i = 0; i < (n - nmaster); i++) | ||
| 48 | sum += spow(ratio, i); | ||
| 49 | tscale = wah / sum; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | nx = wax; | ||
| 53 | ny = way; | ||
| 27 | for(i = 0, c = clients; c; c = c->next) | 54 | for(i = 0, c = clients; c; c = c->next) |
| 28 | if(isvisible(c)) { | 55 | if(isvisible(c)) { |
| 29 | unban(c); | 56 | unban(c); |
| 30 | if(c->isfloating) | 57 | if(c->isfloating) |
| 31 | continue; | 58 | continue; |
| 32 | c->ismax = False; | 59 | c->ismax = False; |
| 33 | nx = wax; | 60 | if(i < nmaster) { /* master window */ |
| 34 | ny = way; | ||
| 35 | if(i < nmaster) { | ||
| 36 | ny += i * mh; | ||
| 37 | nw = mw - 2 * c->border; | 61 | nw = mw - 2 * c->border; |
| 38 | nh = mh; | 62 | if(i + 1 == n || i + 1 == nmaster) |
| 39 | if(i + 1 == (n < nmaster ? n : nmaster)) /* remainder */ | 63 | nh = (way + wah) - ny - (2 * c->border); |
| 40 | nh = wah - mh * i; | 64 | else |
| 41 | nh -= 2 * c->border; | 65 | nh = (mscale * spow(ratio, i)) - (2 * c->border); |
| 42 | } | 66 | } |
| 43 | else { /* tile window */ | 67 | else { /* tile window */ |
| 44 | nx += mw; | 68 | if(i == nmaster) { |
| 45 | nw = tw - 2 * c->border; | 69 | ny = way; |
| 46 | if(th > 2 * c->border) { | 70 | nx = wax + mw; |
| 47 | ny += (i - nmaster) * th; | ||
| 48 | nh = th; | ||
| 49 | if(i + 1 == n) /* remainder */ | ||
| 50 | nh = wah - th * (i - nmaster); | ||
| 51 | nh -= 2 * c->border; | ||
| 52 | } | 71 | } |
| 53 | else /* fallback if th <= 2 * c->border */ | 72 | nw = tw - 2 * c->border; |
| 54 | nh = wah - 2 * c->border; | 73 | if(i + 1 == n) |
| 74 | nh = (way + wah) - ny - (2 * c->border); | ||
| 75 | else | ||
| 76 | nh = (tscale * spow(ratio, i - nmaster)) - (2 * c->border); | ||
| 77 | } | ||
| 78 | if(nh < bh) { | ||
| 79 | nh = bh; | ||
| 80 | ny = way + wah - nh; | ||
| 55 | } | 81 | } |
| 56 | resize(c, nx, ny, nw, nh, False); | 82 | resize(c, nx, ny, nw, nh, False); |
| 83 | ny += nh; | ||
| 57 | i++; | 84 | i++; |
| 58 | } | 85 | } |
| 59 | else | 86 | else |
| @@ -106,18 +133,19 @@ focusclient(const char *arg) { | |||
| 106 | } | 133 | } |
| 107 | 134 | ||
| 108 | void | 135 | void |
| 109 | incmasterw(const char *arg) { | 136 | incratio(const char *arg) { |
| 110 | int i; | 137 | double delta; |
| 138 | |||
| 111 | if(lt->arrange != tile) | 139 | if(lt->arrange != tile) |
| 112 | return; | 140 | return; |
| 113 | if(!arg) | 141 | if(!arg) |
| 114 | masterw = MASTERWIDTH; | 142 | ratio = RATIO; |
| 115 | else { | 143 | else { |
| 116 | i = atoi(arg); | 144 | if(1 == sscanf(arg, "%lf", &delta)) { |
| 117 | if(waw * (masterw + i) / 1000 >= waw - 2 * BORDERPX | 145 | if(delta + ratio < .1 || delta + ratio > 1.9) |
| 118 | || waw * (masterw + i) / 1000 <= 2 * BORDERPX) | 146 | return; |
| 119 | return; | 147 | ratio += delta; |
| 120 | masterw += i; | 148 | } |
| 121 | } | 149 | } |
| 122 | lt->arrange(); | 150 | lt->arrange(); |
| 123 | } | 151 | } |
