From 43478ffed9788b3374f575f5fdb8eeb61897512f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 24 Jul 2026 10:08:59 +0530 Subject: [PATCH] Make block on xdg output information more robust Now does not block forever if output has zero size --- glfw/wl_monitor.c | 12 ++++++++---- glfw/wl_platform.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/glfw/wl_monitor.c b/glfw/wl_monitor.c index d05f13455..aa940a331 100644 --- a/glfw/wl_monitor.c +++ b/glfw/wl_monitor.c @@ -135,6 +135,7 @@ static void xdgOutputHandleLogicalPosition(void *data, struct _GLFWmonitor *monitor = data; monitor->wl.x = x; monitor->wl.y = y; + monitor->wl.xdg_position_received = true; } static void xdgOutputHandleLogicalSize(void *data, @@ -145,6 +146,7 @@ static void xdgOutputHandleLogicalSize(void *data, struct _GLFWmonitor *monitor = data; monitor->wl.xdg_logical_width = width; monitor->wl.xdg_logical_height = height; + monitor->wl.xdg_size_received = true; } static void computeXdgFractionalScale(struct _GLFWmonitor *monitor) @@ -364,13 +366,15 @@ GLFWAPI double glfwGetWaylandCurrentMonitorFractionalScale(void) // spuriously match (0, 0)). for (int i = 0; i < _glfw.monitorCount; i++) { _GLFWmonitor *m = _glfw.monitors[i]; - while (m->wl.xdg_output && m->wl.xdg_logical_width <= 0) { + while (m->wl.xdg_output && + !(m->wl.xdg_size_received && m->wl.xdg_position_received)) { if (wl_display_roundtrip(_glfw.wl.display) < 0) break; } } for (int i = 0; i < _glfw.monitorCount; i++) { _GLFWmonitor *m = _glfw.monitors[i]; - if (m->wl.xdg_output && m->wl.xdg_logical_width > 0 && + if (m->wl.xdg_output && m->wl.xdg_size_received && + m->wl.xdg_position_received && m->wl.x == 0 && m->wl.y == 0) { monitor = m; break; } } if (!monitor) @@ -380,8 +384,8 @@ GLFWAPI double glfwGetWaylandCurrentMonitorFractionalScale(void) if (!monitor->wl.xdg_output) return monitor->wl.scale > 0 ? (double)monitor->wl.scale : 1.0; - // Block until the compositor has delivered xdg_output logical_size. - while (monitor->wl.xdg_logical_width <= 0 || monitor->wl.xdg_logical_height <= 0) + // Block until the compositor has delivered xdg_output logical size and position. + while (!(monitor->wl.xdg_size_received && monitor->wl.xdg_position_received)) { if (wl_display_roundtrip(_glfw.wl.display) < 0) break; } diff --git a/glfw/wl_platform.h b/glfw/wl_platform.h index ebff9681b..4a1952190 100644 --- a/glfw/wl_platform.h +++ b/glfw/wl_platform.h @@ -485,6 +485,8 @@ typedef struct _GLFWmonitorWayland int32_t xdg_logical_width; int32_t xdg_logical_height; double fractional_scale; + bool xdg_size_received; + bool xdg_position_received; } _GLFWmonitorWayland;