summaryrefslogtreecommitdiffhomepage
path: root/patch/layout_nrowgrid.c
diff options
context:
space:
mode:
authorbakkeby <[email protected]>2020-07-15 08:57:30 +0200
committerbakkeby <[email protected]>2020-07-15 08:57:30 +0200
commit903b32ac8b4a69b37981874f23b15a9f65f2a20d (patch)
treeb7aff3bdd522721a03cbfdaea8adf15fefd90463 /patch/layout_nrowgrid.c
parent1584a32063cd252ec726dd18747c5f91f12f8be9 (diff)
downloaddwm-flexipatch-903b32ac8b4a69b37981874f23b15a9f65f2a20d.tar.gz
dwm-flexipatch-903b32ac8b4a69b37981874f23b15a9f65f2a20d.zip
Major refactoring in preparation for bar modules
Diffstat (limited to 'patch/layout_nrowgrid.c')
-rw-r--r--patch/layout_nrowgrid.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/patch/layout_nrowgrid.c b/patch/layout_nrowgrid.c
new file mode 100644
index 0000000..5709d80
--- /dev/null
+++ b/patch/layout_nrowgrid.c
@@ -0,0 +1,103 @@
+#if VANITYGAPS_PATCH
+void
+nrowgrid(Monitor *m)
+{
+ unsigned int n = 0, i = 0, ri = 0, ci = 0; /* counters */
+ int oh, ov, ih, iv; /* vanitygap settings */
+ 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;
+
+ /* count clients */
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
+
+ /* nothing to do here */
+ if (n == 0)
+ return;
+
+ /* force 2 clients to always split vertically */
+ if (FORCE_VSPLIT && n == 2)
+ rows = 1;
+
+ /* never allow empty rows */
+ if (n < rows)
+ rows = n;
+
+ /* define first row */
+ cols = n / rows;
+ uc = cols;
+ cy = m->wy + oh;
+ ch = (m->wh - 2*oh - ih*(rows - 1)) / 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 + oh + uh + ih;
+ uh += ch + ih;
+ }
+
+ cx = m->wx + ov + uw;
+ cw = (m->ww - 2*ov - uw) / (cols - ci);
+ uw += cw + iv;
+
+ resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), 0);
+ }
+}
+#else
+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 (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+ if (n == 0)
+ return;
+
+ /* force 2 clients to always split vertically */
+ if (FORCE_VSPLIT && n == 2)
+ 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;
+ 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);
+ }
+}
+#endif \ No newline at end of file