Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_GetRelativeMouseState(): Get relative mouse position also when relative mouse mode is disabled #12289

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

Sackzement
Copy link
Contributor

Currently the relative mouse position is only set if relative mouse mode is enabled.
That makes SDL_GetRelativeMouseState() only work in relative mouse mode.

This commit removes the check for relative mouse mode and lets the variables be always set.

Fixes #12286

@slouken slouken merged commit 5dce8c7 into libsdl-org:main Feb 13, 2025
41 checks passed
@slouken
Copy link
Collaborator

slouken commented Feb 13, 2025

Merged, thanks!

@Sackzement Sackzement deleted the mouse-relative-pos branch February 13, 2025 19:59
@expikr
Copy link
Contributor

expikr commented Feb 13, 2025

This is completely wrong and should be reverted.

The author misunderstood the purpose of SDL_GetRelativeMouseState’s xy value which serves as a stateful accumulator for relative motion to emulate how legacy non-rawinput games use a constantly recentered cursor to calculate mouse motion once per frame instead of processing mouse motion in the event loop properly.

By definition, if you are not in relative mode then you are not generating relative motion.

Perhaps this is a documentation problem where the docs for the API function did not sufficiently clarify the purpose of this (legacy) functionality?

@slouken
Copy link
Collaborator

slouken commented Feb 13, 2025

SDL_GetRelativeMouseState() has always served as an accumulator of mouse deltas regardless of whether relative motion is enabled. We especially need to continue that behavior so sdl2-compat works correctly. If you need to flush that, just call SDL_GetRelativeMouseState() when you change relative mode, to clear the accumulator.

@expikr
Copy link
Contributor

expikr commented Feb 13, 2025

That wasn’t the impression I got while digging for its provenance, but if that had always been the intent from its inception, I suggest the documentation should be updated to clarify the intent of this function’s usage.

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.

SDL_GetRelativeMouseState always indicating 0 relative motion
3 participants