aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-09-17 15:37:58 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-09-17 15:37:58 +0000
commit2e7102c9563370e5ad160c0f712c90966b4724ce (patch)
treeddba20f978f6619f6d8130036d93933bb86d50ec
parentci: fix path to junit report on release builds (diff)
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.
-rw-r--r--render.c20
1 files 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;
}
}