Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit c28915b

Browse files
committed
Added 'gaplessgrid' layout
1 parent a59347e commit c28915b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ static const int nmaster = 1; /* number of clients in master area */
3737
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
3838

3939
#include "tcl.c"
40+
#include "gaplessgrid.c"
4041

4142
static const Layout layouts[] = {
4243
/* symbol arrange function */
4344
{ "[]=", tile }, /* first entry is default */
4445
{ "><>", NULL }, /* no layout function means floating behavior */
4546
{ "[M]", monocle },
4647
{ "|||", tcl },
48+
{ "###", gaplessgrid },
4749
};
4850

4951
/* Display modes of the tab bar: never shown, always shown, shown only in */
@@ -90,6 +92,7 @@ static Key keys[] = {
9092
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
9193
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
9294
{ MODKEY|ShiftMask, XK_t, setlayout, {.v = &layouts[3]} },
95+
{ MODKEY, XK_g, setlayout, {.v = &layouts[4]} },
9396
{ MODKEY, XK_space, setlayout, {0} },
9497
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
9598
{ MODKEY, XK_0, view, {.ui = ~0 } },

gaplessgrid.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
void
2+
gaplessgrid(Monitor *m) {
3+
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
4+
Client *c;
5+
6+
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next))
7+
n++;
8+
if(n == 0)
9+
return;
10+
11+
/* grid dimensions */
12+
for(cols = 0; cols <= n/2; cols++)
13+
if(cols*cols >= n)
14+
break;
15+
if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
16+
cols = 2;
17+
rows = n/cols;
18+
19+
/* window geometries */
20+
cw = cols ? m->ww / cols : m->ww;
21+
cn = 0; /* current column number */
22+
rn = 0; /* current row number */
23+
for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
24+
if(i/rows + 1 > cols - n%cols)
25+
rows = n/cols + 1;
26+
ch = rows ? m->wh / rows : m->wh;
27+
cx = m->wx + cn*cw;
28+
cy = m->wy + rn*ch;
29+
resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
30+
rn++;
31+
if(rn >= rows) {
32+
rn = 0;
33+
cn++;
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)