Skip to content

fix(sdl2): apply Linux desktop scaling to window size and UI scale - #54

Closed
FarnaHerry wants to merge 1 commit into
sudoevolve:devfrom
FarnaHerry:fix/sdl2-linux-hidpi
Closed

fix(sdl2): apply Linux desktop scaling to window size and UI scale#54
FarnaHerry wants to merge 1 commit into
sudoevolve:devfrom
FarnaHerry:fix/sdl2-linux-hidpi

Conversation

@FarnaHerry

Copy link
Copy Markdown
Contributor

What

On Linux, derive the desktop scaling factor from SDL display DPI (quantized to 0.25 steps, 1.25x minimum), enlarge newly created SDL windows by that factor, and use it as the dpiScale fallback when the drawable-to-window size ratio is 1.0.

Why

SDL drawables on Linux (X11 and Wayland) never reflect desktop scaling — the drawable size always equals the window size. The SDL2 backend therefore computed a dpiScale of 1.0 and rendered unscaled, physically smaller UI than GLFW builds on HiDPI desktops (e.g. 2x Wayland sessions). GLFW builds scale correctly because GLFW reads the desktop content scale directly; Windows was already handled via GetDpiForWindow; macOS reports a 2.0 drawable ratio.

How

  • Add core::window::displayScaleEstimate(), which quantizes SDL_GetDisplayDPI-derived scale to 0.25 steps and ignores values below 1.25x (avoids false positives from physical EDID-reported DPI on unscaled displays).
  • In createWindow (Linux SDL2 only), multiply the requested window size by that estimate so the buffer covers the same physical area as other backends.
  • In the SDL2 app entry point's dpiScale(), keep the drawable ratio as the primary source (macOS Retina) and fall back to displayScaleEstimate() so logical layout size, rendering scale, and pointer mapping stay consistent.

Testing

Verified on Fedora 44 (Wayland session, 2x desktop scaling, Xft.dpi=192) with all four backend combinations (OpenGL/Vulkan × GLFW/SDL2):

  • gallery and other examples in SDL2 builds now show the same physical window size and UI scale as GLFW builds, with native crispness (GLFW via XWayland is compositor-upscaled and slightly blurrier).
  • ctest results unchanged on all four builds: 19/20 passing.

Note: the single failing test, shadertoy_runtime_probe, already fails on the base dev branch (introduced by c404bde perf(render): cache static siblings, fails identically on all four backend builds) and is unrelated to this change.

What: On Linux, derive the desktop scaling factor from SDL display DPI
(quantized to 0.25 steps, 1.25x minimum), enlarge newly created windows
by that factor, and use it as the dpiScale fallback when the
drawable-to-window ratio is 1.0.

Why: SDL drawables on Linux (X11 and Wayland) never reflect desktop
scaling, so the SDL2 backend computed a dpiScale of 1.0 and rendered
unscaled, physically smaller UI than GLFW builds on HiDPI desktops.
GLFW reads the desktop content scale directly; Windows was already
handled via GetDpiForWindow; macOS reports a 2.0 drawable ratio.

How: Add core::window::displayScaleEstimate() sharing the display-DPI
quantization, multiply the SDL_CreateWindow size by it on Linux, and
fall back to it in the app entry point's dpiScale() so logical layout
size, rendering scale, and pointer mapping stay consistent.
@sudoevolve sudoevolve closed this Aug 10, 2026
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.

2 participants