cosmetic
[awesome.git] / layout.c
blob8385c1fa4044341ce2bdd6052585ae665d20f4e1
1 /*
2 * layout.c - layout management
4 * Copyright © 2007 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 <X11/Xatom.h>
23 #include <X11/Xutil.h>
25 #include "tag.h"
26 #include "util.h"
27 #include "xutil.h"
28 #include "focus.h"
29 #include "widget.h"
30 #include "window.h"
31 #include "ewmh.h"
32 #include "client.h"
33 #include "screen.h"
34 #include "layouts/tile.h"
35 #include "layouts/max.h"
36 #include "layouts/fibonacci.h"
37 #include "layouts/floating.h"
39 extern AwesomeConf globalconf;
41 #include "layoutgen.h"
43 static void
44 layout_raise_floatings(int screen)
46 Client *c;
48 for(c = globalconf.clients; c; c = c->next)
49 if(c->isfloating && client_isvisible(c, screen))
50 XRaiseWindow(globalconf.display, c->win);
53 /** Arrange windows following current selected layout
54 * \param screen the screen to arrange
56 static void
57 arrange(int screen)
59 Client *c;
60 Layout *curlay = get_current_layout(screen);
61 Window client_win, root_win;
62 int x, y, d;
63 unsigned int m;
65 for(c = globalconf.clients; c; c = c->next)
67 if(client_isvisible(c, screen) && !c->newcomer)
68 client_unban(c);
69 /* we don't touch other screens windows */
70 else if(c->screen == screen || c->newcomer)
71 client_ban(c);
74 curlay->arrange(screen);
76 for(c = globalconf.clients; c; c = c->next)
77 if(c->newcomer && client_isvisible(c, screen))
79 c->newcomer = False;
80 client_unban(c);
83 if(!globalconf.screens[screen].allow_lower_floats)
84 layout_raise_floatings(screen);
86 c = focus_get_current_client(screen);
87 focus(c, True, screen);
88 if(c && XQueryPointer(globalconf.display, RootWindow(globalconf.display, get_phys_screen(screen)),
89 &root_win, &client_win, &x, &y, &d, &d, &m) &&
90 (root_win == None || client_win == None || client_win == root_win))
91 window_grabbuttons(c->screen, c->win, False, False);
93 /* reset status */
94 globalconf.screens[screen].need_arrange = False;
97 Bool
98 layout_refresh(void)
100 int screen;
101 Bool arranged = False;
103 for(screen = 0; screen < get_screen_count(); screen++)
104 if(globalconf.screens[screen].need_arrange)
106 arrange(screen);
107 arranged = True;
110 return arranged;
113 Layout *
114 get_current_layout(int screen)
116 Tag **curtags = get_current_tags(screen);
117 Layout *l = curtags[0]->layout;
118 p_delete(&curtags);
119 return l;
122 void
123 loadawesomeprops(int screen)
125 int i, ntags = 0;
126 char *prop;
127 Tag *tag;
129 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
130 ntags++;
132 prop = p_new(char, ntags + 1);
134 if(xgettextprop(RootWindow(globalconf.display, get_phys_screen(screen)),
135 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
136 prop, ntags + 1))
137 for(i = 0, tag = globalconf.screens[screen].tags; tag && prop[i]; i++, tag = tag->next)
138 if(prop[i] == '1')
139 tag->selected = True;
140 else
141 tag->selected = False;
143 p_delete(&prop);
145 ewmh_update_net_current_desktop(get_phys_screen(screen));
148 void
149 restack(int screen)
151 Client *sel = globalconf.focus->client;
152 Layout *curlay = get_current_layout(screen);
154 if(!sel)
155 return;
157 if(globalconf.screens[screen].allow_lower_floats)
158 XRaiseWindow(globalconf.display, sel->win);
159 else
160 if(sel->isfloating || curlay->arrange == layout_floating)
161 XRaiseWindow(globalconf.display, sel->win);
163 if(globalconf.screens[screen].focus_move_pointer)
164 XWarpPointer(globalconf.display, None, sel->win, 0, 0, 0, 0,
165 sel->geometry.width / 2, sel->geometry.height / 2);
168 void
169 saveawesomeprops(int screen)
171 int i, ntags = 0;
172 char *prop;
173 Tag *tag;
175 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
176 ntags++;
178 prop = p_new(char, ntags + 1);
180 for(i = 0, tag = globalconf.screens[screen].tags; tag; tag = tag->next, i++)
181 prop[i] = tag->selected ? '1' : '0';
183 prop[i] = '\0';
184 XChangeProperty(globalconf.display,
185 RootWindow(globalconf.display, get_phys_screen(screen)),
186 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
187 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
188 p_delete(&prop);
191 /** Set layout for tag
192 * \param screen Screen ID
193 * \param arg Layout specifier
194 * \ingroup ui_callback
196 void
197 uicb_tag_setlayout(int screen, char *arg)
199 Layout *l = globalconf.screens[screen].layouts;
200 Tag *tag, **curtags;
201 int i;
203 if(arg)
205 curtags = get_current_tags(screen);
206 for(i = 0; l && l != curtags[0]->layout; i++, l = l->next);
207 p_delete(&curtags);
209 if(!l)
210 i = 0;
212 i = compute_new_value_from_arg(arg, (double) i);
214 if(i >= 0)
215 for(l = globalconf.screens[screen].layouts; l && i > 0; i--)
216 l = l->next;
217 else
218 for(l = globalconf.screens[screen].layouts; l && i < 0; i++)
219 l = layout_list_prev_cycle(&globalconf.screens[screen].layouts, l);
221 if(!l)
222 l = globalconf.screens[screen].layouts;
225 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
226 if(tag->selected)
227 tag->layout = l;
229 if(globalconf.focus->client)
230 arrange(screen);
232 widget_invalidate_cache(screen, WIDGET_CACHE_LAYOUTS);
234 saveawesomeprops(screen);
237 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80