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 #include "layoutgen.h"
44 layout_raise_floatings(int screen
)
48 for(c
= globalconf
.clients
; c
; c
= c
->next
)
49 if(c
->isfloating
&& client_isvisible(c
, screen
))
50 XRaiseWindow(globalconf
.display
, c
->win
);
53 /** Arrange windows following current selected layout
54 * \param screen the screen to arrange
60 Layout
*curlay
= get_current_layout(screen
);
61 Window client_win
, root_win
;
65 for(c
= globalconf
.clients
; c
; c
= c
->next
)
67 if(client_isvisible(c
, screen
) && !c
->newcomer
)
69 /* we don't touch other screens windows */
70 else if(c
->screen
== screen
|| c
->newcomer
)
74 curlay
->arrange(screen
);
76 for(c
= globalconf
.clients
; c
; c
= c
->next
)
77 if(c
->newcomer
&& client_isvisible(c
, screen
))
83 if(!globalconf
.screens
[screen
].allow_lower_floats
)
84 layout_raise_floatings(screen
);
86 c
= focus_get_current_client(screen
);
87 focus(c
, True
, screen
);
88 if(c
&& XQueryPointer(globalconf
.display
, RootWindow(globalconf
.display
, get_phys_screen(screen
)),
89 &root_win
, &client_win
, &x
, &y
, &d
, &d
, &m
) &&
90 (root_win
== None
|| client_win
== None
|| client_win
== root_win
))
91 window_grabbuttons(c
->screen
, c
->win
, False
, False
);
94 globalconf
.screens
[screen
].need_arrange
= False
;
101 Bool arranged
= False
;
103 for(screen
= 0; screen
< get_screen_count(); screen
++)
104 if(globalconf
.screens
[screen
].need_arrange
)
114 get_current_layout(int screen
)
116 Tag
**curtags
= get_current_tags(screen
);
117 Layout
*l
= curtags
[0]->layout
;
123 loadawesomeprops(int screen
)
129 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
132 prop
= p_new(char, ntags
+ 1);
134 if(xgettextprop(RootWindow(globalconf
.display
, get_phys_screen(screen
)),
135 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
137 for(i
= 0, tag
= globalconf
.screens
[screen
].tags
; tag
&& prop
[i
]; i
++, tag
= tag
->next
)
139 tag
->selected
= True
;
141 tag
->selected
= False
;
145 ewmh_update_net_current_desktop(get_phys_screen(screen
));
151 Client
*sel
= globalconf
.focus
->client
;
152 Layout
*curlay
= get_current_layout(screen
);
157 if(globalconf
.screens
[screen
].allow_lower_floats
)
158 XRaiseWindow(globalconf
.display
, sel
->win
);
160 if(sel
->isfloating
|| curlay
->arrange
== layout_floating
)
161 XRaiseWindow(globalconf
.display
, sel
->win
);
163 if(globalconf
.screens
[screen
].focus_move_pointer
)
164 XWarpPointer(globalconf
.display
, None
, sel
->win
, 0, 0, 0, 0,
165 sel
->geometry
.width
/ 2, sel
->geometry
.height
/ 2);
169 saveawesomeprops(int screen
)
175 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
178 prop
= p_new(char, ntags
+ 1);
180 for(i
= 0, tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
, i
++)
181 prop
[i
] = tag
->selected
? '1' : '0';
184 XChangeProperty(globalconf
.display
,
185 RootWindow(globalconf
.display
, get_phys_screen(screen
)),
186 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
187 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
191 /** Set layout for tag
192 * \param screen Screen ID
193 * \param arg Layout specifier
194 * \ingroup ui_callback
197 uicb_tag_setlayout(int screen
, char *arg
)
199 Layout
*l
= globalconf
.screens
[screen
].layouts
;
205 curtags
= get_current_tags(screen
);
206 for(i
= 0; l
&& l
!= curtags
[0]->layout
; i
++, l
= l
->next
);
212 i
= compute_new_value_from_arg(arg
, (double) i
);
215 for(l
= globalconf
.screens
[screen
].layouts
; l
&& i
> 0; i
--)
218 for(l
= globalconf
.screens
[screen
].layouts
; l
&& i
< 0; i
++)
219 l
= layout_list_prev_cycle(&globalconf
.screens
[screen
].layouts
, l
);
222 l
= globalconf
.screens
[screen
].layouts
;
225 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
229 if(globalconf
.focus
->client
)
232 widget_invalidate_cache(screen
, WIDGET_CACHE_LAYOUTS
);
234 saveawesomeprops(screen
);
237 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80