summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/SDL
diff options
context:
space:
mode:
authorShawn Hoffman <godisgovernment@gmail.com>2022-04-18 04:09:38 -0700
committerShawn Hoffman <godisgovernment@gmail.com>2022-07-10 15:39:06 -0700
commit54b4ad8f559d6fa16bf0ca15f91de4e7d103996f (patch)
tree89a827e4e0a717547cdff56b9e803864e1171e0e /Source/Core/InputCommon/ControllerInterface/SDL
parentddf83462ac1139e76d6f0732ed83fe41fa9a9050 (diff)
ci/sdl: pump messages for SDL_hidapi so device detection works
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/SDL')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp
index 4a08e27880..6dec6003fd 100644
--- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp
@@ -15,6 +15,8 @@
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#ifdef _WIN32
+#include <Windows.h>
+
#pragma comment(lib, "SDL2.lib")
#endif
@@ -204,11 +206,34 @@ void Init()
}
}
+#ifdef _WIN32
+ // This is a hack to workaround SDL_hidapi using window messages to detect device
+ // removal/arrival, yet no part of SDL pumps messages for it. It can hopefully be removed in the
+ // future when SDL fixes the issue. Note this is a separate issue from SDL_HINT_JOYSTICK_THREAD.
+ // Also note that SDL_WaitEvent may block while device detection window messages get queued up,
+ // causing some noticible stutter. This is just another reason it should be fixed properly by
+ // SDL...
+ const auto window_handle =
+ FindWindowEx(HWND_MESSAGE, nullptr, TEXT("SDL_HIDAPI_DEVICE_DETECTION"), nullptr);
+#endif
+
SDL_Event e;
while (SDL_WaitEvent(&e) != 0)
{
if (!HandleEventAndContinue(e))
return;
+
+#ifdef _WIN32
+ MSG msg;
+ while (window_handle && PeekMessage(&msg, window_handle, 0, 0, PM_NOREMOVE))
+ {
+ if (GetMessageA(&msg, window_handle, 0, 0) != 0)
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+#endif
}
});