From 2e7102c9563370e5ad160c0f712c90966b4724ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 17 Sep 2020 17:37:58 +0200 Subject: [PATCH] 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. --- render.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/render.c b/render.c index 2553c190..43bcf5eb 100644 --- a/render.c +++ b/render.c @@ -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; } }