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 */
36 arrange(Display
* disp
, int screen
, DC
*drawcontext
, awesome_config
*awesomeconf
)
40 for(c
= clients
; c
; c
= c
->next
)
42 if(c
->screen
!= screen
)
44 if(isvisible(c
, screen
, awesomeconf
->selected_tags
, awesomeconf
->ntags
))
49 awesomeconf
->current_layout
->arrange(disp
, screen
, awesomeconf
);
50 focus(disp
, screen
, drawcontext
, NULL
, True
, awesomeconf
);
51 restack(disp
, screen
, drawcontext
, awesomeconf
);
55 uicb_focusnext(Display
*disp
__attribute__ ((unused
)),
58 awesome_config
* awesomeconf
,
59 const char *arg
__attribute__ ((unused
)))
65 for(c
= sel
->next
; c
&& !isvisible(c
, screen
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->next
);
67 for(c
= clients
; c
&& !isvisible(c
, screen
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->next
);
70 focus(c
->display
, screen
, drawcontext
, c
, True
, awesomeconf
);
71 restack(c
->display
, screen
, drawcontext
, awesomeconf
);
76 uicb_focusprev(Display
*disp
__attribute__ ((unused
)),
79 awesome_config
*awesomeconf
,
80 const char *arg
__attribute__ ((unused
)))
86 for(c
= sel
->prev
; c
&& !isvisible(c
, screen
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->prev
);
89 for(c
= clients
; c
&& c
->next
; c
= c
->next
);
90 for(; c
&& !isvisible(c
, screen
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->prev
);
94 focus(c
->display
, screen
, drawcontext
, c
, True
, awesomeconf
);
95 restack(c
->display
, screen
, drawcontext
, awesomeconf
);
100 loadawesomeprops(Display
*disp
, int screen
, awesome_config
* awesomeconf
)
105 prop
= p_new(char, awesomeconf
->ntags
+ 1);
107 if(xgettextprop(disp
, RootWindow(disp
, screen
), AWESOMEPROPS_ATOM(disp
), prop
, awesomeconf
->ntags
+ 1))
108 for(i
= 0; i
< awesomeconf
->ntags
&& prop
[i
]; i
++)
109 awesomeconf
->selected_tags
[i
] = prop
[i
] == '1';
115 restack(Display
* disp
, int screen
, DC
* drawcontext
, awesome_config
*awesomeconf
)
121 drawstatusbar(disp
, screen
, drawcontext
, awesomeconf
);
124 if(sel
->isfloating
|| IS_ARRANGE(floating
))
125 XRaiseWindow(disp
, sel
->win
);
126 if(!IS_ARRANGE(floating
))
128 wc
.stack_mode
= Below
;
129 wc
.sibling
= awesomeconf
->statusbar
.window
;
132 XConfigureWindow(disp
, sel
->win
, CWSibling
| CWStackMode
, &wc
);
133 wc
.sibling
= sel
->win
;
135 for(c
= clients
; c
; c
= c
->next
)
137 if(!IS_TILED(c
, screen
, awesomeconf
->selected_tags
, awesomeconf
->ntags
) || c
== sel
)
139 XConfigureWindow(disp
, c
->win
, CWSibling
| CWStackMode
, &wc
);
144 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
148 saveawesomeprops(Display
*disp
, int screen
, awesome_config
*awesomeconf
)
153 prop
= p_new(char, awesomeconf
->ntags
+ 1);
154 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
155 prop
[i
] = awesomeconf
->selected_tags
[i
] ? '1' : '0';
157 XChangeProperty(disp
, RootWindow(disp
, screen
),
158 AWESOMEPROPS_ATOM(disp
), XA_STRING
, 8,
159 PropModeReplace
, (unsigned char *) prop
, i
);
164 uicb_setlayout(Display
*disp
,
167 awesome_config
* awesomeconf
,
175 if(!(++awesomeconf
->current_layout
)->symbol
)
176 awesomeconf
->current_layout
= &awesomeconf
->layouts
[0];
180 i
= strtol(arg
, NULL
, 10);
181 if(i
< 0 || i
>= awesomeconf
->nlayouts
)
183 awesomeconf
->current_layout
= &awesomeconf
->layouts
[i
];
186 for(c
= clients
; c
; c
= c
->next
)
190 arrange(disp
, screen
, drawcontext
, awesomeconf
);
192 drawstatusbar(disp
, DefaultScreen(disp
), drawcontext
, awesomeconf
);
194 saveawesomeprops(disp
, screen
, awesomeconf
);
196 for(j
= 0; j
< awesomeconf
->ntags
; j
++)
197 if (awesomeconf
->selected_tags
[j
])
198 awesomeconf
->tag_layouts
[j
] = awesomeconf
->current_layout
;
202 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
, True
);
219 else if(sel
->isfloating
)
220 resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, True
);
222 sel
->isfloating
= False
;
224 drawstatusbar(sel
->display
, sel
->screen
, drawcontext
, awesomeconf
);
226 while(XCheckMaskEvent(sel
->display
, EnterWindowMask
, &ev
));
230 uicb_togglemax(Display
*disp
,
231 int screen
__attribute__ ((unused
)),
233 awesome_config
*awesomeconf
,
234 const char *arg
__attribute__ ((unused
)))
236 maximize(get_windows_area_x(awesomeconf
->statusbar
),
237 get_windows_area_y(awesomeconf
->statusbar
),
238 get_windows_area_width(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
239 get_windows_area_height(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
245 uicb_toggleverticalmax(Display
*disp
,
246 int screen
__attribute__ ((unused
)),
248 awesome_config
*awesomeconf
,
249 const char *arg
__attribute__ ((unused
)))
253 get_windows_area_y(awesomeconf
->statusbar
),
255 get_windows_area_height(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
262 uicb_togglehorizontalmax(Display
*disp
,
263 int screen
__attribute__ ((unused
)),
265 awesome_config
*awesomeconf
,
266 const char *arg
__attribute__ ((unused
)))
269 maximize(get_windows_area_x(awesomeconf
->statusbar
),
271 get_windows_area_height(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
278 uicb_zoom(Display
*disp
__attribute__ ((unused
)),
279 int screen
__attribute__ ((unused
)),
280 DC
*drawcontext
__attribute__ ((unused
)),
281 awesome_config
*awesomeconf
,
282 const char *arg
__attribute__ ((unused
)))
288 focus(sel
->display
, sel
->screen
, drawcontext
, sel
, True
, awesomeconf
);
289 arrange(sel
->display
, sel
->screen
, drawcontext
, awesomeconf
);