diff --git a/dwm.c b/dwm.c index e0c960b..aa3257a 100644 --- a/dwm.c +++ b/dwm.c @@ -499,13 +499,14 @@ buttonpress(XEvent *e) void centeredmaster(Monitor *m) { - unsigned int i, n, h, mw, mx, my, oty, ety, tw; + unsigned int i, iSlave, n, nSlaves, h, mw, mx, my, oty, ety, tw; Client *c; /* count number of clients in the selected monitor */ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); if (n == 0) return; + nSlaves = n - m->nmaster; /* initialize areas */ mw = m->ww; @@ -536,12 +537,13 @@ centeredmaster(Monitor *m) my += HEIGHT(c); } else { /* stack clients are stacked vertically */ - if ((i - m->nmaster) % 2 ) { - h = (m->wh - ety) / ( (1 + n - i) / 2); + iSlave = i - m->nmaster; + if (iSlave < nSlaves/2) { + h = (m->wh - ety) / (nSlaves / 2 - iSlave); resize(c, m->wx, m->wy + ety, tw - (2*c->bw), h - (2*c->bw), 0); ety += HEIGHT(c); } else { - h = (m->wh - oty) / ((1 + n - i) / 2); + h = (m->wh - oty) / (nSlaves - iSlave); resize(c, m->wx + mx + mw, m->wy + oty, tw - (2*c->bw), h - (2*c->bw), 0); oty += HEIGHT(c); }