From b9320be372be84f8b9140fce62b77c7462490461 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 14 Dec 2007 17:05:29 +0100 Subject: [PATCH] add spiral and dwindle layouts (fibonacci) --- Makefile | 2 +- awesomerc | 2 + config.c | 3 ++ config.mk | 2 +- layouts/fibonacci.c | 102 ++++++++++++++++++++++++++++++++++++++++++++ layouts/fibonacci.h | 31 ++++++++++++++ 6 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 layouts/fibonacci.c create mode 100644 layouts/fibonacci.h diff --git a/Makefile b/Makefile index c4050af8..494ca748 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ defconfig.h: awesomerc @echo generating defconfig.h from awesomerc @echo "#define AWESOME_DEFAULT_CONFIG \\" > defconfig.h @echo -n "\"" >> defconfig.h - @sed 's/$$/ \\/;s/"/\\"/g' awesomerc >> defconfig.h + @sed 's,\\,\\\\,g;s/$$/ \\/;s/"/\\"/g' awesomerc >> defconfig.h @echo "\"" >> defconfig.h awesome: defconfig.h ${OBJ} diff --git a/awesomerc b/awesomerc index a65bf5d4..a553756d 100644 --- a/awesomerc +++ b/awesomerc @@ -17,6 +17,8 @@ screen 0 layout tile { symbol = "[]=" } layout tileleft { symbol = "=[]" } layout max { symbol = "[ ]" } + layout spiral { symbol = "(@)" } + layout dwindle { symbol = "[\\]" } layout floating { symbol = "><>" } } } diff --git a/config.c b/config.c index 67f5f9c5..454d07af 100644 --- a/config.c +++ b/config.c @@ -35,6 +35,7 @@ #include "layouts/tile.h" #include "layouts/floating.h" #include "layouts/max.h" +#include "layouts/fibonacci.h" #include "defconfig.h" #define AWESOME_CONFIG_FILE ".awesomerc" @@ -88,6 +89,8 @@ static const NameFuncLink LayoutsList[] = {"tile", layout_tile}, {"tileleft", layout_tileleft}, {"max", layout_max}, + {"spiral", layout_spiral}, + {"dwindle", layout_dwindle}, {"floating", layout_floating}, {NULL, NULL} }; diff --git a/config.mk b/config.mk index 582342b0..d55d7718 100644 --- a/config.mk +++ b/config.mk @@ -5,7 +5,7 @@ RELEASE = "Productivity Breaker" # Customize below to fit your system # additional layouts -LAYOUTS = layouts/tile.c layouts/floating.c layouts/max.c +LAYOUTS = layouts/tile.c layouts/floating.c layouts/max.c layouts/fibonacci.c # paths PREFIX = /usr/local diff --git a/layouts/fibonacci.c b/layouts/fibonacci.c new file mode 100644 index 00000000..7b34380a --- /dev/null +++ b/layouts/fibonacci.c @@ -0,0 +1,102 @@ +/* + * fibonacci.c - fibonacci layout + * + * Copyright © 2007 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include "screen.h" +#include "tag.h" +#include "util.h" +#include "layouts/fibonacci.h" + +static void +layout_fibonacci(awesome_config *awesomeconf, int screen, int shape) +{ + int n = 0, i = 0, nx, ny, nw, nh; + Client *c; + ScreenInfo *si = get_screen_info(awesomeconf->display, screen, + &awesomeconf->screens[screen].statusbar, + &awesomeconf->screens[screen].padding); + + nx = si[screen].x_org; + ny = si[screen].y_org; + nw = si[screen].width; + nh = si[screen].height; + + for(c = awesomeconf->clients; c; c = c->next) + if(IS_TILED(c, &awesomeconf->screens[screen], screen)) + n++; + for(c = awesomeconf->clients; c; c = c->next) + if(IS_TILED(c, &awesomeconf->screens[screen], screen)) + { + 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 = si[screen].y_org; + i++; + } + client_resize(c, nx, ny, nw - 2 * c->border, nh - 2 * c->border, awesomeconf, + awesomeconf->screens[screen].resize_hints, False); + } + p_delete(&si); +} + +void +layout_spiral(awesome_config *awesomeconf, int screen) +{ + layout_fibonacci(awesomeconf, screen, 0); +} + +void +layout_dwindle(awesome_config *awesomeconf, int screen) +{ + layout_fibonacci(awesomeconf, screen, 1); +} + +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 diff --git a/layouts/fibonacci.h b/layouts/fibonacci.h new file mode 100644 index 00000000..c8a61efd --- /dev/null +++ b/layouts/fibonacci.h @@ -0,0 +1,31 @@ +/* + * fibonacci.h - fibonacci layout header + * + * Copyright © 2007 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef AWESOME_FIBONACCI_H +#define AWESOME_FIBONACCI_H + +#include "common.h" + +LAYOUT_PROTO(layout_spiral); +LAYOUT_PROTO(layout_dwindle); + +#endif +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99