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>
28 #include "layouts/floating.h"
31 extern Client
*clients
, *sel
; /* global client list */
34 arrange(Display
* disp
, DC
*drawcontext
, awesome_config
*awesomeconf
)
38 for(c
= clients
; c
; c
= c
->next
)
39 if(isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
))
43 awesomeconf
->current_layout
->arrange(disp
, awesomeconf
);
44 focus(disp
, drawcontext
, NULL
, True
, awesomeconf
);
45 restack(disp
, drawcontext
, awesomeconf
);
49 uicb_focusnext(Display
*disp
__attribute__ ((unused
)),
51 awesome_config
* awesomeconf
,
52 const char *arg
__attribute__ ((unused
)))
58 for(c
= sel
->next
; c
&& !isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->next
);
60 for(c
= clients
; c
&& !isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->next
);
63 focus(c
->display
, drawcontext
, c
, True
, awesomeconf
);
64 restack(c
->display
, drawcontext
, awesomeconf
);
69 uicb_focusprev(Display
*disp
__attribute__ ((unused
)),
71 awesome_config
*awesomeconf
,
72 const char *arg
__attribute__ ((unused
)))
78 for(c
= sel
->prev
; c
&& !isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->prev
);
81 for(c
= clients
; c
&& c
->next
; c
= c
->next
);
82 for(; c
&& !isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->prev
);
86 focus(c
->display
, drawcontext
, c
, True
, awesomeconf
);
87 restack(c
->display
, drawcontext
, awesomeconf
);
92 loadawesomeprops(Display
*disp
, awesome_config
* awesomeconf
)
97 prop
= p_new(char, awesomeconf
->ntags
+ 1);
99 if(xgettextprop(disp
, DefaultRootWindow(disp
), AWESOMEPROPS_ATOM(disp
), prop
, awesomeconf
->ntags
+ 1))
100 for(i
= 0; i
< awesomeconf
->ntags
&& prop
[i
]; i
++)
101 awesomeconf
->selected_tags
[i
] = prop
[i
] == '1';
107 restack(Display
* disp
, DC
* drawcontext
, awesome_config
*awesomeconf
)
113 drawstatus(disp
, drawcontext
, awesomeconf
);
116 if(sel
->isfloating
|| IS_ARRANGE(floating
))
117 XRaiseWindow(disp
, sel
->win
);
118 if(!IS_ARRANGE(floating
))
120 wc
.stack_mode
= Below
;
121 wc
.sibling
= awesomeconf
->statusbar
.window
;
124 XConfigureWindow(disp
, sel
->win
, CWSibling
| CWStackMode
, &wc
);
125 wc
.sibling
= sel
->win
;
127 for(c
= clients
; c
; c
= c
->next
)
129 if(!IS_TILED(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
) || c
== sel
)
131 XConfigureWindow(disp
, c
->win
, CWSibling
| CWStackMode
, &wc
);
136 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
140 saveawesomeprops(Display
*disp
, awesome_config
*awesomeconf
)
145 prop
= p_new(char, awesomeconf
->ntags
+ 1);
146 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
147 prop
[i
] = awesomeconf
->selected_tags
[i
] ? '1' : '0';
149 XChangeProperty(disp
, DefaultRootWindow(disp
),
150 AWESOMEPROPS_ATOM(disp
), XA_STRING
, 8,
151 PropModeReplace
, (unsigned char *) prop
, i
);
156 uicb_setlayout(Display
*disp
,
158 awesome_config
* awesomeconf
,
166 if(!(++awesomeconf
->current_layout
)->symbol
)
167 awesomeconf
->current_layout
= &awesomeconf
->layouts
[0];
171 i
= strtol(arg
, NULL
, 10);
172 if(i
< 0 || i
>= awesomeconf
->nlayouts
)
174 awesomeconf
->current_layout
= &awesomeconf
->layouts
[i
];
177 for(c
= clients
; c
; c
= c
->next
)
181 arrange(disp
, drawcontext
, awesomeconf
);
183 drawstatus(disp
, drawcontext
, awesomeconf
);
185 saveawesomeprops(disp
, awesomeconf
);
187 for(j
= 0; j
< awesomeconf
->ntags
; j
++)
188 if (awesomeconf
->selected_tags
[j
])
189 awesomeconf
->tag_layouts
[j
] = awesomeconf
->current_layout
;
193 uicb_togglebar(Display
*disp
,
195 awesome_config
*awesomeconf
,
196 const char *arg
__attribute__ ((unused
)))
198 if(awesomeconf
->statusbar
.position
== BarOff
)
199 awesomeconf
->statusbar
.position
= (awesomeconf
->statusbar
.position
== BarOff
) ? BarTop
: awesomeconf
->statusbar_default_position
;
201 awesomeconf
->statusbar
.position
= BarOff
;
202 updatebarpos(disp
, awesomeconf
->statusbar
);
203 arrange(disp
, drawcontext
, awesomeconf
);
207 maximize(int x
, int y
, int w
, int h
, DC
*drawcontext
, awesome_config
*awesomeconf
)
214 if((sel
->ismax
= !sel
->ismax
))
216 sel
->wasfloating
= sel
->isfloating
;
217 sel
->isfloating
= True
;
222 resize(sel
, x
, y
, w
, h
, True
);
224 else if(sel
->isfloating
)
225 resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, True
);
227 sel
->isfloating
= False
;
229 drawstatus(sel
->display
, drawcontext
, awesomeconf
);
231 while(XCheckMaskEvent(sel
->display
, EnterWindowMask
, &ev
));
235 uicb_togglemax(Display
*disp
,
237 awesome_config
*awesomeconf
,
238 const char *arg
__attribute__ ((unused
)))
240 maximize(get_windows_area_x(awesomeconf
->statusbar
),
241 get_windows_area_y(awesomeconf
->statusbar
),
242 get_windows_area_width(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
243 get_windows_area_height(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
249 uicb_toggleverticalmax(Display
*disp
,
251 awesome_config
*awesomeconf
,
252 const char *arg
__attribute__ ((unused
)))
256 get_windows_area_y(awesomeconf
->statusbar
),
258 get_windows_area_height(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
265 uicb_togglehorizontalmax(Display
*disp
,
267 awesome_config
*awesomeconf
,
268 const char *arg
__attribute__ ((unused
)))
271 maximize(get_windows_area_x(awesomeconf
->statusbar
),
273 get_windows_area_height(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
280 uicb_zoom(Display
*disp
__attribute__ ((unused
)),
281 DC
*drawcontext
__attribute__ ((unused
)),
282 awesome_config
*awesomeconf
,
283 const char *arg
__attribute__ ((unused
)))
289 focus(sel
->display
, drawcontext
, sel
, True
, awesomeconf
);
290 arrange(sel
->display
, drawcontext
, awesomeconf
);