Repository navigation
Conversation
jqntn
force-pushed
the
fix-setwindowsize-highdpi
branch
from
November 3, 2026 22:47
5b90377 to
0b71486
Compare
jqntn
marked this pull request as ready for review
November 3, 2026 23:06
Contributor
|
@raysan5 Is If it's supposed to take logical DPI units, we'd have to multiply (rather than divide) by the DPI scale and pass that into if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI) && (glfwGetPlatform() != GLFW_PLATFORM_WAYLAND))
{
Vector2 scaleDpi = GetWindowScaleDPI();
width = (int)roundf((float)width*scaleDpi.x);
height = (int)roundf((float)height*scaleDpi.y);
glfwSetWindowSize(platform.handle, width, height);
}
else
{
glfwSetWindowSize(platform.handle, width, height);
}My PR (#6352) uses logical DPI units, so if |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6349
With
FLAG_WINDOW_HIGHDPIon Windows and X11,SetWindowSize()stores the requested size inCORE.Window.screen. That size is in physical pixels, butCORE.Window.screenholds logical pixels.FramebufferSizeCallback()corrects it afterwards, but GLFW only calls it when the framebuffer size actually changes. So a same-sizeSetWindowSize()leavesGetScreenWidth()/GetScreenHeight()in physical pixels until the next resize.This PR stores the logical size directly, using the same calculation as
FramebufferSizeCallback()and the same platform check asInitPlatform(). macOS and Wayland are left as they are, since the GLFW window size is already logical there. Nothing changes withoutFLAG_WINDOW_HIGHDPI.Testing (the example from #6349):
GetScreenWidth()xGetScreenHeight()SetWindowSize(2000, 1100)SetWindowSize(2000, 1100)againXft.dpi: 192(scale 2.0), bundled GLFWWithout
FLAG_WINDOW_HIGHDPIthe output is identical before and after, and there are no new warnings with GCC (-Wall -Wextra) or MSVC. I haven't tested macOS or Wayland.Notes:
ToggleBorderlessWindowed()after a same-sizeSetWindowSize().ToggleBorderlessWindowed()savesCORE.Window.screenwhen entering borderless mode, then multiplies it by the DPI scale on exit to get the window size. Since the saved size was already in physical pixels, the restored window was too large. In the example, toggling twice restored a window with a 2564x1570 render size on Windows and 4000x2200 on X11. With this PR, it's 2000x1100 on both.InitWindow(800, 450)gives a 400x225 screen where GLFW gives 800x450, and its resize handler truncates the logical size where GLFW rounds it since [rcore][glfw] Round HighDPI window sizes instead of truncating #6346. Happy to fix those in a separate PR if you want.InitPlatform()rather than#if !defined(_GLFW_WAYLAND). CMake builds only pass_GLFW_WAYLANDto GLFW's own sources, not torcore.c, and when both X11 and Wayland are enabled, only a runtime check knows which one is in use. With the#ifform, the conversion would run on Wayland in CMake builds and be skipped on X11 in Makefile/Zig builds with both backends. Passing_GLFW_WAYLANDtorcore.cin CMake, like [cmake][X11] Add x11 libraries for raylib as glfw make private #5625 did for_GLFW_X11, could be another PR as well.