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>
29 #include "statusbar.h"
33 #include "layouts/tile.h"
34 #include "layouts/max.h"
35 #include "layouts/fibonacci.h"
36 #include "layouts/floating.h"
38 extern AwesomeConf globalconf
;
40 const NameFuncLink LayoutsList
[] =
42 {"tile", layout_tile
},
43 {"tileleft", layout_tileleft
},
45 {"spiral", layout_spiral
},
46 {"dwindle", layout_dwindle
},
47 {"floating", layout_floating
},
51 /** Arrange windows following current selected layout
52 * \param screen the screen to arrange
58 Tag
**curtags
= get_current_tags(screen
);
60 for(c
= globalconf
.clients
; c
; c
= c
->next
)
62 if(client_isvisible(c
, screen
))
64 /* we don't touch other screens windows */
65 else if(c
->screen
== screen
)
69 curtags
[0]->layout
->arrange(screen
);
70 focus(focus_get_current_client(screen
), True
, screen
);
75 /** Send focus to next client in stack
76 * \param screen Screen ID
78 * \ingroup ui_callback
81 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
83 Client
*c
, *sel
= globalconf
.focus
->client
;
87 for(c
= sel
->next
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
89 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
92 focus(c
, True
, screen
);
97 /** Send focus to previous client in stack
98 * \param screen Screen ID
100 * \ingroup ui_callback
103 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
105 Client
*c
, *sel
= globalconf
.focus
->client
;
109 for(c
= sel
->prev
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->prev
);
112 for(c
= globalconf
.clients
; c
&& c
->next
; c
= c
->next
);
113 for(; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->prev
);
117 focus(c
, True
, screen
);
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(globalconf
.display
,
135 RootWindow(globalconf
.display
, get_phys_screen(screen
)),
136 AWESOMEPROPS_ATOM(globalconf
.display
), prop
, ntags
+ 1))
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
*c
, *sel
= globalconf
.focus
->client
;
156 statusbar_draw_all(screen
);
161 if(globalconf
.screens
[screen
].allow_lower_floats
)
162 XRaiseWindow(globalconf
.display
, sel
->win
);
165 curtags
= get_current_tags(screen
);
166 if(sel
->isfloating
||
167 curtags
[0]->layout
->arrange
== layout_floating
)
168 XRaiseWindow(globalconf
.display
, sel
->win
);
169 if(!(curtags
[0]->layout
->arrange
== layout_floating
))
171 wc
.stack_mode
= Below
;
173 XConfigureWindow(globalconf
.display
, sel
->win
, CWStackMode
, &wc
);
174 for(c
= globalconf
.clients
; c
; c
= c
->next
)
176 if(!IS_TILED(c
, screen
) || c
== sel
)
178 XConfigureWindow(globalconf
.display
, c
->win
, CWStackMode
, &wc
);
183 if(globalconf
.screens
[screen
].focus_move_pointer
)
184 XWarpPointer(globalconf
.display
, None
, sel
->win
, 0, 0, 0, 0, sel
->w
/ 2, sel
->h
/ 2);
185 XSync(globalconf
.display
, False
);
186 while(XCheckMaskEvent(globalconf
.display
, EnterWindowMask
, &ev
));
190 saveawesomeprops(int screen
)
196 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
199 prop
= p_new(char, ntags
+ 1);
201 for(i
= 0, tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
, i
++)
202 prop
[i
] = tag
->selected
? '1' : '0';
205 XChangeProperty(globalconf
.display
,
206 RootWindow(globalconf
.display
, get_phys_screen(screen
)),
207 AWESOMEPROPS_ATOM(globalconf
.display
), XA_STRING
, 8,
208 PropModeReplace
, (unsigned char *) prop
, i
);
212 /** Set layout for tag
213 * \param screen Screen ID
214 * \param arg Layout specifier
215 * \ingroup ui_callback
218 uicb_tag_setlayout(int screen
, char *arg
)
220 Layout
*l
= globalconf
.screens
[screen
].layouts
;
226 curtags
= get_current_tags(screen
);
227 for(i
= 0; l
&& l
!= curtags
[0]->layout
; i
++, l
= l
->next
);
231 for(i
= compute_new_value_from_arg(arg
, (double) i
),
232 l
= globalconf
.screens
[screen
].layouts
; l
&& i
> 0; i
--)
235 l
= globalconf
.screens
[screen
].layouts
;
238 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
242 if(globalconf
.focus
->client
)
245 statusbar_draw_all(screen
);
247 saveawesomeprops(screen
);
250 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80