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>
31 #include "statusbar.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 const NameFuncLink LayoutsList
[] =
41 {"tile", layout_tile
},
42 {"tileleft", layout_tileleft
},
44 {"spiral", layout_spiral
},
45 {"dwindle", layout_dwindle
},
46 {"floating", layout_floating
},
50 /** Find the index of the first currently selected tag
51 * \param screen the screen to search
54 #warning this function is bugged and should be replaced
56 get_current_tag(int screen
)
60 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
67 /** Arrange windows following current selected layout
68 * \param screen the screen to arrange
74 Tag
*curtag
= get_current_tag(screen
);
76 for(c
= globalconf
.clients
; c
; c
= c
->next
)
78 if(client_isvisible(c
, screen
))
80 /* we don't touch other screens windows */
81 else if(c
->screen
== screen
)
85 curtag
->layout
->arrange(screen
);
86 focus(focus_get_latest_client_for_tag(screen
, curtag
),
92 get_current_layout(int screen
)
96 if ((curtag
= get_current_tag(screen
)))
97 return curtag
->layout
;
102 /** Send focus to next client in stack
103 * \param screen Screen ID
105 * \ingroup ui_callback
108 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
110 Client
*c
, *sel
= globalconf
.focus
->client
;
114 for(c
= sel
->next
; c
&& !client_isvisible(c
, screen
); c
= c
->next
);
116 for(c
= globalconf
.clients
; c
&& !client_isvisible(c
, screen
); c
= c
->next
);
119 focus(c
, True
, screen
);
124 /** Send focus to previous client in stack
125 * \param screen Screen ID
127 * \ingroup ui_callback
130 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
132 Client
*c
, *sel
= globalconf
.focus
->client
;
136 for(c
= sel
->prev
; c
&& !client_isvisible(c
, screen
); c
= c
->prev
);
139 for(c
= globalconf
.clients
; c
&& c
->next
; c
= c
->next
);
140 for(; c
&& !client_isvisible(c
, screen
); c
= c
->prev
);
144 focus(c
, True
, screen
);
150 loadawesomeprops(int screen
)
156 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
159 prop
= p_new(char, ntags
+ 1);
161 if(xgettextprop(globalconf
.display
,
162 RootWindow(globalconf
.display
, get_phys_screen(screen
)),
163 AWESOMEPROPS_ATOM(globalconf
.display
), prop
, ntags
+ 1))
164 for(i
= 0, tag
= globalconf
.screens
[screen
].tags
; tag
&& prop
[i
]; i
++, tag
= tag
->next
)
166 tag
->selected
= True
;
168 tag
->selected
= False
;
176 Client
*c
, *sel
= globalconf
.focus
->client
;
180 statusbar_draw(screen
);
183 if(globalconf
.screens
[screen
].allow_lower_floats
)
184 XRaiseWindow(globalconf
.display
, sel
->win
);
187 if(sel
->isfloating
||
188 get_current_layout(screen
)->arrange
== layout_floating
)
189 XRaiseWindow(sel
->display
, sel
->win
);
190 if(!(get_current_layout(screen
)->arrange
== layout_floating
))
192 wc
.stack_mode
= Below
;
193 wc
.sibling
= globalconf
.screens
[screen
].statusbar
->window
;
196 XConfigureWindow(sel
->display
, sel
->win
, CWSibling
| CWStackMode
, &wc
);
197 wc
.sibling
= sel
->win
;
199 for(c
= globalconf
.clients
; c
; c
= c
->next
)
201 if(!IS_TILED(c
, screen
) || c
== sel
)
203 XConfigureWindow(globalconf
.display
, c
->win
, CWSibling
| CWStackMode
, &wc
);
208 if(globalconf
.screens
[screen
].focus_move_pointer
)
209 XWarpPointer(globalconf
.display
, None
, sel
->win
, 0, 0, 0, 0, sel
->w
/ 2, sel
->h
/ 2);
210 XSync(globalconf
.display
, False
);
211 while(XCheckMaskEvent(globalconf
.display
, EnterWindowMask
, &ev
));
215 saveawesomeprops(int screen
)
221 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
224 prop
= p_new(char, ntags
+ 1);
226 for(i
= 0, tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
, i
++)
227 prop
[i
] = tag
->selected
? '1' : '0';
230 XChangeProperty(globalconf
.display
,
231 RootWindow(globalconf
.display
, get_phys_screen(screen
)),
232 AWESOMEPROPS_ATOM(globalconf
.display
), XA_STRING
, 8,
233 PropModeReplace
, (unsigned char *) prop
, i
);
237 /** Set layout for tag
238 * \param screen Screen ID
239 * \param arg Layout specifier
240 * \ingroup ui_callback
243 uicb_tag_setlayout(int screen
, char *arg
)
245 Layout
*l
= globalconf
.screens
[screen
].layouts
;
251 for(i
= 0; l
&& l
!= get_current_layout(screen
); i
++, l
= l
->next
);
254 for(i
= compute_new_value_from_arg(arg
, (double) i
),
255 l
= globalconf
.screens
[screen
].layouts
; l
&& i
> 0; i
--)
258 l
= globalconf
.screens
[screen
].layouts
;
261 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
265 if(globalconf
.focus
->client
)
268 statusbar_draw(screen
);
270 saveawesomeprops(screen
);
274 maximize(int x
, int y
, int w
, int h
, int screen
)
276 Client
*sel
= globalconf
.focus
->client
;
281 if((sel
->ismax
= !sel
->ismax
))
283 sel
->wasfloating
= sel
->isfloating
;
284 sel
->isfloating
= True
;
285 client_resize(sel
, x
, y
, w
, h
, True
, !sel
->isfloating
);
287 else if(sel
->wasfloating
)
288 client_resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, True
, False
);
290 sel
->isfloating
= False
;
295 /** Toggle maximize for client
296 * \param screen Screen ID
298 * \ingroup ui_callback
301 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
303 ScreenInfo
*si
= get_screen_info(screen
,
304 globalconf
.screens
[screen
].statusbar
,
305 &globalconf
.screens
[screen
].padding
);
307 maximize(si
[screen
].x_org
, si
[screen
].y_org
,
308 si
[screen
].width
- 2 * globalconf
.screens
[screen
].borderpx
,
309 si
[screen
].height
- 2 * globalconf
.screens
[screen
].borderpx
,
314 /** Toggle vertical maximize for client
315 * \param screen Screen ID
317 * \ingroup ui_callback
320 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
322 Client
*sel
= globalconf
.focus
->client
;
323 ScreenInfo
*si
= get_screen_info(screen
,
324 globalconf
.screens
[screen
].statusbar
,
325 &globalconf
.screens
[screen
].padding
);
331 si
[screen
].height
- 2 * globalconf
.screens
[screen
].borderpx
,
337 /** Toggle horizontal maximize for client
338 * \param screen Screen ID
340 * \ingroup ui_callback
343 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
345 Client
*sel
= globalconf
.focus
->client
;
346 ScreenInfo
*si
= get_screen_info(screen
,
347 globalconf
.screens
[screen
].statusbar
,
348 &globalconf
.screens
[screen
].padding
);
351 maximize(si
[screen
].x_org
,
353 si
[screen
].height
- 2 * globalconf
.screens
[screen
].borderpx
,
360 * \param screen Screen ID
362 * \ingroup ui_callback
365 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
367 Client
*sel
= globalconf
.focus
->client
;
369 if(globalconf
.clients
== sel
)
370 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
378 focus(sel
, True
, screen
);
382 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80