render: fix rounding errors when setting initial window size and scale != 1

An odd cell width/height sometimes resulted in an odd grid
size. Combined with a scaling factor of e.g. 2, that led to a rounding
error when converting pixel sizes to logical window sizes.

As a result, the _next_ configure event would cause us to loose a
pixel, which led to us dropping a row from the grid.
This commit is contained in:
Daniel Eklöf 2020-09-17 17:37:58 +02:00
parent 185a6048a7
commit 2e7102c956
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -2056,11 +2056,23 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
break;
case CONF_SIZE_CELLS:
width = 2 * term->conf->pad_x * scale;
height = 2 * term->conf->pad_y * scale;
width = term->conf->size.cells.width * term->cell_width;
height = term->conf->size.cells.height * term->cell_height;
width += term->conf->size.cells.width * term->cell_width;
height += term->conf->size.cells.height * term->cell_height;
width += 2 * term->conf->pad_x * scale;
height += 2 * term->conf->pad_y * scale;
/*
* Ensure we can scale to logical size, and back to
* pixels without truncating.
*/
if (width % scale)
width += scale - width % scale;
if (height % scale)
height += scale - height % scale;
assert(width % scale == 0);
assert(height % scale == 0);
break;
}
}