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
, DC
*drawcontext
, awesome_config
*awesomeconf
)
40 for(c
= clients
; c
; c
= c
->next
)
41 if(isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
))
45 awesomeconf
->current_layout
->arrange(disp
, awesomeconf
);
46 focus(disp
, DefaultScreen(disp
), drawcontext
, NULL
, True
, awesomeconf
);
47 restack(disp
, drawcontext
, awesomeconf
);
51 uicb_focusnext(Display
*disp
__attribute__ ((unused
)),
53 awesome_config
* awesomeconf
,
54 const char *arg
__attribute__ ((unused
)))
60 for(c
= sel
->next
; c
&& !isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->next
);
62 for(c
= clients
; c
&& !isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->next
);
65 focus(c
->display
, c
->screen
, drawcontext
, c
, True
, awesomeconf
);
66 restack(c
->display
, drawcontext
, awesomeconf
);
71 uicb_focusprev(Display
*disp
__attribute__ ((unused
)),
73 awesome_config
*awesomeconf
,
74 const char *arg
__attribute__ ((unused
)))
80 for(c
= sel
->prev
; c
&& !isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->prev
);
83 for(c
= clients
; c
&& c
->next
; c
= c
->next
);
84 for(; c
&& !isvisible(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
); c
= c
->prev
);
88 focus(c
->display
, c
->screen
, drawcontext
, c
, True
, awesomeconf
);
89 restack(c
->display
, drawcontext
, awesomeconf
);
94 loadawesomeprops(Display
*disp
, int screen
, awesome_config
* awesomeconf
)
99 prop
= p_new(char, awesomeconf
->ntags
+ 1);
101 if(xgettextprop(disp
, RootWindow(disp
, screen
), AWESOMEPROPS_ATOM(disp
), prop
, awesomeconf
->ntags
+ 1))
102 for(i
= 0; i
< awesomeconf
->ntags
&& prop
[i
]; i
++)
103 awesomeconf
->selected_tags
[i
] = prop
[i
] == '1';
109 restack(Display
* disp
, DC
* drawcontext
, awesome_config
*awesomeconf
)
115 drawstatusbar(disp
, DefaultScreen(disp
), drawcontext
, awesomeconf
);
118 if(sel
->isfloating
|| IS_ARRANGE(floating
))
119 XRaiseWindow(disp
, sel
->win
);
120 if(!IS_ARRANGE(floating
))
122 wc
.stack_mode
= Below
;
123 wc
.sibling
= awesomeconf
->statusbar
.window
;
126 XConfigureWindow(disp
, sel
->win
, CWSibling
| CWStackMode
, &wc
);
127 wc
.sibling
= sel
->win
;
129 for(c
= clients
; c
; c
= c
->next
)
131 if(!IS_TILED(c
, awesomeconf
->selected_tags
, awesomeconf
->ntags
) || c
== sel
)
133 XConfigureWindow(disp
, c
->win
, CWSibling
| CWStackMode
, &wc
);
138 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
142 saveawesomeprops(Display
*disp
, int screen
, awesome_config
*awesomeconf
)
147 prop
= p_new(char, awesomeconf
->ntags
+ 1);
148 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
149 prop
[i
] = awesomeconf
->selected_tags
[i
] ? '1' : '0';
151 XChangeProperty(disp
, RootWindow(disp
, screen
),
152 AWESOMEPROPS_ATOM(disp
), XA_STRING
, 8,
153 PropModeReplace
, (unsigned char *) prop
, i
);
158 uicb_setlayout(Display
*disp
,
160 awesome_config
* awesomeconf
,
168 if(!(++awesomeconf
->current_layout
)->symbol
)
169 awesomeconf
->current_layout
= &awesomeconf
->layouts
[0];
173 i
= strtol(arg
, NULL
, 10);
174 if(i
< 0 || i
>= awesomeconf
->nlayouts
)
176 awesomeconf
->current_layout
= &awesomeconf
->layouts
[i
];
179 for(c
= clients
; c
; c
= c
->next
)
183 arrange(disp
, drawcontext
, awesomeconf
);
185 drawstatusbar(disp
, DefaultScreen(disp
), drawcontext
, awesomeconf
);
187 saveawesomeprops(disp
, DefaultScreen(disp
), awesomeconf
);
189 for(j
= 0; j
< awesomeconf
->ntags
; j
++)
190 if (awesomeconf
->selected_tags
[j
])
191 awesomeconf
->tag_layouts
[j
] = awesomeconf
->current_layout
;
195 maximize(int x
, int y
, int w
, int h
, DC
*drawcontext
, awesome_config
*awesomeconf
)
202 if((sel
->ismax
= !sel
->ismax
))
204 sel
->wasfloating
= sel
->isfloating
;
205 sel
->isfloating
= True
;
210 resize(sel
, x
, y
, w
, h
, True
);
212 else if(sel
->isfloating
)
213 resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, True
);
215 sel
->isfloating
= False
;
217 drawstatusbar(sel
->display
, sel
->screen
, drawcontext
, awesomeconf
);
219 while(XCheckMaskEvent(sel
->display
, EnterWindowMask
, &ev
));
223 uicb_togglemax(Display
*disp
,
225 awesome_config
*awesomeconf
,
226 const char *arg
__attribute__ ((unused
)))
228 maximize(get_windows_area_x(awesomeconf
->statusbar
),
229 get_windows_area_y(awesomeconf
->statusbar
),
230 get_windows_area_width(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
231 get_windows_area_height(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
237 uicb_toggleverticalmax(Display
*disp
,
239 awesome_config
*awesomeconf
,
240 const char *arg
__attribute__ ((unused
)))
244 get_windows_area_y(awesomeconf
->statusbar
),
246 get_windows_area_height(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
253 uicb_togglehorizontalmax(Display
*disp
,
255 awesome_config
*awesomeconf
,
256 const char *arg
__attribute__ ((unused
)))
259 maximize(get_windows_area_x(awesomeconf
->statusbar
),
261 get_windows_area_height(disp
, awesomeconf
->statusbar
) - 2 * awesomeconf
->borderpx
,
268 uicb_zoom(Display
*disp
__attribute__ ((unused
)),
269 DC
*drawcontext
__attribute__ ((unused
)),
270 awesome_config
*awesomeconf
,
271 const char *arg
__attribute__ ((unused
)))
277 focus(sel
->display
, sel
->screen
, drawcontext
, sel
, True
, awesomeconf
);
278 arrange(sel
->display
, drawcontext
, awesomeconf
);