Skip to content

Commit

Permalink
Async mouse and keyboard on Windows
Browse files Browse the repository at this point in the history
This works because SDL queries for raw mouse and keyboard input on a separate thread
and we sync all inputs to a `ConcurrentQueue`.
  • Loading branch information
Susko3 committed Apr 8, 2024
1 parent 5ab4f93 commit 7fac7bf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions osu.Framework/Platform/Windows/WindowsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,20 @@ private SDL_bool handleEventFromHook(MSG msg)

protected override int HandleEventFromFilter(SDL_Event evt)
{
bool rawMouse = SDL3.SDL_GetRelativeMouseMode() == SDL_bool.SDL_TRUE;

switch (evt.type)
{
// handle raw mouse and keyboard events in SDL_EventFilter for lower latency are resilience against SDL_PumpEvents() lag
case SDL_EventType.SDL_EVENT_MOUSE_MOTION when rawMouse:
case SDL_EventType.SDL_EVENT_MOUSE_BUTTON_DOWN when rawMouse:
case SDL_EventType.SDL_EVENT_MOUSE_BUTTON_UP when rawMouse:
case SDL_EventType.SDL_EVENT_MOUSE_WHEEL when rawMouse:
case SDL_EventType.SDL_EVENT_KEY_DOWN:
case SDL_EventType.SDL_EVENT_KEY_UP:
HandleEvent(evt);
return DROP_EVENT;

case SDL_EventType.SDL_EVENT_WINDOW_FOCUS_LOST:
warpCursorFromFocusLoss();
break;
Expand Down

0 comments on commit 7fac7bf

Please sign in to comment.