From 852ae63fd8c6cf6a35c02ec750f992f8c01f00d1 Mon Sep 17 00:00:00 2001 From: rafa_99 Date: Sun, 2 Feb 2020 00:52:33 +0000 Subject: Fibonacci Layout --- dwm.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'dwm.c') diff --git a/dwm.c b/dwm.c index 9ae95b5..10dd717 100644 --- a/dwm.c +++ b/dwm.c @@ -169,8 +169,10 @@ static void detachstack(Client *c); static Monitor *dirtomon(int dir); static void drawbar(Monitor *m); static void drawbars(void); +static void dwindle(Monitor *mon); static void enternotify(XEvent *e); static void expose(XEvent *e); +static void fibonacci(Monitor *mon, int s); static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); @@ -225,6 +227,7 @@ static void sigchld(int unused); static void sighup(int unused); static void sigterm(int unused); static void spawn(const Arg *arg); +static void spiral(Monitor *mon); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *); @@ -782,6 +785,11 @@ drawbars(void) drawbar(m); } +void +dwindle(Monitor *mon) { + fibonacci(mon, 1); +} + void enternotify(XEvent *e) { @@ -811,6 +819,63 @@ expose(XEvent *e) drawbar(m); } +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 focus(Client *c) { @@ -1811,6 +1876,11 @@ spawn(const Arg *arg) } } +void +spiral(Monitor *mon) { + fibonacci(mon, 0); +} + void tag(const Arg *arg) { -- cgit v1.2.3