From 3f230027bf402a55a47d00634fbb327fb4744f54 Mon Sep 17 00:00:00 2001 From: 0xPD33 <0xPD33@proton.me> Date: Sun, 15 Feb 2026 23:45:11 +0100 Subject: [PATCH] Fix fullscreen and borderless windowed scaling on Wayland with HiDPI ToggleFullscreen and ToggleBorderlessWindowed exit paths manually scale screen size by DPI before passing to glfwSetWindowMonitor, which double-scales on Wayland where GLFW_SCALE_FRAMEBUFFER already handles it. Skip the manual resize on Wayland. Also fix FramebufferSizeCallback fullscreen branch: on Wayland with GLFW_SCALE_FRAMEBUFFER the framebuffer is still scaled in fullscreen, so use the logical window size as screen size and derive screenScale from the framebuffer/window ratio. Fixes #5504 --- src/platforms/rcore_desktop_glfw.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 9f1533479..4c4a6813f 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -221,7 +221,9 @@ void ToggleFullscreen(void) #if !defined(__APPLE__) // Make sure to restore render size considering HighDPI scaling - if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) + // NOTE: On Wayland, GLFW_SCALE_FRAMEBUFFER handles scaling, skip manual resize + if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI) && + (glfwGetPlatform() != GLFW_PLATFORM_WAYLAND)) { Vector2 scaleDpi = GetWindowScaleDPI(); CORE.Window.screen.width = (unsigned int)(CORE.Window.screen.width*scaleDpi.x); @@ -300,7 +302,9 @@ void ToggleBorderlessWindowed(void) #if !defined(__APPLE__) // Make sure to restore size considering HighDPI scaling - if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) + // NOTE: On Wayland, GLFW_SCALE_FRAMEBUFFER handles scaling, skip manual resize + if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI) && + (glfwGetPlatform() != GLFW_PLATFORM_WAYLAND)) { Vector2 scaleDpi = GetWindowScaleDPI(); CORE.Window.screen.width = (unsigned int)(CORE.Window.screen.width*scaleDpi.x); @@ -1871,6 +1875,23 @@ static void FramebufferSizeCallback(GLFWwindow *window, int width, int height) CORE.Window.screen.height = height; CORE.Window.screenScale = MatrixScale(1.0f, 1.0f, 1.0f); SetMouseScale(1.0f, 1.0f); + + // On Wayland with GLFW_SCALE_FRAMEBUFFER, the framebuffer is still scaled + // in fullscreen. Use logical window size as screen and apply screenScale. + if ((glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) && + FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) + { + int winWidth, winHeight; + glfwGetWindowSize(platform.handle, &winWidth, &winHeight); + if ((winWidth != width) || (winHeight != height)) + { + CORE.Window.screen.width = winWidth; + CORE.Window.screen.height = winHeight; + float scaleX = (float)width/winWidth; + float scaleY = (float)height/winHeight; + CORE.Window.screenScale = MatrixScale(scaleX, scaleY, 1.0f); + } + } } else // Window mode (including borderless window) {