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