3 unsigned int i
, m
, nm
, n
, nx
, ny
, nw
, nh
, aw
, ah
, cols
, rows
;
6 for(n
= 0, m
= 0, c
= clients
; c
; c
= c
->next
,n
++)
9 /* number of non minimized windows */
12 for(cols
= 0; cols
<= nm
/2; cols
++)
15 rows
= (cols
&& (cols
- 1) * cols
>= nm
) ? cols
- 1 : cols
;
16 /* window geoms (cell height/width) */
17 nh
= (wah
- m
) / (rows
? rows
: 1);
18 nw
= waw
/ (cols
? cols
: 1);
19 for(i
= 0, c
= clients
; c
; c
= c
->next
,i
++) {
21 /* if there are less clients in the last row than normal adjust the
22 * split rate to fill the empty space */
23 if(rows
> 1 && i
== (rows
* cols
) - cols
&& (nm
- i
) <= (nm
% cols
))
25 nx
= (i
% cols
) * nw
+ wax
;
26 ny
= (i
/ cols
) * nh
+ way
;
27 /* adjust height/width of last row/column's windows */
28 ah
= (i
>= cols
* (rows
-1)) ? wah
- m
- nh
* rows
: 0;
29 /* special case if there are less clients in the last row */
30 if(rows
> 1 && i
== nm
- 1 && (nm
- i
) < (nm
% cols
))
31 /* (n % cols) == number of clients in the last row */
32 aw
= waw
- nw
* (nm
% cols
);
34 aw
= ((i
+ 1) % cols
== 0) ? waw
- nw
* cols
: 0;
36 mvvline(ny
, nx
, ACS_VLINE
, nh
+ ah
);
37 /* if we are on the first row, or on the last one and there are fewer clients
38 * than normal whose border does not match the line above, print a top tree char
39 * otherwise a plus sign. */
40 if(i
<= cols
|| (i
>= rows
* cols
- cols
&& nm
% cols
&& (cols
- (nm
% cols
)) % 2))
41 mvaddch(ny
, nx
, ACS_TTEE
);
43 mvaddch(ny
, nx
, ACS_PLUS
);
47 if(i
== nm
){ /* first minimized client */
57 resize(c
, nx
, ny
, nw
+ aw
, nh
+ ah
);