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.
29 #include "layouts/tile.h"
32 extern Client
*sel
, *clients
;
35 uicb_setnmaster(Display
*disp
,
38 awesome_config
*awesomeconf
,
41 if(!arg
|| (!IS_ARRANGE(tile
) && !IS_ARRANGE(tileleft
)))
44 if((awesomeconf
->nmaster
= (int) compute_new_value_from_arg(arg
, (double) awesomeconf
->nmaster
)) < 0)
45 awesomeconf
->nmaster
= 0;
47 arrange(disp
, screen
, drawcontext
, awesomeconf
);
51 uicb_setncols(Display
*disp
,
54 awesome_config
*awesomeconf
,
57 if(!arg
|| (!IS_ARRANGE(tile
) && !IS_ARRANGE(tileleft
)))
60 if((awesomeconf
->ncols
= (int) compute_new_value_from_arg(arg
, (double) awesomeconf
->ncols
)) < 1)
61 awesomeconf
->ncols
= 1;
63 arrange(disp
, screen
, drawcontext
, awesomeconf
);
67 uicb_setmwfact(Display
*disp
,
70 awesome_config
* awesomeconf
,
73 if(!IS_ARRANGE(tile
) && !IS_ARRANGE(tileleft
))
76 if((awesomeconf
->mwfact
= compute_new_value_from_arg(arg
, awesomeconf
->mwfact
)) < 0.1)
77 awesomeconf
->mwfact
= 0.1;
78 else if(awesomeconf
->mwfact
> 0.9)
79 awesomeconf
->mwfact
= 0.9;
81 arrange(disp
, screen
, drawcontext
, awesomeconf
);
85 _tile(Display
*disp
, int screen
, awesome_config
*awesomeconf
, const Bool right
)
87 /* windows area geometry */
88 int wah
= 0, waw
= 0, wax
= 0, way
= 0;
90 unsigned int nx
, ny
, nw
, nh
;
92 unsigned int mw
= 0, mh
= 0;
93 int n
, i
, li
, last_i
= 0, masterwin
= 0, otherwin
= 0;
94 int screen_numbers
= 1, use_screen
= -1;
95 int real_ncols
= 1, win_by_col
= 1, current_col
= 0;
96 ScreenInfo
*screens_info
= NULL
;
99 screens_info
= get_screen_info(disp
, screen
, awesomeconf
->statusbar
, &screen_numbers
);
101 for(n
= 0, c
= clients
; c
; c
= c
->next
)
102 if(IS_TILED(c
, screen
, awesomeconf
->selected_tags
, awesomeconf
->ntags
))
105 for(i
= 0, c
= clients
; c
; c
= c
->next
)
107 if(!IS_TILED(c
, screen
, awesomeconf
->selected_tags
, awesomeconf
->ntags
))
111 || (screen_numbers
> 1
113 && ((i
- last_i
) >= masterwin
+ otherwin
114 || n
== screen_numbers
)))
119 wah
= screens_info
[use_screen
].height
;
120 waw
= screens_info
[use_screen
].width
;
121 wax
= screens_info
[use_screen
].x_org
;
122 way
= screens_info
[use_screen
].y_org
;
124 if(n
>= awesomeconf
->nmaster
* screen_numbers
)
126 masterwin
= awesomeconf
->nmaster
;
127 otherwin
= (n
- (awesomeconf
->nmaster
* screen_numbers
)) / screen_numbers
;
129 otherwin
+= (n
- (awesomeconf
->nmaster
* screen_numbers
)) % screen_numbers
;
133 masterwin
= n
/ screen_numbers
;
134 /* first screen takes more master */
136 masterwin
+= n
% screen_numbers
;
140 if(awesomeconf
->nmaster
)
142 mh
= masterwin
? wah
/ masterwin
: waw
;
143 mw
= otherwin
? waw
* awesomeconf
->mwfact
: waw
;
151 if(otherwin
< awesomeconf
->ncols
)
152 real_ncols
= otherwin
;
154 real_ncols
= awesomeconf
->ncols
;
160 li
= last_i
? i
- last_i
: i
;
161 if(li
< awesomeconf
->nmaster
)
163 ny
= way
+ li
* (mh
+ 2 * c
->border
);
164 nx
= wax
+ (right
? 0 : waw
- (mw
+ 2 * c
->border
));
165 resize(c
, nx
, ny
, mw
, mh
, awesomeconf
->resize_hints
);
169 win_by_col
= otherwin
/ real_ncols
;
171 if((li
- awesomeconf
->nmaster
) && (li
- awesomeconf
->nmaster
) % win_by_col
== 0 && current_col
< real_ncols
- 1)
174 if(current_col
== real_ncols
- 1)
175 win_by_col
+= otherwin
% real_ncols
;
177 if(otherwin
<= real_ncols
)
178 nh
= wah
- 2 * c
->border
;
180 nh
= (wah
/ win_by_col
) - 2 * c
->border
;
182 nw
= (waw
- (mw
+ 2 * c
->border
)) / real_ncols
- 2 * c
->border
;
184 if(li
== awesomeconf
->nmaster
|| otherwin
<= real_ncols
|| (li
- awesomeconf
->nmaster
) % win_by_col
== 0)
187 ny
= way
+ ((li
- awesomeconf
->nmaster
) % win_by_col
) * (nh
+ 2 * c
->border
);
189 nx
= wax
+ current_col
* nw
+ (right
? mw
+ 2 * c
->border
: 0);
190 resize(c
, nx
, ny
, nw
, nh
, awesomeconf
->resize_hints
);
198 tile(Display
*disp
, int screen
, awesome_config
*awesomeconf
)
200 _tile(disp
, screen
, awesomeconf
, True
);
204 tileleft(Display
*disp
, int screen
, awesome_config
*awesomeconf
)
206 _tile(disp
, screen
, awesomeconf
, False
);