From 91f18fb57697c57bf9da64ad546eed5c60518618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 14 Jun 2022 20:37:31 +0200 Subject: [PATCH] Wayland: Fix error from glfwSetWindowAspectRatio The aspect ratio was applied during resize but any call to glfwSetWindowAspectRatio emitted a GLFW_FEATURE_UNIMPLEMENTED error. --- README.md | 2 ++ src/wl_window.c | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ccc3eae6..6a10ae5c 100644 --- a/README.md +++ b/README.md @@ -355,6 +355,8 @@ information on what to include when reporting a bug. scale - [Wayland] Bugfix: Window content scale events were not emitted when monitor scale changed + - [Wayland] Bugfix: `glfwSetWindowAspectRatio` reported an error instead of + applying the specified ratio - [POSIX] Removed use of deprecated function `gettimeofday` - [POSIX] Bugfix: `CLOCK_MONOTONIC` was not correctly tested for or enabled - [WGL] Disabled the DWM swap interval hack for Windows 8 and later (#1072) diff --git a/src/wl_window.c b/src/wl_window.c index 73938e90..f3dd2de1 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1923,10 +1923,20 @@ void _glfwSetWindowSizeLimitsWayland(_GLFWwindow* window, void _glfwSetWindowAspectRatioWayland(_GLFWwindow* window, int numer, int denom) { - // TODO: find out how to trigger a resize. - // The actual limits are checked in the xdg_toplevel::configure handler. - _glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, - "Wayland: Window aspect ratio not yet implemented"); + if (window->wl.maximized || window->wl.fullscreen) + return; + + if (numer != GLFW_DONT_CARE && denom != GLFW_DONT_CARE) + { + const float aspectRatio = (float) window->wl.width / (float) window->wl.height; + const float targetRatio = (float) numer / (float) denom; + if (aspectRatio < targetRatio) + window->wl.height = window->wl.width / targetRatio; + else if (aspectRatio > targetRatio) + window->wl.width = window->wl.height * targetRatio; + + resizeWindow(window); + } } void _glfwGetFramebufferSizeWayland(_GLFWwindow* window, int* width, int* height)