gaplessgrid-fullgaps.c - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
gaplessgrid-fullgaps.c (915B)
---
1 void
2 gaplessgrid(Monitor *m) {
3 unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
4 Client *c;
5
6 for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
7 if(n == 0)
8 return;
9
10 /* grid dimensions */
11 for(cols = 0; cols <= n/2; cols++)
12 if(cols*cols >= n)
13 break;
14 if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
15 cols = 2;
16 rows = n/cols;
17
18 /* window geometries */
19 cw = cols ? m->ww / cols : m->ww;
20 cn = 0; /* current column number */
21 rn = 0; /* current row number */
22 for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
23 if(i/rows + 1 > cols - n%cols)
24 rows = n/cols + 1;
25 ch = rows ? m->wh / rows : m->wh;
26 cx = m->wx + cn*cw;
27 cy = m->wy + rn*ch;
28 resize(c, cx + (m->gappx)/2, cy + (m->gappx)/2, cw - 2 * (c->bw + (m->gappx)/2), ch - 2 * (c->bw + (m->gappx)/2), False);
29 rn++;
30 if(rn >= rows) {
31 rn = 0;
32 cn++;
33 }
34 }
35 }