fix typo
[awesome.git] / layout.c
blob29e023b99109ebecfa85854d34d6c6f6df253fa2
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 "screen.h"
26 #include "layout.h"
27 #include "tag.h"
28 #include "util.h"
29 #include "statusbar.h"
30 #include "layouts/floating.h"
32 /* extern */
33 extern Client *clients, *sel; /* global client list */
35 /** Arrange windows following current selected layout
36 * \param disp display ref
37 * \param drawcontext drawcontext ref
38 * \param awesomeconf awesome config
40 void
41 arrange(Display * disp, DC *drawcontext, awesome_config *awesomeconf)
43 Client *c;
45 for(c = clients; c; c = c->next)
47 if(isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
48 unban(c);
49 /* we don't touch other screens windows */
50 else if(c->screen == awesomeconf->screen)
51 ban(c);
53 awesomeconf->current_layout->arrange(disp, awesomeconf);
54 focus(disp, drawcontext, NULL, True, awesomeconf);
55 restack(disp, drawcontext, awesomeconf);
58 void
59 uicb_focusnext(Display *disp __attribute__ ((unused)),
60 DC *drawcontext,
61 awesome_config * awesomeconf,
62 const char *arg __attribute__ ((unused)))
64 Client *c;
66 if(!sel)
67 return;
68 for(c = sel->next; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->next);
69 if(!c)
70 for(c = clients; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->next);
71 if(c)
73 focus(c->display, drawcontext, c, True, awesomeconf);
74 restack(c->display, drawcontext, awesomeconf);
78 void
79 uicb_focusprev(Display *disp __attribute__ ((unused)),
80 DC *drawcontext,
81 awesome_config *awesomeconf,
82 const char *arg __attribute__ ((unused)))
84 Client *c;
86 if(!sel)
87 return;
88 for(c = sel->prev; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->prev);
89 if(!c)
91 for(c = clients; c && c->next; c = c->next);
92 for(; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->prev);
94 if(c)
96 focus(c->display, drawcontext, c, True, awesomeconf);
97 restack(c->display, drawcontext, awesomeconf);
101 void
102 loadawesomeprops(Display *disp, awesome_config * awesomeconf)
104 int i;
105 char *prop;
107 prop = p_new(char, awesomeconf->ntags + 1);
109 if(xgettextprop(disp, RootWindow(disp, awesomeconf->phys_screen), AWESOMEPROPS_ATOM(disp), prop, awesomeconf->ntags + 1))
110 for(i = 0; i < awesomeconf->ntags && prop[i]; i++)
111 awesomeconf->tags[i].selected = prop[i] == '1';
113 p_delete(&prop);
116 void
117 restack(Display * disp, DC * drawcontext, awesome_config *awesomeconf)
119 Client *c;
120 XEvent ev;
121 XWindowChanges wc;
123 drawstatusbar(disp, drawcontext, awesomeconf);
124 if(!sel)
125 return;
126 if(sel->isfloating || IS_ARRANGE(layout_floating))
127 XRaiseWindow(disp, sel->win);
128 if(!IS_ARRANGE(layout_floating))
130 wc.stack_mode = Below;
131 wc.sibling = awesomeconf->statusbar.window;
132 if(!sel->isfloating)
134 XConfigureWindow(disp, sel->win, CWSibling | CWStackMode, &wc);
135 wc.sibling = sel->win;
137 for(c = clients; c; c = c->next)
139 if(!IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags) || c == sel)
140 continue;
141 XConfigureWindow(disp, c->win, CWSibling | CWStackMode, &wc);
142 wc.sibling = c->win;
145 XSync(disp, False);
146 while(XCheckMaskEvent(disp, EnterWindowMask, &ev));
149 void
150 saveawesomeprops(Display *disp, awesome_config *awesomeconf)
152 int i;
153 char *prop;
155 prop = p_new(char, awesomeconf->ntags + 1);
156 for(i = 0; i < awesomeconf->ntags; i++)
157 prop[i] = awesomeconf->tags[i].selected ? '1' : '0';
158 prop[i] = '\0';
159 XChangeProperty(disp, RootWindow(disp, awesomeconf->phys_screen),
160 AWESOMEPROPS_ATOM(disp), XA_STRING, 8,
161 PropModeReplace, (unsigned char *) prop, i);
162 p_delete(&prop);
165 void
166 uicb_setlayout(Display *disp,
167 DC *drawcontext,
168 awesome_config * awesomeconf,
169 const char *arg)
171 int i;
172 Client *c;
174 if(arg)
176 for(i = 0; i < awesomeconf->nlayouts && &awesomeconf->layouts[i] != awesomeconf->current_layout; i++);
177 i = compute_new_value_from_arg(arg, (double) i);
178 if(i >= awesomeconf->nlayouts)
179 i = 0;
180 else if(i < 0)
181 i = awesomeconf->nlayouts - 1;
183 else
184 i = 0;
186 awesomeconf->current_layout = &awesomeconf->layouts[i];
188 for(c = clients; c; c = c->next)
189 c->ftview = True;
191 if(sel)
192 arrange(disp, drawcontext, awesomeconf);
193 else
194 drawstatusbar(disp, drawcontext, awesomeconf);
196 saveawesomeprops(disp, awesomeconf);
198 for(i = 0; i < awesomeconf->ntags; i++)
199 if (awesomeconf->tags[i].selected)
200 awesomeconf->tags[i].layout = awesomeconf->current_layout;
203 static void
204 maximize(int x, int y, int w, int h, DC *drawcontext, awesome_config *awesomeconf)
206 if(!sel)
207 return;
209 if((sel->ismax = !sel->ismax))
211 sel->wasfloating = sel->isfloating;
212 sel->isfloating = True;
213 sel->rx = sel->x;
214 sel->ry = sel->y;
215 sel->rw = sel->w;
216 sel->rh = sel->h;
217 resize(sel, x, y, w, h, awesomeconf, True);
219 else if(sel->wasfloating)
220 resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, awesomeconf, True);
221 else
222 sel->isfloating = False;
224 arrange(sel->display, drawcontext, awesomeconf);
227 void
228 uicb_togglemax(Display *disp,
229 DC *drawcontext,
230 awesome_config *awesomeconf,
231 const char *arg __attribute__ ((unused)))
233 ScreenInfo *si = get_screen_info(disp, awesomeconf->screen, &awesomeconf->statusbar);
235 maximize(si[awesomeconf->screen].x_org, si[awesomeconf->screen].y_org,
236 si[awesomeconf->screen].width - 2 * awesomeconf->borderpx,
237 si[awesomeconf->screen].height - 2 * awesomeconf->borderpx,
238 drawcontext, awesomeconf);
239 XFree(si);
242 void
243 uicb_toggleverticalmax(Display *disp,
244 DC *drawcontext,
245 awesome_config *awesomeconf,
246 const char *arg __attribute__ ((unused)))
248 ScreenInfo *si = get_screen_info(disp, awesomeconf->screen, &awesomeconf->statusbar);
250 if(sel)
251 maximize(sel->x, si[awesomeconf->screen].y_org,
252 sel->w, si[awesomeconf->screen].height - 2 * awesomeconf->borderpx,
253 drawcontext, awesomeconf);
254 XFree(si);
258 void
259 uicb_togglehorizontalmax(Display *disp,
260 DC *drawcontext,
261 awesome_config *awesomeconf,
262 const char *arg __attribute__ ((unused)))
264 ScreenInfo *si = get_screen_info(disp, awesomeconf->screen, &awesomeconf->statusbar);
266 if(sel)
267 maximize(si[awesomeconf->screen].x_org, sel->y,
268 si[awesomeconf->screen].height - 2 * awesomeconf->borderpx, sel->h,
269 drawcontext, awesomeconf);
270 XFree(si);
273 void
274 uicb_zoom(Display *disp __attribute__ ((unused)),
275 DC *drawcontext __attribute__ ((unused)),
276 awesome_config *awesomeconf,
277 const char *arg __attribute__ ((unused)))
279 if(!sel)
280 return;
281 detach(sel);
282 attach(sel);
283 focus(sel->display, drawcontext, sel, True, awesomeconf);
284 arrange(sel->display, drawcontext, awesomeconf);