From 1940dbccfdc4f807c99974fa6872553d0c16fb55 Mon Sep 17 00:00:00 2001 From: p0ryae Date: Fri, 28 Nov 2025 11:54:07 -0800 Subject: [PATCH] Wayland: Fix drag-window segfault by using xdg_toplevel from libdecor glfwDragWindow() previously assumed window->wl.xdg.toplevel was always valid, which is not the case when libdecor provides server-side decorations. This caused window dragging to fail and segfault on native Wayland. The fix retrieves the xdg_toplevel from the libdecor frame when available and adds validation checks for missing seat or serial to prevent additional edge cases. --- src/wl_window.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/wl_window.c b/src/wl_window.c index 746ab800d..7173130ed 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -2565,7 +2565,33 @@ void _glfwFocusWindowWayland(_GLFWwindow* window) void _glfwDragWindowWayland(_GLFWwindow* window) { - xdg_toplevel_move(window->wl.xdg.toplevel, _glfw.wl.seat, _glfw.wl.serial); + struct xdg_toplevel* toplevel = + window->wl.libdecor.frame ? + libdecor_frame_get_xdg_toplevel(window->wl.libdecor.frame) : + window->wl.xdg.toplevel; + + if (!toplevel) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Wayland: Cannot drag window: xdg_toplevel not created yet"); + return; + } + + if (!_glfw.wl.seat) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Wayland: Cannot drag window: no valid seat"); + return; + } + + if (_glfw.wl.serial == 0) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Wayland: Cannot drag window: no valid serial"); + return; + } + + xdg_toplevel_move(toplevel, _glfw.wl.seat, _glfw.wl.serial); } void _glfwSetWindowMonitorWayland(_GLFWwindow* window,