diff -Naur --exclude='.hg*' dwm-tip/config.default.h dwm-grid/config.default.h --- dwm-tip/config.default.h 2007-02-25 23:26:01.000000000 +0200 +++ dwm-grid/config.default.h 2007-04-02 12:46:25.000000000 +0300 @@ -32,6 +32,7 @@ /* symbol function */ \ { "[]=", tile }, /* first entry is default */ \ { "><>", floating }, \ + { "+++", grid }, \ }; #define MASTERWIDTH 600 /* master width per thousand */ #define NMASTER 1 /* clients in master area */ diff -Naur --exclude='.hg*' dwm-tip/layout.c dwm-grid/layout.c --- dwm-tip/layout.c 2007-02-26 14:36:31.000000000 +0200 +++ dwm-grid/layout.c 2007-04-02 12:45:50.000000000 +0300 @@ -14,6 +14,52 @@ static unsigned int nmaster = NMASTER; static void +grid(void) { + unsigned int i, n, nx, ny, aw, ah, cw, ch, cols, rows; + Client *c; + + for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) + n++; + + /* grid dimensions */ + for(rows = 0; rows <= n/2; rows++) + if(rows*rows >= n) + break; + cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; + + /* window geoms (cell height/width) */ + ch = wah / (rows ? rows : 1); + cw = waw / (cols ? cols : 1); + + for(i = 0, c = clients; c; c = c->next) + if(isvisible(c)) { + if(c->isbanned) + XMoveWindow(dpy, c->win, c->x, c->y); + c->isbanned = False; + if(c->isfloating) + continue; + c->ismax = False; + nx = (i / rows) * cw; + ny = (i % rows) * ch + (TOPBAR ? bh : 0); + /* adjust height/width of last row/column's windows */ + ah = ((i + 1) % rows == 0) ? wah - ch * rows : 0; + aw = (i >= rows * (cols - 1)) ? waw - cw * cols : 0; + resize(c, nx, ny, cw - 2 * BORDERPX + aw, ch - 2 * BORDERPX + ah, False); + i++; + } + else { + c->isbanned = True; + XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); + } + + if(!sel || !isvisible(sel)) { + for(c = stack; c && !isvisible(c); c = c->snext); + focus(c); + } + restack(); +} + +static void tile(void) { unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; Client *c;