dwm-custom/patch/layout_gapplessgrid.c

49 lines
1022 B
C
Raw Normal View History

2024-05-22 17:29:40 +02:00
void
gaplessgrid(Monitor *m)
{
unsigned int i, n;
int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
/* grid dimensions */
for (cols = 0; cols <= n/2; cols++)
if (cols*cols >= n)
break;
if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
cols = 2;
rows = n/cols;
cn = rn = 0; // reset column no, row no, client count
ch = m->wh / rows;
cw = m->ww / cols;
rrest = m->wh - ch * rows;
crest = m->ww - cw * cols;
x = m->wx;
y = m->wy;
for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
if (i/rows + 1 > cols - n%cols) {
rows = n/cols + 1;
ch = m->wh / rows;
rrest = m->wh - ch * rows;
}
resize(c,
x,
y + rn*ch + MIN(rn, rrest),
cw + (cn < crest ? 1 : 0) - 2*c->bw,
ch + (rn < rrest ? 1 : 0) - 2*c->bw,
0);
rn++;
if (rn >= rows) {
rn = 0;
x += cw + (cn < crest ? 1 : 0);
cn++;
}
}
}