Gappless grid pixel perfect updates

This commit is contained in:
bakkeby 2020-05-10 10:40:47 +02:00
parent 1508d9f274
commit 174e3260d2

View File

@ -2,12 +2,12 @@
void void
gaplessgrid(Monitor *m) gaplessgrid(Monitor *m)
{ {
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch; unsigned int i, n;
int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
int oh, ov, ih, iv; int oh, ov, ih, iv;
Client *c; Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n); getgaps(m, &oh, &ov, &ih, &iv, &n);
if (n == 0) if (n == 0)
return; return;
@ -18,21 +18,31 @@ gaplessgrid(Monitor *m)
if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
cols = 2; cols = 2;
rows = n/cols; rows = n/cols;
cn = rn = 0; // reset column no, row no, client count
ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
cw = (m->ww - 2*ov - iv * (cols - 1)) / cols;
rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
crest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
x = m->wx + ov;
y = m->wy + oh;
/* window geometries */
cw = cols ? (m->ww - 2*ov - iv*(cols - 1)) / cols : m->ww - 2*ov;
cn = 0; /* current column number */
rn = 0; /* current row number */
for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
if (i/rows + 1 > cols - n%cols) if (i/rows + 1 > cols - n%cols) {
rows = n/cols + 1; rows = n/cols + 1;
ch = rows ? (m->wh - 2*oh - ih*(rows - 1)) / rows : m->wh - 2*oh; ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
cx = m->wx + ov + cn*(cw + iv); rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
cy = m->wy + oh + rn*(ch + ih); }
resize(c, cx, cy, cw - 2*c->bw, ch - 2*c->bw, False); resize(c,
x,
y + rn*(ch + ih) + MIN(rn, rrest),
cw + (cn < crest ? 1 : 0) - 2*c->bw,
ch + (rn < rrest ? 1 : 0) - 2*c->bw,
0);
rn++; rn++;
if (rn >= rows) { if (rn >= rows) {
rn = 0; rn = 0;
x += cw + ih + (cn < crest ? 1 : 0);
cn++; cn++;
} }
} }
@ -41,7 +51,8 @@ gaplessgrid(Monitor *m)
void void
gaplessgrid(Monitor *m) gaplessgrid(Monitor *m)
{ {
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch; unsigned int i, n;
int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
Client *c; Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
@ -55,21 +66,31 @@ gaplessgrid(Monitor *m)
if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
cols = 2; cols = 2;
rows = n/cols; 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;
/* 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)) { for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
if (i/rows + 1 > cols - n%cols) if (i/rows + 1 > cols - n%cols) {
rows = n/cols + 1; rows = n/cols + 1;
ch = rows ? m->wh / rows : m->wh; ch = m->wh / rows;
cx = m->wx + cn*cw; rrest = m->wh - ch * rows;
cy = m->wy + rn*ch; }
resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False); 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++; rn++;
if (rn >= rows) { if (rn >= rows) {
rn = 0; rn = 0;
x += cw + (cn < crest ? 1 : 0);
cn++; cn++;
} }
} }