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).
This commit is contained in:
SuperUserNameMan 2024-07-22 16:06:32 +02:00 committed by GitHub
parent c5f90a5edd
commit 1a7657ebd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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]));