add compute_new_value_from_arg() to do the +/- job in uicb fcts
[awesome.git] / layouts / spiral.c
blob7685d394903a3d91279a0c0c9ad98ea2d26b00d7
1 /*
2 * spiral.c - spiral layout
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
5 * Copyright © 2007 Jeroen Schot <schot@a-eskwadraat.nl>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "awesome.h"
24 #include "layout.h"
25 #include "tag.h"
26 #include "spiral.h"
28 extern Client *clients; /* global client list */
30 static void
31 fibonacci(Display *disp, awesome_config *awesomeconf, int shape)
33 int n, nx, ny, nh, nw, i;
34 Client *c;
36 nx = get_windows_area_x(awesomeconf->statusbar);
37 ny = 0;
38 nw = get_windows_area_width(disp, awesomeconf->statusbar);
39 nh = get_windows_area_height(disp, awesomeconf->statusbar);
40 for(n = 0, c = clients; c; c = c->next)
41 if(IS_TILED(c, awesomeconf->selected_tags, awesomeconf->ntags))
42 n++;
43 for(i = 0, c = clients; c; c = c->next)
45 c->ismax = False;
46 if((i % 2 && nh / 2 > 2 * c->border)
47 || (!(i % 2) && nw / 2 > 2 * c->border))
49 if(i < n - 1)
51 if(i % 2)
52 nh /= 2;
53 else
54 nw /= 2;
55 if((i % 4) == 2 && !shape)
56 ny += nh;
58 if((i % 4) == 0)
60 if(shape)
61 ny += nh;
62 else
63 ny -= nh;
65 else if((i % 4) == 1)
66 nx += nw;
67 else if((i % 4) == 2)
68 ny += nh;
69 else if((i % 4) == 3)
71 if(shape)
72 nx += nw;
73 else
74 nx -= nw;
76 if(i == 0)
77 ny = get_windows_area_y(awesomeconf->statusbar);
78 i++;
80 resize(c, nx, ny, nw - 2 * c->border, nh - 2 * c->border, False);
85 void
86 dwindle(Display *disp, awesome_config *awesomeconf)
88 fibonacci(disp, awesomeconf, 1);
91 void
92 spiral(Display *disp, awesome_config *awesomeconf)
94 fibonacci(disp, awesomeconf, 0);