# HG changeset patch # User paulo@thepaulopc # Date 1264663709 28800 # Node ID e060ab82b136c5ae8aa8221d0392a215eda78cea # Parent a54de16f8277eed977492023be1cbf330fb64f7f gapless grid diff -r a54de16f8277 -r e060ab82b136 layout.c --- a/layout.c Fri Apr 24 01:34:17 2009 -0700 +++ b/layout.c Wed Jan 27 23:28:29 2010 -0800 @@ -222,43 +222,46 @@ static void grid(void) { - unsigned int i, n, nx, ny, nw, nh, aw, ah, tw, th, cols, rows; + unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch; Client *c; for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) n++; + if(n == 0) + return; - for(rows = 0; rows <= n/2; rows++) - if(rows*rows >= n) + /* grid dimensions */ + for(cols = 0; cols <= n/2; cols++) + if(cols*cols >= n) break; - cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; + if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ + cols = 2; + rows = n/cols; - th = wah / (rows ? rows : 1); - tw = waw / (cols ? cols : 1); - nw = tw - 2 * BORDERPX; - nh = th - 2 * BORDERPX; - + /* window geometries */ + cw = cols ? waw / cols : waw; + cn = 0; /* current column number */ + rn = 0; /* current row number */ 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->isversatile) - continue; - c->ismax = False; - nx = (i / rows) * tw; - ny = (i % rows) * th + (TOPBAR ? dc.h : 0); - /* adjust height and width of last row's and last column's windows */ - ah = ((i + 1) % rows == 0) ? wah - th * rows : 0; - aw = (i >= rows * (cols - 1)) ? waw - tw * cols : 0; - resize(c, nx, ny, nw + aw, nh + ah, False); + if(i/rows + 1 > cols - n%cols) + rows = n/cols + 1; + ch = rows ? wah / rows : wah; + cx = cn*cw; + cy = (TOPBAR ? dc.h : 0) + rn*ch; + resize(c, cx, cy, cw - 2 * BORDERPX, ch - 2 * BORDERPX, False); + rn++; + if(rn >= rows) { + rn = 0; + cn++; + } 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);