it's pretty ok
[awesome.git] / layouts / spiral.c
blob70de4d78201b25405e19f1faa83ef4832d075312
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->screen, awesomeconf->selected_tags, awesomeconf->ntags))
42 n++;
44 for(i = 0, c = clients; c; c = c->next)
46 if(!IS_TILED(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags))
47 continue;
49 c->ismax = False;
50 if((i % 2 && nh / 2 > 2 * c->border)
51 || (!(i % 2) && nw / 2 > 2 * c->border))
53 if(i < n - 1)
55 if(i % 2)
56 nh /= 2;
57 else
58 nw /= 2;
59 if((i % 4) == 2 && !shape)
60 ny += nh;
62 if((i % 4) == 0)
64 if(shape)
65 ny += nh;
66 else
67 ny -= nh;
69 else if((i % 4) == 1)
70 nx += nw;
71 else if((i % 4) == 2)
72 ny += nh;
73 else if((i % 4) == 3)
75 if(shape)
76 nx += nw;
77 else
78 nx -= nw;
80 if(i == 0)
81 ny = get_windows_area_y(awesomeconf->statusbar);
82 i++;
84 resize(c, nx, ny, nw - 2 * c->border, nh - 2 * c->border, False);
89 void
90 dwindle(Display *disp, awesome_config *awesomeconf)
92 fibonacci(disp, awesomeconf, 1);
95 void
96 spiral(Display *disp, awesome_config *awesomeconf)
98 fibonacci(disp, awesomeconf, 0);