dwm/layouts.c

79 lines
2.0 KiB
C
Raw Normal View History

2023-05-28 13:45:41 +08:00
void
tile(Monitor *m)
{
unsigned int i, n, h, mw, my, ty;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
if (n > m->nmaster)
mw = m->nmaster ? m->ww * m->mfact : 0;
else
2024-05-31 21:39:01 +08:00
mw = m->ww - gappx;
for (i = 0, my = ty = gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
2024-05-31 14:05:30 +08:00
if (i < m->nmaster) {
2024-05-31 21:39:01 +08:00
h = (m->wh - my) / (MIN(n, m->nmaster) - i) - gappx;
resize(c, m->wx + gappx, m->wy + my, mw - (2*c->bw) - gappx, h - (2*c->bw), 0);
if (my + HEIGHT(c) + gappx < m->wh)
my += HEIGHT(c) + gappx;
2024-05-31 14:05:30 +08:00
} else {
2024-05-31 21:39:01 +08:00
h = (m->wh - ty) / (n - i) - gappx;
resize(c, m->wx + mw + gappx, m->wy + ty, m->ww - mw - (2*c->bw) - 2*gappx, h - (2*c->bw), 0);
if (ty + HEIGHT(c) + gappx < m->wh)
ty += HEIGHT(c) + gappx;
2023-05-28 13:45:41 +08:00
}
}
void
monocle(Monitor *m)
{
unsigned int n = 0;
Client *c;
for (c = m->clients; c; c = c->next)
if (ISVISIBLE(c))
n++;
if (n > 0) /* override layout symbol */
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
}
2024-05-31 14:11:54 +08: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 */
2024-05-31 22:01:58 +08:00
cw = cols ? (m->ww - gappx) / cols : m->ww - gappx;
2024-05-31 14:11:54 +08:00
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;
2024-05-31 22:01:58 +08:00
ch = rows ? (m->wh - gappx) / rows : m->wh - gappx;
2024-05-31 14:11:54 +08:00
cx = m->wx + cn*cw;
cy = m->wy + rn*ch;
2024-05-31 22:01:58 +08:00
resize(c, cx + gappx, cy + gappx, cw - 2 * c->bw - gappx, ch - 2 * c->bw - gappx, False);
2024-05-31 14:11:54 +08:00
rn++;
if(rn >= rows) {
rn = 0;
cn++;
}
}
}