From 1a7657ebd0b3ccbb98af0652dff41f0e870ce90d Mon Sep 17 00:00:00 2001 From: SuperUserNameMan <9801802+SuperUserNameMan@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:06:32 +0200 Subject: [PATCH] `rcore_desktop_glfw.c` : `SetWindowMonitor()` workaround for Wayland According to my understanding of current GLFW version, on Wayland, the only way to move the windowed window from one monitor to another is to toggle it to fullscreen twice (since only a fullscreen window can be moved to another monitor by code). --- src/platforms/rcore_desktop_glfw.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 07b58a030..10e1110d7 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -628,9 +628,6 @@ void SetWindowPosition(int x, int y) } // Set monitor for the current window -// NOTE : As of current version of Wayland and GLFW, it is not possible to set the position of a windowed -// window by code, so this fonction will not move it from a display to another. Instead, it will -// associate a monitor index to the window for fullscreen mode. void SetWindowMonitor(int monitor) { int monitorCount = 0; @@ -638,6 +635,7 @@ void SetWindowMonitor(int monitor) if ((monitor >= 0) && (monitor < monitorCount)) { + bool changingMonitor = (CORE.Window.lastAssociatedMonitorIndex != monitor); CORE.Window.lastAssociatedMonitorIndex = monitor; if ((CORE.Window.fullscreen) || IsWindowState(FLAG_BORDERLESS_WINDOWED_MODE)) @@ -648,6 +646,21 @@ void SetWindowMonitor(int monitor) glfwSetWindowMonitor(platform.handle, monitors[monitor], 0, 0, mode->width, mode->height, mode->refreshRate); } else + if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) + { + // On current implementation of Wayland and GLFW, + // this is the only way i found to move the window + // from one monitor to another : + + if (changingMonitor && !IsWindowState(FLAG_BORDERLESS_WINDOWED_MODE)) + { + //!\ TODO FIXME This workaround might causes some unexpected issues and could be improved + + ToggleBorderlessWindowed(); + ToggleBorderlessWindowed(); + } + } + else { TRACELOG(LOG_INFO, "GLFW: Selected monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor]));