Commit d77eb8a8d5c201e53de7019d26d81500fa9897a0

Sam Lantinga 2023-02-08T14:22:39

Make sure we synchronously re-enable USB reporting mode for Switch controllers (thanks @SortaCore!) Fixes https://github.com/libsdl-org/SDL/issues/3450 (cherry picked from commit b7c6fec10a152e47f8fa18350134188b75e9df0b)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 168a2df..bfc6976 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -2163,7 +2163,11 @@ static SDL_bool HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
                 const Uint32 INPUT_WAIT_TIMEOUT_MS = 100;
                 if (SDL_TICKS_PASSED(now, ctx->m_unLastInput + INPUT_WAIT_TIMEOUT_MS)) {
                     /* Steam may have put the controller back into non-reporting mode */
+                    SDL_bool wasSyncWrite = ctx->m_bSyncWrite;
+
+                    ctx->m_bSyncWrite = SDL_TRUE;
                     WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_ForceUSB, NULL, 0, SDL_FALSE);
+                    ctx->m_bSyncWrite = wasSyncWrite;
                 }
             } else if (device->is_bluetooth) {
                 const Uint32 INPUT_WAIT_TIMEOUT_MS = 3000;