Skip to content

SDL2: drain event queue every frame + relative mouse mode during gameplay - #49

Merged
mrxenginner merged 1 commit into
mrxenginner:miamifrom
xjulian3x:fix/sdl2-relative-mouse
Oct 2, 2026
Merged

mrxenginner merged 1 commit into
mrxenginner:miamifrom
xjulian3x:fix/sdl2-relative-mouse

Conversation

@xjulian3x

@xjulian3x xjulian3x commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Two coupled problems in the SDL2 skeleton break mouse input:

  1. 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.
  2. The skeleton never grabs the pointer (_InputInitialiseMouse ignores exclusive, _InputMouseNeedsExclusive() returns false), and CPad::UpdateMouse() derives camera deltas from polled SDL_GetMouseState positions, 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() toggles SDL_SetRelativeMouseMode on 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.
  • While relative mode is active, 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.

@xjulian3x
xjulian3x force-pushed the fix/sdl2-relative-mouse branch from 6ea0fdb to 958b880 Compare October 1, 2026 00:32
@xjulian3x xjulian3x changed the title SDL2: relative mouse mode during gameplay (fixes cursor escaping the window / edge stalls) SDL2: drain event queue every frame + relative mouse mode during gameplay Oct 1, 2026
@mrxenginner
mrxenginner merged commit a26fff4 into mrxenginner:miami Oct 2, 2026
1 of 22 checks passed
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