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>
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 const name_func_link_t LayoutsList
[] =
43 {"tile", layout_tile
},
44 {"tileleft", layout_tileleft
},
46 {"spiral", layout_spiral
},
47 {"dwindle", layout_dwindle
},
48 {"floating", layout_floating
},
52 /** Arrange windows following current selected layout
53 * \param screen the screen to arrange
59 Tag
**curtags
= get_current_tags(screen
);
60 Window client_win
, root_win
;
64 for(c
= globalconf
.clients
; c
; c
= c
->next
)
66 if(client_isvisible(c
, screen
) && !c
->newcomer
)
68 /* we don't touch other screens windows */
69 else if(c
->screen
== screen
|| c
->newcomer
)
73 curtags
[0]->layout
->arrange(screen
);
74 for(c
= globalconf
.clients
; c
; c
= c
->next
)
75 if(c
->newcomer
&& client_isvisible(c
, screen
))
80 c
= focus_get_current_client(screen
);
81 focus(c
, True
, screen
);
82 if(c
&& XQueryPointer(globalconf
.display
, RootWindow(globalconf
.display
, get_phys_screen(screen
)),
83 &root_win
, &client_win
, &x
, &y
, &d
, &d
, &m
) &&
84 (root_win
== None
|| client_win
== None
|| client_win
== root_win
))
85 window_grabbuttons(c
->screen
, c
->win
, False
, False
);
93 get_current_layout(int screen
)
95 Tag
**curtags
= get_current_tags(screen
);
96 Layout
*l
= curtags
[0]->layout
;
101 /** Send focus to next client in stack
102 * \param screen Screen ID
104 * \ingroup ui_callback
107 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
109 Client
*c
, *sel
= globalconf
.focus
->client
;
113 for(c
= sel
->next
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
115 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
118 focus(c
, True
, screen
);
123 /** Send focus to previous client in stack
124 * \param screen Screen ID
126 * \ingroup ui_callback
129 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
133 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
135 focus(prev
, True
, screen
);
141 loadawesomeprops(int screen
)
147 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
150 prop
= p_new(char, ntags
+ 1);
152 if(xgettextprop(RootWindow(globalconf
.display
, get_phys_screen(screen
)),
153 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
155 for(i
= 0, tag
= globalconf
.screens
[screen
].tags
; tag
&& prop
[i
]; i
++, tag
= tag
->next
)
157 tag
->selected
= True
;
159 tag
->selected
= False
;
163 ewmh_update_net_current_desktop(get_phys_screen(screen
));
169 Client
*c
, *sel
= globalconf
.focus
->client
;
176 if(globalconf
.screens
[screen
].allow_lower_floats
)
177 XRaiseWindow(globalconf
.display
, sel
->win
);
180 curtags
= get_current_tags(screen
);
181 if(sel
->isfloating
||
182 curtags
[0]->layout
->arrange
== layout_floating
)
183 XRaiseWindow(globalconf
.display
, sel
->win
);
184 if(!(curtags
[0]->layout
->arrange
== layout_floating
))
186 wc
.stack_mode
= Below
;
188 XConfigureWindow(globalconf
.display
, sel
->win
, CWStackMode
, &wc
);
189 for(c
= globalconf
.clients
; c
; c
= c
->next
)
191 if(!IS_TILED(c
, screen
) || c
== sel
)
193 XConfigureWindow(globalconf
.display
, c
->win
, CWStackMode
, &wc
);
198 if(globalconf
.screens
[screen
].focus_move_pointer
)
199 XWarpPointer(globalconf
.display
, None
, sel
->win
, 0, 0, 0, 0,
200 sel
->geometry
.width
/ 2, sel
->geometry
.height
/ 2);
204 saveawesomeprops(int screen
)
210 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
213 prop
= p_new(char, ntags
+ 1);
215 for(i
= 0, tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
, i
++)
216 prop
[i
] = tag
->selected
? '1' : '0';
219 XChangeProperty(globalconf
.display
,
220 RootWindow(globalconf
.display
, get_phys_screen(screen
)),
221 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
222 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
226 /** Set layout for tag
227 * \param screen Screen ID
228 * \param arg Layout specifier
229 * \ingroup ui_callback
232 uicb_tag_setlayout(int screen
, char *arg
)
234 Layout
*l
= globalconf
.screens
[screen
].layouts
;
240 curtags
= get_current_tags(screen
);
241 for(i
= 0; l
&& l
!= curtags
[0]->layout
; i
++, l
= l
->next
);
247 i
= compute_new_value_from_arg(arg
, (double) i
);
250 for(l
= globalconf
.screens
[screen
].layouts
; l
&& i
> 0; i
--)
253 for(l
= globalconf
.screens
[screen
].layouts
; l
&& i
< 0; i
++)
257 l
= globalconf
.screens
[screen
].layouts
;
260 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
264 if(globalconf
.focus
->client
)
267 widget_invalidate_cache(screen
, WIDGET_CACHE_LAYOUTS
);
269 saveawesomeprops(screen
);
272 /** Toggle floating state of a client
273 * \param screen Screen ID
275 * \ingroup ui_callback
278 uicb_client_togglefloating(int screen
, char *arg
)
280 Client
*sel
= globalconf
.focus
->client
;
285 if((sel
->isfloating
= !sel
->isfloating
))
288 client_resize(sel
, sel
->f_geometry
, False
);
291 client_resize(sel
, sel
->m_geometry
, False
);
293 widget_invalidate_cache(sel
->screen
, WIDGET_CACHE_CLIENTS
);
294 client_saveprops(sel
);
298 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80