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

Async mouse and keyboard input on windows #6235

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Susko3
Copy link
Member

@Susko3 Susko3 commented Apr 8, 2024

Depends on:

This PR simply handles relative mouse and keyboard events in the SDL_EventFilter i.e. HandleEventFromFilter.

This works because SDL queries raw mouse and keyboard inputs on a separate thread. Our SDL_EventFilter will intercept those events before they are pushed to the internal SDL queue, handle them, and then request SDL to drop them.

Testing

Apply the diff and toggle relative mouse mode in TestSceneInputManger.
This isn't a perfect simulation of SDL_PumpEvents() lag, but it shows the async input in action.

diff --git a/osu.Framework/Platform/SDL3Window.cs b/osu.Framework/Platform/SDL3Window.cs
index aac3baf44..737547203 100644
--- a/osu.Framework/Platform/SDL3Window.cs
+++ b/osu.Framework/Platform/SDL3Window.cs
@@ -460,6 +460,7 @@ private void setSDLIcon(Image<Rgba32> image)
         private void pollSDLEvents()
         {
             SDL3.SDL_PumpEvents();
+            Thread.Sleep(100);
 
             int eventsRead;

This works because SDL queries for raw mouse and keyboard input on a separate thread
and we sync all inputs to a `ConcurrentQueue`.
@peppy peppy self-requested a review April 15, 2024 03:41
@peppy
Copy link
Member

peppy commented Apr 15, 2024

This seems to break input on my VM setup. Yes I have a weird setup but it did work, so something has potentially changed or broken. I haven't yet investigated why, but can if required (if the issue isn't obvious).

master:

2024-04-15.15.35.29.mp4

this PR:

2024-04-15.15.34.02.mp4

Copy link
Member

@peppy peppy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented

@Susko3
Copy link
Member Author

Susko3 commented Apr 15, 2024

Hmm, it's weird that the relative mouse movements align with the cursor in one scenario but not the other. But I wouldn't call it broken, the framework cursor is still moving proportionally to your mouse movements.

The weirder thing is that the mouse cursor isn't hidden when in relative mode.

I have no idea what could cause any of this. But if you'll be looking at this, don't forget to enable event logging with

SDL3.SDL_SetHint(SDL3.SDL_HINT_EVENT_LOGGING, "2"u8);

@peppy
Copy link
Member

peppy commented Apr 16, 2024

the framework cursor is still moving proportionally to your mouse movements

I tried to show this, but it's actually not proportionally correct either. I'll see what I can find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants