Skip to content

Commit

Permalink
add fibonacci layout
Browse files Browse the repository at this point in the history
  • Loading branch information
prabirshrestha committed Dec 9, 2019
1 parent 2622159 commit cc28e62
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ options:
@echo CC $<
@${CC} -c ${CFLAGS} $<

${OBJS}: config.h config.mk bstack.c grid.c gaplessgrid.c
${OBJS}: config.h config.mk bstack.c grid.c gaplessgrid.c fibonacci.c

config.h: config.def.h
@echo creating $@ from config.def.h
Expand Down
5 changes: 5 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static float mfact = 0.55; /* factor of master area size [0.05..0.95] */
#include "bstack.c"
#include "grid.c"
#include "gaplessgrid.c"
#include "fibonacci.c"

static Layout layouts[] = {
/* symbol arrange function */
Expand All @@ -53,6 +54,8 @@ static Layout layouts[] = {
{ "TTT", bstack },
{ "###", gaplessgrid },
{ "+++", grid },
{ "(@)", spiral },
{ "[\\]", dwindle },
};

/* key definitions */
Expand Down Expand Up @@ -91,6 +94,8 @@ static Key keys[] = {
{ MODKEY, 'B', setlayout, {.v = &layouts[3]} },
{ MODKEY, 'G', setlayout, {.v = &layouts[4]} },
{ MODKEY|MOD_SHIFT, 'G', setlayout, {.v = &layouts[5]} },
{ MODKEY, 'D', setlayout, {.v = &layouts[6]} },
{ MODKEY|MOD_SHIFT, 'D', setlayout, {.v = &layouts[7]} },
{ MODKEY|MOD_CONTROL, VK_SPACE, setlayout, {0} },
{ MODKEY|MOD_SHIFT, VK_SPACE, togglefloating, {0} },
{ MODKEY, 'N', toggleborder, {0} },
Expand Down
66 changes: 66 additions & 0 deletions fibonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
void
fibonacci(int s) {
unsigned int i, n, nx, ny, nw, nh;
Client *c;

for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++);
if(n == 0)
return;

nx = wx;
ny = 0;
nw = ww;
nh = wh;

for(i = 0, c = nexttiled(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 = ww * mfact;
ny = wy;
}
else if(i == 1)
nw = ww - nw;
i++;
}
resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw);
}
}

void
dwindle(void) {
fibonacci(1);
}

void
spiral(void) {
fibonacci(0);
}

0 comments on commit cc28e62

Please sign in to comment.