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"
30 #include "layouts/floating.h"
33 extern Client
*clients
, *sel
; /* global client list */
35 /** Arrange windows following current selected layout
36 * \param disp display ref
37 * \param drawcontext drawcontext ref
38 * \param awesomeconf awesome config
41 arrange(Display
* disp
, DC
*drawcontext
, awesome_config
*awesomeconf
)
45 for(c
= clients
; c
; c
= c
->next
)
47 if(isvisible(c
, awesomeconf
->screen
, awesomeconf
->tags
, awesomeconf
->ntags
))
49 /* we don't touch other screens windows */
50 else if(c
->screen
== awesomeconf
->screen
)
53 awesomeconf
->current_layout
->arrange(disp
, awesomeconf
);
54 focus(disp
, drawcontext
, NULL
, True
, awesomeconf
);
55 restack(disp
, drawcontext
, awesomeconf
);
59 uicb_focusnext(Display
*disp
__attribute__ ((unused
)),
61 awesome_config
* awesomeconf
,
62 const char *arg
__attribute__ ((unused
)))
68 for(c
= sel
->next
; c
&& !isvisible(c
, awesomeconf
->screen
, awesomeconf
->tags
, awesomeconf
->ntags
); c
= c
->next
);
70 for(c
= clients
; c
&& !isvisible(c
, awesomeconf
->screen
, awesomeconf
->tags
, awesomeconf
->ntags
); c
= c
->next
);
73 focus(c
->display
, drawcontext
, c
, True
, awesomeconf
);
74 restack(c
->display
, drawcontext
, awesomeconf
);
79 uicb_focusprev(Display
*disp
__attribute__ ((unused
)),
81 awesome_config
*awesomeconf
,
82 const char *arg
__attribute__ ((unused
)))
88 for(c
= sel
->prev
; c
&& !isvisible(c
, awesomeconf
->screen
, awesomeconf
->tags
, awesomeconf
->ntags
); c
= c
->prev
);
91 for(c
= clients
; c
&& c
->next
; c
= c
->next
);
92 for(; c
&& !isvisible(c
, awesomeconf
->screen
, awesomeconf
->tags
, awesomeconf
->ntags
); c
= c
->prev
);
96 focus(c
->display
, drawcontext
, c
, True
, awesomeconf
);
97 restack(c
->display
, drawcontext
, awesomeconf
);
102 loadawesomeprops(Display
*disp
, awesome_config
* awesomeconf
)
107 prop
= p_new(char, awesomeconf
->ntags
+ 1);
109 if(xgettextprop(disp
, RootWindow(disp
, awesomeconf
->phys_screen
), AWESOMEPROPS_ATOM(disp
), prop
, awesomeconf
->ntags
+ 1))
110 for(i
= 0; i
< awesomeconf
->ntags
&& prop
[i
]; i
++)
111 awesomeconf
->tags
[i
].selected
= prop
[i
] == '1';
117 restack(Display
* disp
, DC
* drawcontext
, awesome_config
*awesomeconf
)
123 drawstatusbar(disp
, drawcontext
, awesomeconf
);
126 if(sel
->isfloating
|| IS_ARRANGE(layout_floating
))
127 XRaiseWindow(disp
, sel
->win
);
128 if(!IS_ARRANGE(layout_floating
))
130 wc
.stack_mode
= Below
;
131 wc
.sibling
= awesomeconf
->statusbar
.window
;
134 XConfigureWindow(disp
, sel
->win
, CWSibling
| CWStackMode
, &wc
);
135 wc
.sibling
= sel
->win
;
137 for(c
= clients
; c
; c
= c
->next
)
139 if(!IS_TILED(c
, awesomeconf
->screen
, awesomeconf
->tags
, awesomeconf
->ntags
) || c
== sel
)
141 XConfigureWindow(disp
, c
->win
, CWSibling
| CWStackMode
, &wc
);
146 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
150 saveawesomeprops(Display
*disp
, awesome_config
*awesomeconf
)
155 prop
= p_new(char, awesomeconf
->ntags
+ 1);
156 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
157 prop
[i
] = awesomeconf
->tags
[i
].selected
? '1' : '0';
159 XChangeProperty(disp
, RootWindow(disp
, awesomeconf
->phys_screen
),
160 AWESOMEPROPS_ATOM(disp
), XA_STRING
, 8,
161 PropModeReplace
, (unsigned char *) prop
, i
);
166 uicb_setlayout(Display
*disp
,
168 awesome_config
* awesomeconf
,
176 for(i
= 0; i
< awesomeconf
->nlayouts
&& &awesomeconf
->layouts
[i
] != awesomeconf
->current_layout
; i
++);
177 i
= compute_new_value_from_arg(arg
, (double) i
);
178 if(i
>= awesomeconf
->nlayouts
)
181 i
= awesomeconf
->nlayouts
- 1;
186 awesomeconf
->current_layout
= &awesomeconf
->layouts
[i
];
188 for(c
= clients
; c
; c
= c
->next
)
192 arrange(disp
, drawcontext
, awesomeconf
);
194 drawstatusbar(disp
, drawcontext
, awesomeconf
);
196 saveawesomeprops(disp
, awesomeconf
);
198 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
199 if (awesomeconf
->tags
[i
].selected
)
200 awesomeconf
->tags
[i
].layout
= awesomeconf
->current_layout
;
204 maximize(int x
, int y
, int w
, int h
, DC
*drawcontext
, awesome_config
*awesomeconf
)
209 if((sel
->ismax
= !sel
->ismax
))
211 sel
->wasfloating
= sel
->isfloating
;
212 sel
->isfloating
= True
;
217 resize(sel
, x
, y
, w
, h
, awesomeconf
, True
);
219 else if(sel
->wasfloating
)
220 resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, awesomeconf
, True
);
222 sel
->isfloating
= False
;
224 arrange(sel
->display
, drawcontext
, awesomeconf
);
228 uicb_togglemax(Display
*disp
,
230 awesome_config
*awesomeconf
,
231 const char *arg
__attribute__ ((unused
)))
233 ScreenInfo
*si
= get_screen_info(disp
, awesomeconf
->screen
, &awesomeconf
->statusbar
);
235 maximize(si
[awesomeconf
->screen
].x_org
, si
[awesomeconf
->screen
].y_org
,
236 si
[awesomeconf
->screen
].width
- 2 * awesomeconf
->borderpx
,
237 si
[awesomeconf
->screen
].height
- 2 * awesomeconf
->borderpx
,
238 drawcontext
, awesomeconf
);
243 uicb_toggleverticalmax(Display
*disp
,
245 awesome_config
*awesomeconf
,
246 const char *arg
__attribute__ ((unused
)))
248 ScreenInfo
*si
= get_screen_info(disp
, awesomeconf
->screen
, &awesomeconf
->statusbar
);
251 maximize(sel
->x
, si
[awesomeconf
->screen
].y_org
,
252 sel
->w
, si
[awesomeconf
->screen
].height
- 2 * awesomeconf
->borderpx
,
253 drawcontext
, awesomeconf
);
259 uicb_togglehorizontalmax(Display
*disp
,
261 awesome_config
*awesomeconf
,
262 const char *arg
__attribute__ ((unused
)))
264 ScreenInfo
*si
= get_screen_info(disp
, awesomeconf
->screen
, &awesomeconf
->statusbar
);
267 maximize(si
[awesomeconf
->screen
].x_org
, sel
->y
,
268 si
[awesomeconf
->screen
].height
- 2 * awesomeconf
->borderpx
, sel
->h
,
269 drawcontext
, awesomeconf
);
274 uicb_zoom(Display
*disp
__attribute__ ((unused
)),
275 DC
*drawcontext
__attribute__ ((unused
)),
276 awesome_config
*awesomeconf
,
277 const char *arg
__attribute__ ((unused
)))
283 focus(sel
->display
, drawcontext
, sel
, True
, awesomeconf
);
284 arrange(sel
->display
, drawcontext
, awesomeconf
);