SDL: Try to guess the type of a Nintendo Switch controller if we can't read the device info

From 6619de8f2441971b585f18e022668e1875d1991e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 12 Jun 2024 23:22:44 -0700
Subject: [PATCH] Try to guess the type of a Nintendo Switch controller if we
 can't read the device info

---
 src/joystick/hidapi/SDL_hidapi_switch.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 73967e7378d1c..246985715ac59 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -1279,6 +1279,27 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
             break;
         case k_eSwitchDeviceInfoControllerType_Unknown:
             /* We couldn't read the device info for this controller, might not be fully compliant */
+            if (device->vendor_id == USB_VENDOR_NINTENDO) {
+                switch (device->product_id) {
+                case USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT:
+                    ctx->m_eControllerType = k_eSwitchDeviceInfoControllerType_JoyConLeft;
+                    HIDAPI_SetDeviceName(device, "Nintendo Switch Joy-Con (L)");
+                    device->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT;
+                    break;
+                case USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT:
+                    ctx->m_eControllerType = k_eSwitchDeviceInfoControllerType_JoyConRight;
+                    HIDAPI_SetDeviceName(device, "Nintendo Switch Joy-Con (R)");
+                    device->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT;
+                    break;
+                case USB_PRODUCT_NINTENDO_SWITCH_PRO:
+                    ctx->m_eControllerType = k_eSwitchDeviceInfoControllerType_ProController;
+                    HIDAPI_SetDeviceName(device, "Nintendo Switch Pro Controller");
+                    device->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO;
+                    break;
+                default:
+                    break;
+                }
+            }
             return;
         default:
             device->type = SDL_GAMEPAD_TYPE_STANDARD;