💾 Archived View for ait.place › dot › suckless › dwm_diffs › dwm_nrowgrid.diff.txt captured on 2021-12-03 at 14:04:38.

View Raw

More Information

-=-=-=-=-=-=-

diff --git a/config.def.h b/config.def.h
index 1c0b587..c103673 100644
--- a/config.def.h
+++ b/config.def.h
@@ -41,6 +41,7 @@ static const Layout layouts[] = {
 	{ "[]=",      tile },    /* first entry is default */
 	{ "><>",      NULL },    /* no layout function means floating behavior */
 	{ "[M]",      monocle },
+	{ "###",      nrowgrid },
 };
 
 /* key definitions */
@@ -112,4 +113,3 @@ static Button buttons[] = {
 	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
 	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
 };
-
diff --git a/dwm.c b/dwm.c
index 664c527..0f9d792 100644
--- a/dwm.c
+++ b/dwm.c
@@ -185,6 +185,7 @@ static void monocle(Monitor *m);
 static void motionnotify(XEvent *e);
 static void movemouse(const Arg *arg);
 static Client *nexttiled(Client *c);
+static void nrowgrid(Monitor *m);
 static void pop(Client *);
 static void propertynotify(XEvent *e);
 static void quit(const Arg *arg);
@@ -1200,6 +1201,58 @@ nexttiled(Client *c)
 	return c;
 }
 
+void
+nrowgrid(Monitor *m)
+{
+    unsigned int n = 0, i = 0, ri = 0, ci = 0;  /* counters */
+    unsigned int cx, cy, cw, ch;                /* client geometry */
+    unsigned int uw = 0, uh = 0, uc = 0;        /* utilization trackers */
+    unsigned int cols, rows = m->nmaster + 1;
+    Client *c;
+
+    for (c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+
+    /* nothing to do here */
+    if (n == 0)
+        return;
+
+    /* always have 3 or less be rows 1 */
+    if (n < 4)
+        rows = 1;
+
+    /* never allow empty rows */
+    if (n < rows)
+        rows = n;
+
+    /* define first row */
+    cols = n / rows;
+    uc = cols;
+    cy = m->wy;
+    ch = m->wh / rows;
+    uh = ch;
+
+    for (c = nexttiled(m->clients); c; c = nexttiled(c->next), i++, ci++) {
+        if (ci == cols) {
+            uw = 0;
+            ci = 0;
+            ri++;
+
+            /* next row */
+            cols = (n - uc) / (rows - ri);
+            uc += cols;
+            cy = m->wy + uh;
+            ch = (m->wh - uh) / (rows - ri);
+            uh += ch;
+        }
+
+        cx = m->wx + uw;
+        cw = (m->ww - uw) / (cols - ci);
+        uw += cw;
+
+        resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, 0);
+    }
+}
+
 void
 pop(Client *c)
 {