2023-09-06 15:05:38 +02:00
|
|
|
void
|
|
|
|
grid(Monitor *m) {
|
|
|
|
unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows;
|
|
|
|
Client *c;
|
|
|
|
|
|
|
|
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next))
|
|
|
|
n++;
|
|
|
|
|
|
|
|
/* grid dimensions */
|
|
|
|
for(rows = 0; rows <= n/2; rows++)
|
|
|
|
if(rows*rows >= n)
|
|
|
|
break;
|
|
|
|
cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows;
|
|
|
|
|
|
|
|
/* window geoms (cell height/width) */
|
|
|
|
ch = m->wh / (rows ? rows : 1);
|
|
|
|
cw = m->ww / (cols ? cols : 1);
|
|
|
|
for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
|
|
|
|
cx = m->wx + (i / rows) * cw;
|
|
|
|
cy = m->wy + (i % rows) * ch;
|
|
|
|
/* adjust height/width of last row/column's windows */
|
|
|
|
ah = ((i + 1) % rows == 0) ? m->wh - ch * rows : 0;
|
|
|
|
aw = (i >= rows * (cols - 1)) ? m->ww - cw * cols : 0;
|
|
|
|
resize(c, cx, cy, cw - 2 * c->bw + aw, ch - 2 * c->bw + ah, False);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2023-09-07 20:33:05 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
gaplessgrid(Monitor *m) {
|
|
|
|
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* window geometries */
|
|
|
|
cw = cols ? m->ww / cols : m->ww;
|
|
|
|
cn = 0; /* current column number */
|
|
|
|
rn = 0; /* current row number */
|
|
|
|
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 = rows ? m->wh / rows : m->wh;
|
|
|
|
cx = m->wx + cn*cw;
|
|
|
|
cy = m->wy + rn*ch;
|
|
|
|
resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
|
|
|
|
rn++;
|
|
|
|
if(rn >= rows) {
|
|
|
|
rn = 0;
|
|
|
|
cn++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
horizgrid(Monitor *m) {
|
|
|
|
Client *c;
|
|
|
|
unsigned int n, i;
|
|
|
|
int w = 0;
|
|
|
|
int ntop, nbottom = 0;
|
|
|
|
|
|
|
|
/* Count windows */
|
|
|
|
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
|
|
|
|
|
|
|
if(n == 0)
|
|
|
|
return;
|
|
|
|
else if(n == 1) { /* Just fill the whole screen */
|
|
|
|
c = nexttiled(m->clients);
|
|
|
|
resize(c, m->wx, m->wy, m->ww - (2*c->bw), m->wh - (2*c->bw), False);
|
|
|
|
} else if(n == 2) { /* Split vertically */
|
|
|
|
w = m->ww / 2;
|
|
|
|
c = nexttiled(m->clients);
|
|
|
|
resize(c, m->wx, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
|
|
|
|
c = nexttiled(c->next);
|
|
|
|
resize(c, m->wx + w, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
|
|
|
|
} else {
|
|
|
|
ntop = n / 2;
|
|
|
|
nbottom = n - ntop;
|
|
|
|
for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
|
|
|
if(i < ntop)
|
|
|
|
resize(c, m->wx + i * m->ww / ntop, m->wy, m->ww / ntop - (2*c->bw), m->wh / 2 - (2*c->bw), False);
|
|
|
|
else
|
|
|
|
resize(c, m->wx + (i - ntop) * m->ww / nbottom, m->wy + m->wh / 2, m->ww / nbottom - (2*c->bw), m->wh / 2 - (2*c->bw), False);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|