This patch adds a tatami arrangement to dwm, accessible through modkey+y
There are 5 different patterns for different number (modulo 5) of clients open
diff -Naur dwm/config.def.h dwm-tatami/config.def.h
--- dwm/config.def.h 2020-09-24 02:14:27.545355268 -0500
+++ dwm-tatami/config.def.h 2020-09-24 02:46:12.041952267 -0500
@@ -34,13 +34,15 @@
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
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 resizehints = 0; /* 1 means respect size hints in tiled resizals */
+#include "tatami.c"
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
+ { "|+|", tatami },
};
/* key definitions */
@@ -76,6 +78,7 @@
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+ { MODKEY, XK_y, setlayout, {.v = &layouts[3]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
diff -Naur dwm/tatami.c dwm-tatami/tatami.c
--- dwm/tatami.c 1969-12-31 18:00:00.000000000 -0600
+++ dwm-tatami/tatami.c 2020-09-24 02:17:14.335349175 -0500
@@ -0,0 +1,157 @@
+void
+tatami(Monitor *m) {
+ unsigned int i, n, nx, ny, nw, nh,
+ mats, tc,
+ tnx, tny, tnw, tnh;
+ Client *c;
+
+ for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
+ if(n == 0)
+ return;
+
+ nx = m->wx;
+ ny = 0;
+ nw = m->ww;
+ nh = m->wh;
+
+ c = nexttiled(m->clients);
+
+ if(n != 1) nw = m->ww * m->mfact;
+ ny = m->wy;
+
+ resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False);
+
+ c = nexttiled(c->next);
+
+ nx += nw;
+ nw = m->ww - nw;
+
+ if(n>1)
+ {
+
+ tc = n-1;
+ mats = tc/5;
+
+ nh/=(mats + (tc % 5 > 0));
+
+ for(i = 0; c && (i < (tc % 5)); c = nexttiled(c->next))
+ {
+ tnw=nw;
+ tnx=nx;
+ tnh=nh;
+ tny=ny;
+ switch(tc - (mats*5))
+ {
+ case 1://fill
+ break;
+ case 2://up and down
+ if((i % 5) == 0) //up
+ tnh/=2;
+ else if((i % 5) == 1) //down
+ {
+ tnh/=2;
+ tny += nh/2;
+ }
+ break;
+ case 3://bottom, up-left and up-right
+ if((i % 5) == 0) //up-left
+ {
+ tnw = nw/2;
+ tnh = (2*nh)/3;
+ }
+ else if((i % 5) == 1)//up-right
+ {
+ tnx += nw/2;
+ tnw = nw/2;
+ tnh = (2*nh)/3;
+ }
+ else if((i % 5) == 2)//bottom
+ {
+ tnh = nh/3;
+ tny += (2*nh)/3;
+ }
+ break;
+ case 4://bottom, left, right and top
+ if((i % 5) == 0) //top
+ {
+ tnh = (nh)/4;
+ }
+ else if((i % 5) == 1)//left
+ {
+ tnw = nw/2;
+ tny += nh/4;
+ tnh = (nh)/2;
+ }
+ else if((i % 5) == 2)//right
+ {
+ tnx += nw/2;
+ tnw = nw/2;
+ tny += nh/4;
+ tnh = (nh)/2;
+ }
+ else if((i % 5) == 3)//bottom
+ {
+ tny += (3*nh)/4;
+ tnh = (nh)/4;
+ }
+ break;
+ }
+ ++i;
+ resize(c, tnx, tny, tnw - 2 * c->bw, tnh - 2 * c->bw, False);
+ }
+
+ ++mats;
+
+ for(i = 0; c && (mats>0); c = nexttiled(c->next)) {
+
+ if((i%5)==0)
+ {
+ --mats;
+ if(((tc % 5) > 0)||(i>=5))
+ ny+=nh;
+ }
+
+ tnw=nw;
+ tnx=nx;
+ tnh=nh;
+ tny=ny;
+
+
+ switch(i % 5)
+ {
+ case 0: //top-left-vert
+ tnw = (nw)/3;
+ tnh = (nh*2)/3;
+ break;
+ case 1: //top-right-hor
+ tnx += (nw)/3;
+ tnw = (nw*2)/3;
+ tnh = (nh)/3;
+ break;
+ case 2: //center
+ tnx += (nw)/3;
+ tnw = (nw)/3;
+ tny += (nh)/3;
+ tnh = (nh)/3;
+ break;
+ case 3: //bottom-right-vert
+ tnx += (nw*2)/3;
+ tnw = (nw)/3;
+ tny += (nh)/3;
+ tnh = (nh*2)/3;
+ break;
+ case 4: //(oldest) bottom-left-hor
+ tnw = (2*nw)/3;
+ tny += (2*nh)/3;
+ tnh = (nh)/3;
+ break;
+ default:
+ break;
+ }
+
+ ++i;
+ //i%=5;
+ resize(c, tnx, tny, tnw - 2 * c->bw, tnh - 2 * c->bw, False);
+ }
+ }
+}