Repository navigation
SDL2: drain event queue every frame + relative mouse mode during gameplay - #49
Merged
Merged
Conversation
xjulian3x
force-pushed
the
fix/sdl2-relative-mouse
branch
from
October 1, 2026 00:32
6ea0fdb to
958b880
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two coupled problems in the SDL2 skeleton break mouse input:
inputEventHandler()polls exactly ONE event per call (if (SDL_PollEvent(...))) while mouse motion floods the queue — input lags seconds behind and most motion deltas are never processed._InputInitialiseMouseignoresexclusive,_InputMouseNeedsExclusive()returns false), andCPad::UpdateMouse()derives camera deltas from polledSDL_GetMouseStatepositions, which freeze at window/monitor boundaries — with a second monitor the hidden cursor wanders off-screen and the camera stalls; at output edges residual ±1px jitter causes a slow drift-spin.Fixes, all guarded by
LIBRW_SDL2(GLFW/X11 builds unaffected):inputEventHandler()drains the whole event queue per call (while), matching the GLFW skeleton.inputEventHandler()togglesSDL_SetRelativeMouseModeon gameplay/menu transitions (the frontend keeps absolute positions), zeroes the delta accumulators, resyncs the polled-position baseline on exit, clears deltas on focus loss, and releases the grab if a mode switch fails so the frontend can never be left with unusable coordinates.CPad::UpdateMouse()consumes the true motion-event deltas (xrel/yrel) accumulated in the skeleton instead of position differences. The event drain is a prerequisite — with one-event-per-frame polling most deltas would be discarded.Button and wheel handling unchanged.