Repository navigation
[rcore][glfw] SetWindowSize(), SetWindowMinSize(), SetWindowMaxSize(): use logical units with FLAG_WINDOW_HIGHDPI - #6363
Conversation
5b90377 to
0b71486
Compare
|
@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 |
|
@Ne0nWinds Definitely it should take logical units, aligned with InitWindow(), physical units are calculated and managed internally if HighDPI-awareness is required by user. |
|
@jqntn I think your PR does fix the specific issue in the bug. However, If you pass in a width of Here's a simple test: SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
InitWindow(800, 450, "example");
SetWindowSize(800, 450); // the window size shouldn't changeI think |
…ize()`: use logical HighDPI units
0b71486 to
0f458e5
Compare
SetWindowSize(): set logical screen size with FLAG_WINDOW_HIGHDPISetWindowSize(), SetWindowMinSize(), SetWindowMaxSize(): use logical units with FLAG_WINDOW_HIGHDPI
|
Thanks @Ne0nWinds and @raysan5 for the guidance, I think now we should be on the same page |
|
@jqntn thanks for the review.
Feel free to review it, all backends should be consistent |
Fixes #6349
With
FLAG_WINDOW_HIGHDPIon Windows and X11,SetWindowSize()passes the requested size straight to GLFW, so it's treated as physical pixels, whileInitWindow()takes logical units. It also stores that size inCORE.Window.screen, which holds 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 makes
SetWindowSize()take logical units, likeInitWindow(). The size is multiplied by the DPI scale before being passed to GLFW, using the same calculation and platform check asInitPlatform(), soCORE.Window.screenalways holds the logical size.SetWindowMinSize()andSetWindowMaxSize()get the same treatment. macOS and Wayland are left as they are, since the GLFW window size is already logical there. Nothing changes withoutFLAG_WINDOW_HIGHDPI.Testing (
FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE):InitWindow(800, 450)SetWindowSize(800, 450)SetWindowSize(500, 300)SetWindowSize(500, 300)againValues are
GetScreenWidth()xGetScreenHeight()(GetRenderWidth()xGetRenderHeight()).SetWindowMinSize(600, 350)andSetWindowMaxSize(1000, 600)now limit the window to 900x525 and 1500x900 at 150% (600x350 and 1000x600 before). On X11, the size hints are 1200x700 and 2000x1200 at 200%.Xft.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 in physical pixels, the restored window was too large. In the test above, toggling twice changed the window from 500x300 to 750x450 on Windows and 1000x600 on X11. With this PR, it stays at 750x450 and 1000x600.SetWindowMinSize()andSetWindowMaxSize()apply the DPI scale once, when they're called, and GLFW doesn't rescale the limits when the monitor scale changes. So on Windows, a 600x350 minimum set at 150% stays 900x525 after the window moves to a 100% monitor. Before this PR, the limits weren't scaled at all. X11 isn't affected because GLFW uses one global scale read at startup, and on macOS and Wayland the limits aren't scaled since GLFW already works in logical units there. This could be handled in another PR.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.