sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

gaplessgrid.c (851B)


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