Enable dispatching of WM_INPUT events directly, in case the application hasn't created a window with the normal message loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 0f505a4..d88e831 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -640,6 +640,20 @@ RAWINPUT_GetPendingDeviceChanges(void)
}
}
+static SDL_bool pump_device_events;
+static void
+RAWINPUT_GetPendingDeviceEvents(void)
+{
+ if (pump_device_events) {
+ MSG msg;
+ while (PeekMessage(&msg, SDL_HelperWindow, WM_INPUT, WM_INPUT + 1, PM_REMOVE)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ pump_device_events = SDL_FALSE;
+ }
+}
+
static int
RAWINPUT_JoystickInit(void)
{
@@ -673,6 +687,7 @@ RAWINPUT_JoystickInit(void)
/* Get initial controller connect messages */
RAWINPUT_GetPendingDeviceChanges();
+ pump_device_events = SDL_TRUE;
return 0;
}
@@ -917,6 +932,8 @@ RAWINPUT_PostUpdate(void)
guide_button_candidate.joystick = NULL;
#endif /* SDL_JOYSTICK_RAWINPUT_MATCHING */
+
+ pump_device_events = SDL_TRUE;
}
SDL_bool
@@ -1705,7 +1722,7 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
static void
RAWINPUT_JoystickUpdate(SDL_Joystick *joystick)
{
- /* The input events have been handled in the main loop message pumping */
+ RAWINPUT_GetPendingDeviceEvents();
RAWINPUT_UpdateOtherAPIs(joystick);
}