Skip to content

[rcore][glfw] SetWindowSize(): set logical screen size with FLAG_WINDOW_HIGHDPI - #6363

Open
jqntn wants to merge 1 commit into
raysan5:masterfrom
jqntn:fix-setwindowsize-highdpi
Open

jqntn wants to merge 1 commit into
raysan5:masterfrom
jqntn:fix-setwindowsize-highdpi

Conversation

@jqntn

@jqntn jqntn commented Nov 3, 2026 •

Copy link
Copy Markdown

Fixes #6349

With FLAG_WINDOW_HIGHDPI on Windows and X11, SetWindowSize() stores the requested size in CORE.Window.screen. That size is in physical pixels, but CORE.Window.screen holds logical pixels. FramebufferSizeCallback() corrects it afterwards, but GLFW only calls it when the framebuffer size actually changes. So a same-size SetWindowSize() leaves GetScreenWidth()/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 as InitPlatform(). macOS and Wayland are left as they are, since the GLFW window size is already logical there. Nothing changes without FLAG_WINDOW_HIGHDPI.

Testing (the example from #6349):

GetScreenWidth()xGetScreenHeight() Windows 150%, before after X11 200%, before after
SetWindowSize(2000, 1100) 1333x733 1333x733 1000x550 1000x550
SetWindowSize(2000, 1100) again 2000x1100 1333x733 2000x1100 1000x550
  • Windows 11, 150% display scale, MSVC
  • Linux X11, Xvfb with Xft.dpi: 192 (scale 2.0), bundled GLFW

Without FLAG_WINDOW_HIGHDPI the 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:

  • This also fixes ToggleBorderlessWindowed() after a same-size SetWindowSize(). ToggleBorderlessWindowed() saves CORE.Window.screen when 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.
  • The SDL3 backend has the same problem (SDL 3.2.10, same X11 setup), along with a few other HighDPI issues: 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.
  • This uses the runtime check from InitPlatform() rather than #if !defined(_GLFW_WAYLAND). CMake builds only pass _GLFW_WAYLAND to GLFW's own sources, not to rcore.c, and when both X11 and Wayland are enabled, only a runtime check knows which one is in use. With the #if form, the conversion would run on Wayland in CMake builds and be skipped on X11 in Makefile/Zig builds with both backends. Passing _GLFW_WAYLAND to rcore.c in CMake, like [cmake][X11] Add x11 libraries for raylib as glfw make private #5625 did for _GLFW_X11, could be another PR as well.

@jqntn
jqntn force-pushed the fix-setwindowsize-highdpi branch from 5b90377 to 0b71486 Compare November 3, 2026 22:47
@jqntn
jqntn marked this pull request as ready for review November 3, 2026 23:06
@Ne0nWinds

Ne0nWinds commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

@raysan5 Is SetWindowSize() supposed to take physical or logical units? If it takes physical units, this PR is correct.

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 glfwSetWindowSize. Example:

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 SetWindowSize() is supposed to take physical units, I'll have to make some changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rcore][GLFW] Same-size SetWindowSize() leaves GetScreenWidth()/GetScreenHeight() at physical pixels (FLAG_WINDOW_HIGHDPI)

2 participants