From 1de73c0dc545448dd40829a665c393fab19a5a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 8 Jan 2023 22:13:45 +0100 Subject: [PATCH] Wayland: Emit size event when setting aspect ratio (cherry picked from commit c1a79c1c41456a6fb0d2490a449eb4b2e0144302) --- src/wl_window.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 5c516e73..123039dd 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -2039,17 +2039,26 @@ void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, if (window->wl.maximized || window->wl.fullscreen) return; + int width = window->wl.width, height = window->wl.height; + if (numer != GLFW_DONT_CARE && denom != GLFW_DONT_CARE) { - const float aspectRatio = (float) window->wl.width / (float) window->wl.height; + const float aspectRatio = (float) width / (float) height; const float targetRatio = (float) numer / (float) denom; if (aspectRatio < targetRatio) - window->wl.height = window->wl.width / targetRatio; + height /= targetRatio; else if (aspectRatio > targetRatio) - window->wl.width = window->wl.height * targetRatio; + width *= targetRatio; + } + if (width != window->wl.width || height != window->wl.height) + { + window->wl.width = width; + window->wl.height = height; resizeWindow(window); + _glfwInputWindowSize(window, width, height); + if (window->wl.visible) _glfwInputWindowDamage(window); }