use draw_color_new()
[awesome.git] / layout.c
blob2de63aea8ff711dc309b67d5ec349209d122b788
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"
36 #include "common/util.h"
38 extern AwesomeConf globalconf;
40 #include "layoutgen.h"
42 static void
43 layout_raise_floatings(int screen)
45 Client *c;
47 for(c = globalconf.clients; c; c = c->next)
48 if(c->isfloating && client_isvisible(c, screen))
49 XRaiseWindow(globalconf.display, c->win);
52 /** Arrange windows following current selected layout
53 * \param screen the screen to arrange
55 static void
56 arrange(int screen)
58 Client *c;
59 Layout *curlay = get_current_layout(screen);
61 for(c = globalconf.clients; c; c = c->next)
63 if(client_isvisible(c, screen) && !c->newcomer)
64 client_unban(c);
65 /* we don't touch other screens windows */
66 else if(c->screen == screen || c->newcomer)
67 client_ban(c);
70 curlay->arrange(screen);
72 for(c = globalconf.clients; c; c = c->next)
73 if(c->newcomer && client_isvisible(c, screen))
75 c->newcomer = False;
76 client_unban(c);
77 if(globalconf.screens[screen].new_get_focus)
78 focus(c, screen, False);
81 layout_raise_floatings(screen);
83 /* if we have a valid client that could be focused but currently no window
84 * are focused, then set the focus on this window */
85 if((c = focus_get_current_client(screen)) && !globalconf.focus->client)
86 focus(c, screen, False);
88 /* reset status */
89 globalconf.screens[screen].need_arrange = False;
92 int
93 layout_refresh(void)
95 int screen;
96 int arranged = 0;
98 for(screen = 0; screen < globalconf.nscreen; screen++)
99 if(globalconf.screens[screen].need_arrange)
101 arrange(screen);
102 arranged++;
105 return arranged;
108 Layout *
109 get_current_layout(int screen)
111 Tag **curtags = get_current_tags(screen);
112 Layout *l = curtags[0]->layout;
113 p_delete(&curtags);
114 return l;
117 void
118 loadawesomeprops(int screen)
120 int i, ntags = 0;
121 char *prop;
122 Tag *tag;
124 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
125 ntags++;
127 prop = p_new(char, ntags + 1);
129 if(xgettextprop(RootWindow(globalconf.display, get_phys_screen(screen)),
130 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
131 prop, ntags + 1))
132 for(i = 0, tag = globalconf.screens[screen].tags; tag && prop[i]; i++, tag = tag->next)
133 tag_view_byindex(screen, i, prop[i] == '1');
135 p_delete(&prop);
138 void
139 saveawesomeprops(int screen)
141 int i, ntags = 0;
142 char *prop;
143 Tag *tag;
145 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
146 ntags++;
148 prop = p_new(char, ntags + 1);
150 for(i = 0, tag = globalconf.screens[screen].tags; tag; tag = tag->next, i++)
151 prop[i] = tag->selected ? '1' : '0';
153 prop[i] = '\0';
154 XChangeProperty(globalconf.display,
155 RootWindow(globalconf.display, get_phys_screen(screen)),
156 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
157 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
158 p_delete(&prop);
161 /** Set layout for tag
162 * \param screen Screen ID
163 * \param arg Layout specifier
164 * \ingroup ui_callback
166 void
167 uicb_tag_setlayout(int screen, char *arg)
169 Layout *l = globalconf.screens[screen].layouts;
170 Tag *tag, **curtags;
171 int i;
173 if(arg)
175 curtags = get_current_tags(screen);
176 for(i = 0; l && l != curtags[0]->layout; i++, l = l->next);
177 p_delete(&curtags);
179 if(!l)
180 i = 0;
182 i = compute_new_value_from_arg(arg, (double) i);
184 if(i >= 0)
185 for(l = globalconf.screens[screen].layouts; l && i > 0; i--)
186 l = l->next;
187 else
188 for(l = globalconf.screens[screen].layouts; l && i < 0; i++)
189 l = layout_list_prev_cycle(&globalconf.screens[screen].layouts, l);
191 if(!l)
192 l = globalconf.screens[screen].layouts;
195 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
196 if(tag->selected)
197 tag->layout = l;
199 if(globalconf.focus->client)
200 arrange(screen);
202 widget_invalidate_cache(screen, WIDGET_CACHE_LAYOUTS);
204 saveawesomeprops(screen);
207 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80