summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2022-03-26 13:41:00 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2022-03-26 13:41:00 -0400
commit27b7186e77048c1d820a741067f745b1b1304939 (patch)
treeaba87a0b28301f7f9a7e27dbfc66b9178a006123
parentbd923ee2975eea7bfc5b9b13bf99ebf5e087a686 (diff)
Add gaplessgrid patch
-rw-r--r--config.def.h6
-rw-r--r--dwm.c37
-rw-r--r--patch/dwm-gaplessgrid-20160731-56a31dc.diff43
3 files changed, 84 insertions, 2 deletions
diff --git a/config.def.h b/config.def.h
index 2279c10..9d8da04 100644
--- a/config.def.h
+++ b/config.def.h
@@ -46,6 +46,7 @@ static const Layout layouts[] = {
{ "===", bstackhoriz },
{ "|M|", centeredmaster },
{ ">M>", centeredfloatingmaster },
+ { "[+]", gaplessgrid },
};
/* key definitions */
@@ -83,8 +84,9 @@ static Key keys[] = {
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_u, setlayout, {.v = &layouts[3]} },
{ MODKEY, XK_o, setlayout, {.v = &layouts[4]} },
- { MODKEY, XK_r, setlayout, {.v = &layouts[3]} },
- { MODKEY, XK_n, setlayout, {.v = &layouts[4]} },
+ { MODKEY, XK_r, setlayout, {.v = &layouts[5]} },
+ { MODKEY, XK_n, setlayout, {.v = &layouts[6]} },
+ { MODKEY, XK_v, setlayout, {.v = &layouts[6]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
diff --git a/dwm.c b/dwm.c
index 7ae9ac4..c4927e2 100644
--- a/dwm.c
+++ b/dwm.c
@@ -238,6 +238,7 @@ static void centeredmaster(Monitor *m);
static void centeredfloatingmaster(Monitor *m);
static void bstack(Monitor *m);
static void bstackhoriz(Monitor *m);
+static void gaplessgrid(Monitor *m);
/* variables */
static const char broken[] = "broken";
@@ -2323,3 +2324,39 @@ centeredfloatingmaster(Monitor *m)
tx += WIDTH(c);
}
}
+
+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/patch/dwm-gaplessgrid-20160731-56a31dc.diff b/patch/dwm-gaplessgrid-20160731-56a31dc.diff
new file mode 100644
index 0000000..4f3bb13
--- /dev/null
+++ b/patch/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++;
++ }
++ }
++}