Removed extraneous windows message pumping Most of the raw input events are dispatched in the main windows message loop. We only dispatch device change messages separately when we need them to be completely up to date.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 7cf836e..e3a1ef7 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -89,10 +89,7 @@ extern HWND SDL_HelperWindow;
static SDL_bool SDL_RAWINPUT_inited = SDL_FALSE;
static int SDL_RAWINPUT_numjoysticks = 0;
-static SDL_bool SDL_RAWINPUT_need_pump = SDL_TRUE;
-static void RAWINPUT_JoystickDetect(void);
-static void RAWINPUT_PumpMessages(void);
static void RAWINPUT_JoystickClose(SDL_Joystick *joystick);
typedef struct _SDL_RAWINPUT_Device
@@ -611,6 +608,20 @@ RAWINPUT_QuitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
#endif /* SDL_JOYSTICK_RAWINPUT_WGI */
+
+/* Most of the time the raw input messages will get dispatched in the main event loop,
+ * but sometimes we want to get any pending device change messages immediately.
+ */
+static void
+RAWINPUT_GetPendingDeviceChanges(void)
+{
+ MSG msg;
+ while (PeekMessage(&msg, SDL_HelperWindow, WM_INPUT_DEVICE_CHANGE, WM_INPUT_DEVICE_CHANGE, PM_REMOVE)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+}
+
static int
RAWINPUT_JoystickInit(void)
{
@@ -642,8 +653,9 @@ RAWINPUT_JoystickInit(void)
SDL_RAWINPUT_inited = SDL_TRUE;
- RAWINPUT_JoystickDetect();
- RAWINPUT_PumpMessages();
+ /* Get initial controller connect messages */
+ RAWINPUT_GetPendingDeviceChanges();
+
return 0;
}
@@ -831,31 +843,6 @@ RAWINPUT_DelDevice(SDL_RAWINPUT_Device *device, SDL_bool send_event)
}
static void
-RAWINPUT_PumpMessages(void)
-{
- if (SDL_RAWINPUT_need_pump) {
- MSG msg;
- while (PeekMessage(&msg, SDL_HelperWindow, WM_INPUT, WM_INPUT, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- SDL_RAWINPUT_need_pump = SDL_FALSE;
- }
-}
-
-static void
-RAWINPUT_UpdateDeviceList(void)
-{
- MSG msg;
- /* In theory, want only WM_INPUT_DEVICE_CHANGE messages here, but PeekMessage returns nothing unless you also ask
- for WM_INPUT */
- while (PeekMessage(&msg, SDL_HelperWindow, WM_INPUT_DEVICE_CHANGE, WM_INPUT, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-}
-
-static void
RAWINPUT_PostUpdate(void)
{
#ifdef SDL_JOYSTICK_RAWINPUT_MATCHING
@@ -926,7 +913,7 @@ RAWINPUT_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version)
SDL_RAWINPUT_Device *device;
/* Make sure the device list is completely up to date when we check for device presence */
- RAWINPUT_UpdateDeviceList();
+ RAWINPUT_GetPendingDeviceChanges();
device = SDL_RAWINPUT_devices;
while (device) {
@@ -941,12 +928,7 @@ RAWINPUT_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version)
static void
RAWINPUT_JoystickDetect(void)
{
- /* Just ensure the window's add/remove messages have been pumped */
- RAWINPUT_UpdateDeviceList();
-
RAWINPUT_PostUpdate();
-
- SDL_RAWINPUT_need_pump = SDL_TRUE;
}
static SDL_RAWINPUT_Device *
@@ -1674,8 +1656,8 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
static void
RAWINPUT_JoystickUpdate(SDL_Joystick *joystick)
{
- /* Ensure data messages have been pumped */
- RAWINPUT_PumpMessages();
+ /* The input events have been handled in the main loop message pumping */
+
RAWINPUT_UpdateOtherAPIs(joystick);
}