I've been using dvtm at work a lot recently so I figured I'd port the
Fibonacci spiral/dwindle layouts to dvtm. This patch is for 0.5.2. I find
it's not as useful as the Fibonacci layouts in dwm but I figure why not
release it anyway.
-Niki Yoshiuchi
diff --git a/config.h b/config.h
index 0ef2458..563e8e5 100644
--- a/config.h
+++ b/config.h
@@ -44,12 +44,15 @@
#include grid.c
#include bstack.c
#include fullscreen.c
+#include dwindle.c
Layout layouts[] = {
{ []=, tile },
{ +++, grid },
{ TTT, bstack },
{ [ ], fullscreen },
+ { [...@], spiral },
+ { [\\], dwindle },
};
#define MOD CTRL('g')
@@ -66,12 +69,14 @@ Key keys[] = {
{ MOD, 'g', { setlayout, { +++ } } },
{ MOD, 'b', { setlayout, { TTT } } },
{ MOD, 'm', { setlayout, { [ ] } } },
+ { MOD, 's', { setlayout, { [...@] } } },
+ { MOD, 'd', { setlayout, { [\\] } } },
{ MOD, ' ', { setlayout, { NULL }} },
{ MOD, 'h', { setmwfact, { -0.05 } } },
{ MOD, 'l', { setmwfact, { +0.05 } } },
{ MOD, '.', { toggleminimize, { NULL }} },
#ifdef CONFIG_STATUSBAR
- { MOD, 's', { togglebar, { NULL }} },
+ { MOD, 'r', { togglebar, { NULL }} },
#endif
#ifdef CONFIG_MOUSE
{ MOD, 'M', { mouse_toggle, { NULL }} },
diff --git a/fibonacci.c b/fibonacci.c
new file mode 100644
index 000..a19941f
--- /dev/null
+++ b/fibonacci.c
@@ -0,0 +1,84 @@
+static void
+fibonacci(int s) {
+ unsigned int nx, ny, nw, nh, i, n, m, nm, mod;
+ Client *c;
+
+ for(n = 0, m = 0, c = clients; c; c = c-next,n++)
+ if(c-minimized)
+ m++;
+ /* number of non minimized windows */
+ nm = n - m;
+
+ /* initial position and dimensions */
+ nx = wax;
+ ny = way;
+ nw = waw;
+ nh = (wah - m); /* leave space for the minimized clients */
+
+ /* set the mod factor, 2 for dwindle, 4 for spiral */
+ mod = s ? 4 : 2;
+
+ for(i = 0, c = clients; c; c = c-next,i++) {
+ if(!c-minimized) {
+ /* dwindle: even case, spiral: case 0*/
+ if(i % mod == 0) {
+ny += (i == 0 ? 0 : nh) * (s ? -1 : 1);
+/* TODO: first client uses the width factor, the rest divide by two */
+/* don't adjust the width for the last non-minimized client */
+if(i nm - 1)
+ nw /= 2;
+ }
+ /* dwindle: odd case, spiral: case 1*/
+ else if(i % mod == 1) {
+nx += nw;
+mvvline(ny, nx, ACS_VLINE, nh);
+mvaddch(ny, nx, ACS_TTEE);
+++nx;
+--nw;
+/* don't adjust the height for the last non-minimized client */
+if(i nm - 1)
+ nh /= 2;
+ }
+ /* spiral: case 2*/
+ else if(i % mod == 2 s) {
+ny += nh;
+/* don't adjust the width for the last non-minimized client */
+if(i nm - 1) {
+ nw /= 2;
+ nx += nw;
+ mvvline(ny, nx, ACS_VLINE, nh);
+ mvaddch(ny, nx, ACS_TTEE);
+ ++nx;
+}
+ }
+ /* spiral: case 3*/
+ else if(s) {
+nx -= nw;
+--nw;
+/* don't adjust the height for the last non-minimized client */
+if(i nm - 1) {
+ nh /= 2;
+ ny += nh;
+}
+ }
+ } else {
+ nh = 1;
+ nw = waw;
+ nx = wax;
+ ny = way + wah - (n - i);
+ }
+
+ resize(c,nx,ny,nw,nh);
+ }
+}
+
+static void
+spiral(void) {
+ fibonacci(1);
+}
+
+static void
+dwindle(void) {
+ fibonacci(0);
+}
+