rename some screens function
[awesome.git] / layout.c
blob8cdc0e3c6b35795f1894414b3183e8d474c852b2
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 "xutil.h"
27 #include "focus.h"
28 #include "widget.h"
29 #include "window.h"
30 #include "client.h"
31 #include "screen.h"
32 #include "layouts/tile.h"
33 #include "layouts/max.h"
34 #include "layouts/fibonacci.h"
35 #include "layouts/floating.h"
37 extern AwesomeConf globalconf;
39 #include "layoutgen.h"
41 static void
42 layout_raise_floatings(int screen)
44 Client *c;
46 for(c = globalconf.clients; c; c = c->next)
47 if(c->isfloating && client_isvisible(c, screen))
48 XRaiseWindow(globalconf.display, c->win);
51 /** Arrange windows following current selected layout
52 * \param screen the screen to arrange
54 static void
55 arrange(int screen)
57 Client *c;
58 Layout *curlay = get_current_layout(screen);
60 for(c = globalconf.clients; c; c = c->next)
62 if(client_isvisible(c, screen) && !c->newcomer)
63 client_unban(c);
64 /* we don't touch other screens windows */
65 else if(c->screen == screen || c->newcomer)
66 client_ban(c);
69 curlay->arrange(screen);
71 for(c = globalconf.clients; c; c = c->next)
72 if(c->newcomer && client_isvisible(c, screen))
74 c->newcomer = False;
75 client_unban(c);
76 if(globalconf.screens[screen].new_get_focus)
77 client_focus(c, screen, False);
80 layout_raise_floatings(screen);
82 /* if we have a valid client that could be focused but currently no window
83 * are focused, then set the focus on this window */
84 if((c = focus_get_current_client(screen)) && !globalconf.focus->client)
85 client_focus(c, screen, False);
87 /* reset status */
88 globalconf.screens[screen].need_arrange = False;
91 int
92 layout_refresh(void)
94 int screen;
95 int arranged = 0;
97 for(screen = 0; screen < globalconf.nscreen; screen++)
98 if(globalconf.screens[screen].need_arrange)
100 arrange(screen);
101 arranged++;
104 return arranged;
107 Layout *
108 get_current_layout(int screen)
110 Tag **curtags = tags_get_current(screen);
111 Layout *l = curtags[0]->layout;
112 p_delete(&curtags);
113 return l;
116 void
117 loadawesomeprops(int screen)
119 int i, ntags = 0;
120 char *prop;
121 Tag *tag;
123 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
124 ntags++;
126 prop = p_new(char, ntags + 1);
128 if(xgettextprop(RootWindow(globalconf.display, get_phys_screen(screen)),
129 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
130 prop, ntags + 1))
131 for(i = 0, tag = globalconf.screens[screen].tags; tag && prop[i]; i++, tag = tag->next)
132 tag_view_byindex(screen, i, prop[i] == '1');
134 p_delete(&prop);
137 void
138 saveawesomeprops(int screen)
140 int i, ntags = 0;
141 char *prop;
142 Tag *tag;
144 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
145 ntags++;
147 prop = p_new(char, ntags + 1);
149 for(i = 0, tag = globalconf.screens[screen].tags; tag; tag = tag->next, i++)
150 prop[i] = tag->selected ? '1' : '0';
152 prop[i] = '\0';
153 XChangeProperty(globalconf.display,
154 RootWindow(globalconf.display, get_phys_screen(screen)),
155 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
156 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
157 p_delete(&prop);
160 /** Set layout for tag
161 * \param screen Screen ID
162 * \param arg Layout specifier
163 * \ingroup ui_callback
165 void
166 uicb_tag_setlayout(int screen, char *arg)
168 Layout *l = globalconf.screens[screen].layouts;
169 Tag *tag, **curtags;
170 int i;
172 if(arg)
174 curtags = tags_get_current(screen);
175 for(i = 0; l && l != curtags[0]->layout; i++, l = l->next);
176 p_delete(&curtags);
178 if(!l)
179 i = 0;
181 i = compute_new_value_from_arg(arg, (double) i);
183 if(i >= 0)
184 for(l = globalconf.screens[screen].layouts; l && i > 0; i--)
185 l = l->next;
186 else
187 for(l = globalconf.screens[screen].layouts; l && i < 0; i++)
188 l = layout_list_prev_cycle(&globalconf.screens[screen].layouts, l);
190 if(!l)
191 l = globalconf.screens[screen].layouts;
194 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
195 if(tag->selected)
196 tag->layout = l;
198 if(globalconf.focus->client)
199 arrange(screen);
201 widget_invalidate_cache(screen, WIDGET_CACHE_LAYOUTS);
203 saveawesomeprops(screen);
206 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80