From 8581d6850bb4cf9229e99de188b339da50eee777 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 24 Apr 2020 22:52:02 +0200 Subject: [PATCH] Stabilize auto-resize The window dimensions are integers, so resizing to fit the content may not be exact. When computing the optimal size, it could cause to reduce alternatively the width and height by few pixels, making the "optimal size" unstable. To avoid this problem, check if the optimal size is already correct either by keeping the width or the height. --- app/src/screen.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/screen.c b/app/src/screen.c index d4f96a39..a9019172 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -113,6 +113,13 @@ get_optimal_size(struct size current_size, struct size content_size) { h = MIN(current_size.height, display_size.height); } + if (h == w * content_size.height / content_size.width + || w == h * content_size.width / content_size.height) { + // The size is already optimal, if we ignore rounding errors due to + // integer window dimensions + return (struct size) {w, h}; + } + bool keep_width = content_size.width * h > content_size.height * w; if (keep_width) { // remove black borders on top and bottom