gaplessgrid.c (929B)
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 if(n <= 1) 12 cols = 1; 13 else 14 cols = 2; 15 /* for(cols = 0; cols <= n/2; cols++) */ 16 /* if(cols*cols >= n) */ 17 /* break; */ 18 if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ 19 cols = 2; 20 rows = n/cols; 21 22 /* window geometries */ 23 cw = cols ? m->ww / cols : m->ww; 24 cn = 0; /* current column number */ 25 rn = 0; /* current row number */ 26 for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { 27 if(i/rows + 1 > cols - n%cols) 28 rows = n/cols + 1; 29 ch = rows ? m->wh / rows : m->wh; 30 cx = m->wx + cn*cw; 31 cy = m->wy + rn*ch; 32 resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False); 33 rn++; 34 if(rn >= rows) { 35 rn = 0; 36 cn++; 37 } 38 } 39 }