On Fri, Oct 12, 2007 at 10:09:51AM +0200, Anselm R. Garbe wrote:
> Well, I'd prefer that declare the stuff you need from dwm.c as
> externals, simply because they aren't declared as static there.
> 
> At the beginning of fibonacci.c  or .h add:
> 
> extern Client *nexttiled(Client *c);
> extern int screen, sx, sy, sw, sh, wax, way, waw, wah;
> extern Client *clients;
> 
> Then there is no need to put them into dwm.h. The only annoying
> thing is that all extension need to include the Client
> definition imho.
> 

Ah ok, well I added these declarations at the beginning of fibonacci.c, as
well as 3 functions I missed : focus, resize and restack.
Hopefully it's right now.
diff -r e50c3eb0f55a config.def.h
--- a/config.def.h      Thu Oct 11 20:50:01 2007 +0200
+++ b/config.def.h      Fri Oct 12 10:50:41 2007 +0200
@@ -22,7 +22,8 @@ Rule rules[] = {
 };
 
 /* layout(s) */
-#define ISTILE                 isarrange(tile) /* || isarrange(<custom>) */
+#include "fibonacci.h"
+#define ISTILE                 (isarrange(tile) || isarrange(spiral) || 
isarrange(dwindle))
 #define MWFACT                 0.6     /* master width factor [0.1 .. 0.9] */
 #define RESIZEHINTS            True    /* False - respect size hints in tiled 
resizals */
 #define SNAP                   32      /* snap pixel */
@@ -30,6 +31,8 @@ Layout layouts[] = {
        /* symbol               function */
        { "[]=",                tile }, /* first entry is default */
        { "><>",                floating },
+       { "(@)",    spiral }, /* fibonacci spiral */
+       { "[\\]",   dwindle }, /* fibonacci diagonal */
 };
 
 /* key definitions */
diff -r e50c3eb0f55a config.mk
--- a/config.mk Thu Oct 11 20:50:01 2007 +0200
+++ b/config.mk Fri Oct 12 10:50:41 2007 +0200
@@ -2,6 +2,8 @@ VERSION = 4.6
 VERSION = 4.6
 
 # Customize below to fit your system
+
+SRC = fibonacci.c
 
 # paths
 PREFIX = /usr/local
diff -r e50c3eb0f55a fibonacci.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/fibonacci.c       Fri Oct 12 10:50:41 2007 +0200
@@ -0,0 +1,75 @@
+/* See LICENSE file for copyright and license details. */
+#include "dwm.h"
+
+extern void focus(Client *c);
+extern Client *nexttiled(Client *c);
+extern void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
+extern void restack(void);
+
+extern int screen, sx, sy, sw, sh, wax, way, waw, wah;
+extern Client *clients;
+
+/* static */
+
+static void
+fibonacci(int shape) {
+       unsigned int i, n, nx, ny, nw, nh;
+       Client *c;
+
+       nx = wax;
+       ny = 0;
+       nw = waw;
+       nh = wah;
+       for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
+               n++;
+       for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++) {
+               c->ismax = False;
+               if((i % 2 && nh / 2 > 2 * c->border)
+               || (!(i % 2) && nw / 2 > 2 * c->border))
+               {
+                       if(i < n - 1) {
+                               if(i % 2)
+                                       nh /= 2;
+                               else
+                                       nw /= 2;
+                               if((i % 4) == 2 && !shape)
+                                       nx += nw;
+                               else if((i % 4) == 3 && !shape)
+                                       ny += nh;
+                       }
+                       if((i % 4) == 0) {
+                               if(shape)
+                                       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(shape)
+                                       nx += nw;
+                               else
+                                       nx -= nw;
+                       }
+                       if(i == 0)
+                               ny = way;
+               }
+               resize(c, nx, ny, nw - 2 * c->border, nh - 2 * c->border, 
False);
+       }
+       focus(NULL);
+       restack();
+}
+
+/* extern */
+
+void
+dwindle(void) {
+       fibonacci(1);
+}
+
+void
+spiral(void) {
+       fibonacci(0);
+}
diff -r e50c3eb0f55a fibonacci.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/fibonacci.h       Fri Oct 12 10:50:41 2007 +0200
@@ -0,0 +1,3 @@
+/* fibonacci.c */
+void dwindle(void);   /* arranges all windows in a fibonacci diagonal */
+void spiral(void);    /* arranges all windows in a fibonacci spiral */

Reply via email to