From 8d4f10fcc0837573a54ccc1f3c9951fa2bedd6ed Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sun, 8 Aug 2021 20:55:26 -0500 Subject: [PATCH] wayland: fix keepaspect-window during resize So the resizing mechanism is actually supposed to match the video size to the window size while preserving the aspect ratio. In wayland, the current logic behaves as if --no-keepaspect-window was set. Fix this by simply multiplying the height by the same scale factor the width is multiplied by. Also get rid of the pointless (width > height) test (it makes no difference in any case) as well as some unneccesary checks for the keepaspect-window option. The use of ceil here is to make sure the window coordinates can never possibly have be 0 due to truncation (weston can still give you a 1x1 window which is fun). Fixes #9098. --- video/out/wayland_common.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 8e03be84ab..e34c84a0b4 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -859,14 +859,11 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel, return; if (!is_fullscreen && !is_maximized) { - if (vo_opts->keepaspect && vo_opts->keepaspect_window) { - if (width > height) { - double scale_factor = (double)width / wl->reduced_width; - width = wl->reduced_width * scale_factor; - } else { - double scale_factor = (double)height / wl->reduced_height; - height = wl->reduced_height * scale_factor; - } + if (vo_opts->keepaspect) { + double scale_factor = (double)width / wl->reduced_width; + width = ceil(wl->reduced_width * scale_factor); + if (vo_opts->keepaspect_window) + height = ceil(wl->reduced_height * scale_factor); } wl->window_size.x0 = 0; wl->window_size.y0 = 0; @@ -1761,7 +1758,7 @@ int vo_wayland_reconfig(struct vo *vo) set_geometry(wl); - if (wl->vo_opts->keepaspect && wl->vo_opts->keepaspect_window) + if (wl->vo_opts->keepaspect) wl->window_size = wl->vdparams; if (!wl->vo_opts->fullscreen && !wl->vo_opts->window_maximized)