dvtm

Fork of dvtm, a minimal terminal multiplexer
git clone git://git.laack.co/dvtm.git
Log | Files | Refs | README | LICENSE

grid.c (1687B)


      1 static void grid(void)
      2 {
      3 	unsigned int i, n, nx, ny, nw, nh, aw, ah, cols, rows;
      4 	Client *c;
      5 
      6 	for (n = 0, c = nextvisible(clients); c; c = nextvisible(c->next))
      7 		if (!c->minimized)
      8 			n++;
      9 	/* grid dimensions */
     10 	for (cols = 0; cols <= n / 2; cols++)
     11 		if (cols * cols >= n)
     12 			break;
     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)) {
     18 		if (c->minimized)
     19 			continue;
     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))
     23 			nw = waw / (n - i);
     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);
     32 		else
     33 			aw = ((i + 1) % cols == 0) ? waw - nw * cols : 0;
     34 		if (i % cols) {
     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. */
     39 			if (i <= cols
     40 			    || (i >= rows * cols - cols && n % cols
     41 				&& (cols - (n % cols)) % 2))
     42 				mvaddch(ny, nx, ACS_TTEE);
     43 			else
     44 				mvaddch(ny, nx, ACS_PLUS);
     45 			nx++, aw--;
     46 		}
     47 		resize(c, nx, ny, nw + aw, nh + ah);
     48 		i++;
     49 	}
     50 }