Compute the rule only one time
[awesome.git] / layouts / fibonacci.c
blob11eb6db366d5a67a2f0ff613b5348b9190f8551b
1 /*
2 * fibonacci.c - fibonacci layout
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "screen.h"
23 #include "tag.h"
24 #include "client.h"
25 #include "layouts/fibonacci.h"
26 #include "common/util.h"
28 extern AwesomeConf globalconf;
30 static void
31 layout_fibonacci(int screen, int shape)
33 int n = 0, i = 0;
34 Client *c;
35 area_t geometry, area;
36 geometry = area = screen_get_area(screen,
37 globalconf.screens[screen].statusbar,
38 &globalconf.screens[screen].padding);
40 for(c = globalconf.clients; c; c = c->next)
41 if(IS_TILED(c, screen))
42 n++;
43 for(c = globalconf.clients; c; c = c->next)
44 if(IS_TILED(c, screen))
46 c->ismax = False;
47 if((i % 2 && geometry.height / 2 > 2 * c->border)
48 || (!(i % 2) && geometry.width / 2 > 2 * c->border))
50 if(i < n - 1)
52 if(i % 2)
53 geometry.height /= 2;
54 else
55 geometry.width /= 2;
56 if((i % 4) == 2 && !shape)
57 geometry.x += geometry.width;
58 else if((i % 4) == 3 && !shape)
59 geometry.y += geometry.height;
61 if((i % 4) == 0)
63 if(shape)
64 geometry.y += geometry.height;
65 else
66 geometry.y -= geometry.height;
68 else if((i % 4) == 1)
69 geometry.x += geometry.width;
70 else if((i % 4) == 2)
71 geometry.y += geometry.height;
72 else if((i % 4) == 3)
74 if(shape)
75 geometry.x += geometry.width;
76 else
77 geometry.x -= geometry.width;
79 if(i == 0)
80 geometry.y = area.y;
81 i++;
83 geometry.width -= 2 * c->border;
84 geometry.height -= 2 * c->border;
85 if(globalconf.screens[screen].resize_hints)
86 client_resize(c,
87 client_geometry_hints(c,
88 client_titlebar_update_position(c,
89 geometry)));
90 else
91 client_resize(c, client_titlebar_update_position(c, geometry));
92 geometry.width += 2 * c->border;
93 geometry.height += 2 * c->border;
97 void
98 layout_spiral(int screen)
100 layout_fibonacci(screen, 0);
103 void
104 layout_dwindle(int screen)
106 layout_fibonacci(screen, 1);
109 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80