Skip to content

Conversation

@rachel-bousfield
Copy link

@rachel-bousfield rachel-bousfield commented Nov 6, 2025

Summary

Bugfixes "Fix the scaling factor for high-dpi displays."

Purpose of change

The number of pixels returned by SDL_GetWindowSize do not take into account dpi scaling, like on Apple Retina displays. Thankfully SDL 2.26 (Nov 2022) provides a SDL_GetWindowSizeInPixels for accounting for exactly this.

Additionally, even in full screen mode the dimensions of SDL_DisplayMode are incorrect due to SDL_GetDesktopDisplayMode similarly not factoring in dpi scale.

Describe the solution

Switch to SDL_GetWindowSizeInPixels and implement a new get_display_scale function for measuring the dpi scaling ratios. The measurement creates a small, hidden window to quickly measure the horizontal and vertical stretch necessary to account for dpi. On failure the return values are 1x, ensuring no logical change.

Describe alternatives you've considered

One could perhaps imagine a larger refactor where we always perform window measurements, but even in this case we'd want precisely the same affordance provided by get_display_scale. This keeps things minimal and known to not break other platforms.

Testing

I've tested this on my MacBook in each mode, though given it's backend agnostic it should work cross-platform. A friend has also on Windows and I'll soon be on Linux with an intentionally out-dated SDL version too.

EDIT: Confirmed it works on Linux with and without old versions of SDL (pre 2022)

Additional context

None

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) new contributor labels Nov 6, 2025
rachel-bousfield and others added 2 commits November 6, 2025 14:29
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@rachel-bousfield
Copy link
Author

Apologies, it's my first time contributing. Feel free to change what this points against. The code in question hasn't changed in many years so it shouldn't matter

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Hi @rachel-bousfield, welcome to CleverRaven! We see that this is your first time commenting here. Check out how development works and be sure to follow the code of conduct! We hope to see you around!

@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Nov 6, 2025
rachel-bousfield and others added 3 commits November 6, 2025 14:43
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@rachel-bousfield
Copy link
Author

rachel-bousfield commented Nov 6, 2025

Tested to confirm this works on Linux both with and without outdated (pre 2022) versions of SDL2

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Hi @rachel-bousfield, welcome to CleverRaven! We see that this is your first time commenting here. Check out how development works and be sure to follow the code of conduct! We hope to see you around!

@github-actions github-actions bot added BasicBuildPassed This PR builds correctly, label assigned by github actions and removed BasicBuildPassed This PR builds correctly, label assigned by github actions labels Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

astyled astyled PR, label is assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions new contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants