diff -uNrp dwm.orig/config.h dwm.colstack/config.h --- dwm.orig/config.h 2007-09-19 12:42:52.000000000 +0100 +++ dwm.colstack/config.h 2007-09-19 13:07:55.000000000 +0100 @@ -29,6 +29,9 @@ Layout layouts[] = { }; #define RESIZEHINTS True /* False - respect size hints in tiled resizals */ #define MWFACT 0.6 /* master width factor [0.1 .. 0.9] */ +#define NMASTER 1 /* clients in master area */ +#define NROWS 3 /* clients per column in stacking area */ +#define NCOLS 1 /* number of stacking area columns */ #define SNAP 32 /* snap pixel */ /* key definitions */ @@ -47,6 +50,12 @@ Key keys[] = { \ { MODKEY, XK_k, focusprev, NULL }, \ { MODKEY, XK_h, setmwfact, "-0.05" }, \ { MODKEY, XK_l, setmwfact, "+0.05" }, \ + { MODKEY|ShiftMask, XK_j, setnrows, "-1" }, \ + { MODKEY|ShiftMask, XK_k, setnrows, "+1" }, \ + { MODKEY|ControlMask, XK_j, setncols, "-1" }, \ + { MODKEY|ControlMask, XK_k, setncols, "+1" }, \ + { MODKEY|ShiftMask, XK_h, setnmaster, "-1" }, \ + { MODKEY|ShiftMask, XK_l, setnmaster, "+1" }, \ { MODKEY, XK_m, togglemax, NULL }, \ { MODKEY, XK_Return, zoom, NULL }, \ { MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \ diff -uNrp dwm.orig/dwm.c dwm.colstack/dwm.c --- dwm.orig/dwm.c 2007-09-19 12:42:53.000000000 +0100 +++ dwm.colstack/dwm.c 2007-09-19 13:35:50.000000000 +0100 @@ -166,6 +166,9 @@ void scan(void); void setclientstate(Client *c, long state); void setlayout(const char *arg); void setmwfact(const char *arg); +void setncols(const char *arg); +void setnmaster(const char *arg); +void setnrows(const char *arg); void setup(void); void spawn(const char *arg); void tag(const char *arg); @@ -192,6 +195,7 @@ void zoom(const char *arg); /* variables */ char stext[256]; double mwfact; +unsigned int nmaster, nrows, ncols; int screen, sx, sy, sw, sh, wax, way, waw, wah; int (*xerrorxlib)(Display *, XErrorEvent *); unsigned int bh, bpos, ntags; @@ -1417,6 +1421,66 @@ setmwfact(const char *arg) { } void +setncols(const char *arg) { + int i; + if(!isarrange(tile)) + return; + if(!arg) + i = NCOLS; + else if(arg[0] != '+' && arg[0] != '-') + i = atoi(arg); + else + i = ncols + atoi(arg); + if(i < 1 || waw * mwfact <= 2 * BORDERPX * i) + return; + ncols = i; + if(sel) + arrange(); + else + drawbar(); +} + +void +setnmaster(const char *arg) { + int i; + if(!isarrange(tile)) + return; + if(!arg) + i = NMASTER; + else if(arg[0] != '+' && arg[0] != '-') + i = atoi(arg); + else + i = nmaster + atoi(arg); + if(i < 0 || wah <= 2 * BORDERPX * i) + return; + nmaster = i; + if(sel) + arrange(); + else + drawbar(); +} + +void +setnrows(const char *arg) { + int i; + if(!isarrange(tile)) + return; + if(!arg) + i = NROWS; + else if(arg[0] != '+' && arg[0] != '-') + i = atoi(arg); + else + i = nrows + atoi(arg); + if(i < 1 || wah <= 2 * BORDERPX * i) + return; + nrows = i; + if(sel) + arrange(); + else + drawbar(); +} + +void setup(void) { unsigned int i, j, mask; Window w; @@ -1481,6 +1545,9 @@ setup(void) { /* init layouts */ mwfact = MWFACT; + nmaster = NMASTER; + nrows = NROWS; + ncols = NCOLS; nlayouts = sizeof layouts / sizeof layouts[0]; for(blw = i = 0; i < nlayouts; i++) { j = textw(layouts[i].symbol); @@ -1566,40 +1633,78 @@ textw(const char *text) { void tile(void) { - unsigned int i, n, nx, ny, nw, nh, mw, th; + unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th, tw1, cols, rows, rows1; Client *c; for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) n++; - /* window geoms */ - mw = (n == 1) ? waw : mwfact * waw; - th = (n > 1) ? wah / (n - 1) : 0; - if(n > 1 && th < bh) - th = wah; + /* calculate correct number of stack rows */ + if(n - nmaster > nrows * ncols) + rows = (n - nmaster) / ncols + ((n - nmaster) % ncols ? 1 : 0); + else + rows = nrows; + + /* master area geoms */ + if(nmaster == 0) { + mh = mw = 0; + } + else if(n <= nmaster) { + mh = wah / (n > 0 ? n : 1); + mw = waw; + } + else { + mh = wah / (nmaster > 0 ? nmaster : 1); + mw = waw * mwfact; + } + + /* stacking area geoms */ + if(n <= nmaster + rows) { + rows1 = n > nmaster ? n - nmaster : 1; + tw = tw1 = waw - mw; + th = wah / rows1; + } + else { + rows1 = 1 + (n - nmaster - 1) % rows; + cols = (n - nmaster) / rows + ((n - nmaster) % rows ? 1 : 0); + tw = (waw - mw) / cols; + tw1 = waw - mw - (cols - 1) * tw; + th = wah / rows; + } nx = wax; ny = way; + for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++) { c->ismax = False; - if(i == 0) { /* master */ + if(i < nmaster) { /* master column */ nw = mw - 2 * c->border; - nh = wah - 2 * c->border; + nh = mh - 2 * c->border; + if(i == 0) + nh += wah - mh * (n < nmaster ? n : nmaster); } - else { /* tile window */ - if(i == 1) { + else if(i < nmaster + rows1) { /* first stack column */ + if(i == nmaster) { /* initialise */ ny = way; nx += mw; + nh = wah - 2*c->border - (rows1 - 1) * th; + } + else + nh = th - 2 * c->border; + nw = tw1 - 2 * c->border; + } + else { /* successive stack columns - rows > 0 if we reach here */ + if((i - nmaster - rows1) % rows == 0) { /* reinitialise */ + ny = way; + nx += nw + 2 * c-> border; + nh = wah - 2*c->border - (rows - 1) * th; } - nw = waw - mw - 2 * c->border; - if(i + 1 == n) /* remainder */ - nh = (way + wah) - ny - 2 * c->border; else nh = th - 2 * c->border; + nw = tw - 2 * c->border; } resize(c, nx, ny, nw, nh, RESIZEHINTS); - if(n > 1 && th != wah) - ny += nh + 2 * c->border; + ny += nh + 2 * c->border; } }