diff -upN a/config.def.h b/config.def.h --- a/config.def.h 2019-05-28 13:43:00.326646120 +0200 +++ b/config.def.h 2019-05-29 00:33:28.536627035 +0200 @@ -36,8 +36,10 @@ static const float mfact = 0.55; /* static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ +#include "gaplessgrid.c" static const Layout layouts[] = { /* symbol arrange function */ + { "###", gaplessgrid }, { "[]=", tile }, /* first entry is default */ { "><>", NULL }, /* no layout function means floating behavior */ { "[M]", monocle }, diff -upN a/gaplessgrid.c b/gaplessgrid.c --- a/gaplessgrid.c 1970-01-01 01:00:00.000000000 +0100 +++ b/gaplessgrid.c 2019-06-25 00:26:33.779968246 +0200 @@ -0,0 +1,40 @@ +void +gaplessgrid(Monitor *m) { + unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch; + Client *c; + + for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ; + if(n == 0) + return; + if(n == 1){ + c = nexttiled(m->clients); + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); + return; + } + + /* grid dimensions */ + for(cols = 0; cols <= n/2; cols++) + if(cols*cols >= n) + break; + if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ + cols = 2; + rows = n/cols; + + /* window geometries */ + cw = cols ? m->ww / cols : m->ww; + cn = 0; /* current column number */ + rn = 0; /* current row number */ + for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { + if(i/rows + 1 > cols - n%cols) + rows = n/cols + 1; + ch = rows ? (m->wh-m->gappx) / rows : m->wh; + cx = m->wx + m->gappx + cn*cw; + cy = m->wy + m->gappx + rn*ch; + resize(c, cx - cn*m->gappx/cols, cy, cw - 2 * (c->bw) - m->gappx - m->gappx/cols, ch - 2 * c->bw - m->gappx, False); + rn++; + if(rn >= rows) { + rn = 0; + cn++; + } + } +}