Skip to content

Improve Windows raw input thread handling#15239

Merged
slouken merged 3 commits intolibsdl-org:mainfrom
whrvt:win-rawinput-register
Mar 23, 2026
Merged

Improve Windows raw input thread handling#15239
slouken merged 3 commits intolibsdl-org:mainfrom
whrvt:win-rawinput-register

Conversation

@whrvt
Copy link
Contributor

@whrvt whrvt commented Mar 20, 2026

Description

This is a followup to commits 43e90c7 and b9c227e.

The thread is still created once and only shut down on WIN_VideoQuit,
but the thread will unregister the devices when they're disabled to avoid
wasting time processing raw input that won't be appreciated by anyone.

This also allows RIDEV_NOLEGACY to be set on the devices, otherwise they
swallow up the WM_MOUSE* events that would be going to the main thread
when relative mode is disabled. That's out of scope for this change, though.

Also, fixed up some existing issues in the first 2 commits.

@whrvt whrvt force-pushed the win-rawinput-register branch from 256413a to fc983e8 Compare March 20, 2026 13:55
@whrvt
Copy link
Contributor Author

whrvt commented Mar 20, 2026

Just a small update to preemptively guard against an unlikely error scenario.

@whrvt
Copy link
Contributor Author

whrvt commented Mar 20, 2026

After testing this in my game, I realized that RegisterRawInputDevices itself is actually the culprit for the long delays, not the thread startup/shutdown itself. I'll update this with a slightly modified strategy that should work around that, though.

@whrvt whrvt force-pushed the win-rawinput-register branch 3 times, most recently from e97c76c to ad45bc6 Compare March 20, 2026 16:05
@whrvt
Copy link
Contributor Author

whrvt commented Mar 20, 2026

Updated to avoid declaring variables between goto/label.

@whrvt whrvt force-pushed the win-rawinput-register branch from ad45bc6 to abd1855 Compare March 20, 2026 16:55
@whrvt whrvt force-pushed the win-rawinput-register branch from abd1855 to 7182e71 Compare March 20, 2026 19:42
return SDL_Unsupported();
}

bool WIN_SetRawKeyboardFlag_Inputsink(SDL_VideoDevice *_this, bool enabled)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you mean to include this here?

Copy link
Contributor Author

@whrvt whrvt Mar 21, 2026

Choose a reason for hiding this comment

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

I sent it as a separate commit because I was already touching code near that and it's a minor change. Do you want me to drop it?
I did just notice that I messed up the splitting for the second commit, though, I'll fix that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, that's fine, I didn't realize it was just missing.

whrvt added 2 commits March 20, 2026 23:53
CreateEvent/CreateThread return NULL on failure.
The thread is still created once and only shut down on WIN_VideoQuit,
but the thread will unregister the devices when they're disabled to avoid
wasting time processing raw input that won't be appreciated by anyone.

This also allows RIDEV_NOLEGACY to be set on the devices, otherwise they
swallow up the WM_MOUSE* events that would be going to the main thread
when relative mode is disabled. That's out of scope for this change, though.
@whrvt whrvt force-pushed the win-rawinput-register branch from 7182e71 to 3402461 Compare March 21, 2026 06:56
@slouken slouken merged commit 983e984 into libsdl-org:main Mar 23, 2026
45 checks passed
@slouken
Copy link
Collaborator

slouken commented Mar 23, 2026

Merged, thanks!

@whrvt whrvt deleted the win-rawinput-register branch March 23, 2026 02:02
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