aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2020-11-03 22:38:47 -0500
committerMitch Riedstra <mitch@riedstra.us>2020-11-03 22:38:47 -0500
commit509e38c6c86a3078441cbcde61355e9d60cdf35d (patch)
tree28e75ddb8f140fdc9105637c0a3ab5ca23aa6694
parent85c0fa85768fd34ed9e16d3f8e7194e4aea09b38 (diff)
downloaddwm-509e38c6c86a3078441cbcde61355e9d60cdf35d.tar.gz
dwm-509e38c6c86a3078441cbcde61355e9d60cdf35d.tar.xz
Add fibonacci based layout
-rw-r--r--config.h4
-rw-r--r--layouts.c67
2 files changed, 71 insertions, 0 deletions
diff --git a/config.h b/config.h
index 8a4f4af..e7067d4 100644
--- a/config.h
+++ b/config.h
@@ -56,6 +56,8 @@ static const Layout layouts[] = {
{ "|M|", centeredmaster },
{ ">M>", centeredfloatingmaster },
{ "HHH", grid },
+ { "[@]", spiral },
+ { "[\\]", dwindle },
};
/* key definitions */
@@ -108,6 +110,8 @@ static Key keys[] = {
{ MODKEY, XK_u, setlayout, {.v = &layouts[3]} },
{ MODKEY|ShiftMask, XK_o, setlayout, {.v = &layouts[4]} },
{ MODKEY, XK_g, setlayout, {.v = &layouts[5]} },
+ { MODKEY, XK_v, setlayout, {.v = &layouts[6]} },
+ { MODKEY|ShiftMask, XK_v, setlayout, {.v = &layouts[7]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
diff --git a/layouts.c b/layouts.c
index d26acf3..1a6d7fc 100644
--- a/layouts.c
+++ b/layouts.c
@@ -25,3 +25,70 @@ grid(Monitor *m) {
i++;
}
}
+
+void
+fibonacci(Monitor *mon, int s) {
+ unsigned int i, n, nx, ny, nw, nh;
+ Client *c;
+
+ for(n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), n++);
+ if(n == 0)
+ return;
+
+ nx = mon->wx;
+ ny = 0;
+ nw = mon->ww;
+ nh = mon->wh;
+
+ for(i = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next)) {
+ if((i % 2 && nh / 2 > 2 * c->bw)
+ || (!(i % 2) && nw / 2 > 2 * c->bw)) {
+ if(i < n - 1) {
+ if(i % 2)
+ nh /= 2;
+ else
+ nw /= 2;
+ if((i % 4) == 2 && !s)
+ nx += nw;
+ else if((i % 4) == 3 && !s)
+ ny += nh;
+ }
+ if((i % 4) == 0) {
+ if(s)
+ ny += nh;
+ else
+ ny -= nh;
+ }
+ else if((i % 4) == 1)
+ nx += nw;
+ else if((i % 4) == 2)
+ ny += nh;
+ else if((i % 4) == 3) {
+ if(s)
+ nx += nw;
+ else
+ nx -= nw;
+ }
+ if(i == 0)
+ {
+ if(n != 1)
+ nw = mon->ww * mon->mfact;
+ ny = mon->wy;
+ }
+ else if(i == 1)
+ nw = mon->ww - nw;
+ i++;
+ }
+ resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False);
+ }
+}
+
+void
+dwindle(Monitor *mon) {
+ fibonacci(mon, 1);
+}
+
+void
+spiral(Monitor *mon) {
+ fibonacci(mon, 0);
+}