From 4361920501bf8027c2d0f7fcb4a43bde7cf0f503 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 11 Feb 2026 09:11:37 -0800
Subject: [PATCH] Fixed HIDAPI hotplug detection in applications that don't
initialize video
(cherry picked from commit eaeca340f3828aa706e2cff05bafb61e9132c7f7)
---
src/SDL.c | 5 +++++
src/SDL_internal.h | 3 +++
src/hidapi/SDL_hidapi.c | 2 +-
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/SDL.c b/src/SDL.c
index 2128438c6e861..767921589f7b1 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -280,6 +280,11 @@ bool SDL_IsMainThread(void)
return true;
}
+bool SDL_IsVideoThread(void)
+{
+ return (SDL_GetCurrentThreadID() == SDL_VideoThreadID);
+}
+
// Initialize all the subsystems that require initialization before threads start
void SDL_InitMainThread(void)
{
diff --git a/src/SDL_internal.h b/src/SDL_internal.h
index 3fa50c30f06e1..5d1fd3eab2aae 100644
--- a/src/SDL_internal.h
+++ b/src/SDL_internal.h
@@ -306,6 +306,9 @@ extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
// Do any initialization that needs to happen before threads are started
extern void SDL_InitMainThread(void);
+// Return true if this thread has initialized video
+extern bool SDL_IsVideoThread(void);
+
/* The internal implementations of these functions have up to nanosecond precision.
We can expose these functions as part of the API if we want to later.
*/
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index f3de6b344b83e..0dda4d4ba18a7 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -388,7 +388,7 @@ static void HIDAPI_UpdateDiscovery(void)
}
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
- if (SDL_IsMainThread()) {
+ if (SDL_IsVideoThread()) {
// just let the usual SDL_PumpEvents loop dispatch these, fixing bug 2998. --ryan.
} else {
// We'll only get messages on the same thread that created the window