dwm/layout_horizgrid.c

48 lines
1.1 KiB
C

void
horizgrid(Monitor *m) {
Client *c;
unsigned int n, i;
int mx = 0, my = 0, mh = 0, mw = 0;
int sx = 0, sy = 0, sh = 0, sw = 0;
int ntop;
float mfacts = 0, sfacts = 0;
int mrest, srest, mtotal = 0, stotal = 0;
int oh, ov, ih, iv;
getgaps(m, &oh, &ov, &ih, &iv, &n);
sx = mx = m->wx + ov;
sy = my = m->wy + oh;
sh = mh = m->wh - 2*oh;
sw = mw = m->ww - 2*ov;
if (n > ntop) {
sh = (mh - ih) / 2;
mh = mh - ih - sh;
sy = my + mh + ih;
mw = m->ww - 2*ov - iv * (ntop - 1);
sw = m->ww - 2*ov - iv * (n - ntop - 1);
}
mfacts = ntop;
sfacts = n - ntop;
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
if (i < ntop)
mtotal += mh / mfacts;
else
stotal += sw / sfacts;
mrest = mh - mtotal;
srest = sw - stotal;
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
if (i < ntop) {
resize(c, mx, my, mw / mfacts + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
mx += WIDTH(c) + iv;
} else {
resize(c, sx, sy, sw / sfacts + ((i - ntop) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
sx += WIDTH(c) + iv;
}
}