From 48e0e0acf5b4e0a94280e1cd4919dd76e5ed57f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 14 Jun 2022 18:46:47 +0200 Subject: [PATCH] Wayland: Fix reporting of monitor scale changes Content scale events would be emitted when a window surface entered or left an output, but not when one of a window's current outputs had its scale changed. (cherry picked from commit e37ba80b1343f46d1b380fd3b9816e1260d8ee0a) --- README.md | 2 ++ src/wl_monitor.c | 12 ++++++++++++ src/wl_platform.h | 1 + src/wl_window.c | 6 +++--- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f86a7482..d93ca6e6 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,8 @@ information on what to include when reporting a bug. changed - [Wayland] Bugfix: `glfwTerminate` would segfault if any monitor had changed scale + - [Wayland] Bugfix: Window content scale events were not emitted when monitor + scale changed ## Contact diff --git a/src/wl_monitor.c b/src/wl_monitor.c index 5c97577e..99de8933 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -111,6 +111,18 @@ static void outputHandleScale(void* userData, struct _GLFWmonitor* monitor = userData; monitor->wl.scale = factor; + + for (_GLFWwindow* window = _glfw.windowListHead; window; window = window->next) + { + for (int i = 0; i < window->wl.monitorsCount; i++) + { + if (window->wl.monitors[i] == monitor) + { + _glfwUpdateContentScaleWayland(window); + break; + } + } + } } #ifdef WL_OUTPUT_NAME_SINCE_VERSION diff --git a/src/wl_platform.h b/src/wl_platform.h index 9616dd7f..288cf145 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -358,6 +358,7 @@ typedef struct _GLFWcursorWayland } _GLFWcursorWayland; void _glfwAddOutputWayland(uint32_t name, uint32_t version); +void _glfwUpdateContentScaleWayland(_GLFWwindow* window); GLFWbool _glfwInputTextWayland(_GLFWwindow* window, uint32_t scancode); void _glfwAddSeatListenerWayland(struct wl_seat* seat); diff --git a/src/wl_window.c b/src/wl_window.c index ef5e7a02..996bac8b 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -376,7 +376,7 @@ static void resizeWindow(_GLFWwindow* window) wl_surface_commit(window->wl.decorations.bottom.surface); } -static void checkScaleChange(_GLFWwindow* window) +void _glfwUpdateContentScaleWayland(_GLFWwindow* window) { if (_glfw.wl.compositorVersion < WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION) return; @@ -414,7 +414,7 @@ static void surfaceHandleEnter(void* userData, window->wl.monitors[window->wl.monitorsCount++] = monitor; - checkScaleChange(window); + _glfwUpdateContentScaleWayland(window); } static void surfaceHandleLeave(void* userData, @@ -435,7 +435,7 @@ static void surfaceHandleLeave(void* userData, } window->wl.monitors[--window->wl.monitorsCount] = NULL; - checkScaleChange(window); + _glfwUpdateContentScaleWayland(window); } static const struct wl_surface_listener surfaceListener =