Skip to content

Scale mouse coordinates only when the main view has a logical presentation mode set - #625

Merged
Kontrabant merged 1 commit into
libsdl-org:mainfrom
Kontrabant:logical_scale_fix
Sep 17, 2026
Merged

Kontrabant merged 1 commit into
libsdl-org:mainfrom
Kontrabant:logical_scale_fix

Conversation

@Kontrabant

@Kontrabant Kontrabant commented Sep 17, 2026

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the SDL project under the zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

When a render target is set, querying the logical presentation mode will report the presentation mode on the render target, which can differ from the main view, and the main view properties are what is used to transform mouse coordinates. When a render target is bound, store the main view presentation mode, and use it to determine whether mouse coordinates in events should be implicitly scaled.

This should be a proper fix for the issue.

Fixes #624 without regressing #606

@Kontrabant
Kontrabant force-pushed the logical_scale_fix branch 2 times, most recently from 07e624e to b24bb51 Compare September 17, 2026 16:26
@Kontrabant Kontrabant changed the title Scale pointer coordinates when logical presentation is disabled and a… Scale mouse coordinates only when the main view has a logical presentation mode set Sep 17, 2026
@Kontrabant

Copy link
Copy Markdown
Contributor Author

Looking more at SDL2, this is definitely the correct fix for the issue, as SDL2 doesn't implicitly scale event values unless the window itself is using a logical presentation mode, and when a render target is attached, the 'backup' logical values are queried, which are equivalent to the "main view" in SDL3.

…ation mode set

When a render target is bound, querying the logical presentation mode will report the presentation mode on the render target, which can differ from the mode set on the main view. When a render target is bound, store the main view logical presentation mode and use it to determine whether mouse coordinates in events should be implicitly scaled, as the main view is always used to transform event coordinates.
@Kontrabant
Kontrabant merged commit 45bb7f6 into libsdl-org:main Sep 17, 2026
8 checks passed
@Kontrabant
Kontrabant deleted the logical_scale_fix branch September 17, 2026 17:07
@Kontrabant Kontrabant added this to the 2.32.74 milestone Sep 17, 2026
@bjorn

bjorn commented Sep 17, 2026

Copy link
Copy Markdown

Thanks for the quick fix!

@Kontrabant

Copy link
Copy Markdown
Contributor Author

No problem. Sorry about letting this bug slip through in the first place 🤦‍♂️.

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.

Mouse event coordinates are scaled twice when only SDL_RenderSetScale is used (2.32.72)

2 participants