diff --git a/config.def.h b/config.def.h index 83b1441..45eda0a 100644 --- a/config.def.h +++ b/config.def.h @@ -121,12 +121,14 @@ static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ +#include "gaplessgrid.c" static const Layout layouts[] = { /* symbol arrange function */ { "[]=", tile }, /* first entry is default */ { "><>", NULL }, /* no layout function means floating behavior */ { "[M]", monocle }, { "[D]", deck }, + { "###", gaplessgrid }, }; /* key definitions */ diff --git a/gaplessgrid.c b/gaplessgrid.c new file mode 100644 index 0000000..6b7ded2 --- /dev/null +++ b/gaplessgrid.c @@ -0,0 +1,47 @@ +void +gaplessgrid(Monitor *m) +{ + unsigned int i, n; + int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters + Client *c; + + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if ( n == 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; + cn = rn = 0; // reset column no, row no, client count + + ch = (m->wh - 2*gappx - gappx * (rows - 1)) / rows; + cw = (m->ww - 2*gappx - gappx * (cols - 1)) / cols; + rrest = (m->wh - 2*gappx - gappx * (rows - 1)) - ch * rows; + crest = (m->ww - 2*gappx - gappx * (cols - 1)) - cw * cols; + x = m->wx + gappx; + y = m->wy + gappx; + + 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 = (m->wh - 2*gappx - gappx * (rows - 1)) / rows; + rrest = (m->wh - 2*gappx - gappx * (rows - 1)) - ch * rows; + } + resize(c, + x, + y + rn*(ch + gappx) + MIN(rn, rrest), + cw + (cn < crest ? 1 : 0) - 2*c->bw, + ch + (rn < rrest ? 1 : 0) - 2*c->bw, + 0); + rn++; + if (rn >= rows) { + rn = 0; + x += cw + gappx + (cn < crest ? 1 : 0); + cn++; + } + } +} diff --git a/patches/layouts/dwm-gaplessgrid-20160731-56a31dc.diff b/patches/layouts/dwm-gaplessgrid-20160731-56a31dc.diff new file mode 100644 index 0000000..4f3bb13 --- /dev/null +++ b/patches/layouts/dwm-gaplessgrid-20160731-56a31dc.diff @@ -0,0 +1,43 @@ +URL: http://dwm.suckless.org/patches/gapless_grid +Add gapless grid layout. + +Index: dwm/gaplessgrid.c +=================================================================== +--- /dev/null ++++ dwm/gaplessgrid.c +@@ -0,0 +1,35 @@ ++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; ++ ++ /* 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 / rows : m->wh; ++ cx = m->wx + cn*cw; ++ cy = m->wy + rn*ch; ++ resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False); ++ rn++; ++ if(rn >= rows) { ++ rn = 0; ++ cn++; ++ } ++ } ++} diff --git a/scripts/layoutmenu.sh b/scripts/layoutmenu.sh index 8370b12..ffa7e2c 100755 --- a/scripts/layoutmenu.sh +++ b/scripts/layoutmenu.sh @@ -5,4 +5,5 @@ cat <<> Floating Layout 1 [M] Monocle Layout 2 [D] Deck Layout 3 +### Grid Layout 4 EOF