Skip to content

Commit b7056a3

Browse files
committed
Fixed controller name when hotplugging the Nintendo Switch 2 Pro Controller
1 parent 8868a2c commit b7056a3

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/joystick/hidapi/SDL_hidapi_switch2.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,29 @@ static bool HIDAPI_DriverSwitch2_IsEnabled(void)
5151
static bool HIDAPI_DriverSwitch2_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
5252
{
5353
if (vendor_id == USB_VENDOR_NINTENDO) {
54-
if (product_id == USB_PRODUCT_NINTENDO_SWITCH2_PRO) {
54+
switch (product_id) {
55+
case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
56+
case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
5557
return true;
56-
}
57-
if (product_id == USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER) {
58-
return true;
59-
}
58+
}
6059
}
6160

6261
return false;
6362
}
6463

6564
static bool HIDAPI_DriverSwitch2_InitDevice(SDL_HIDAPI_Device *device)
6665
{
66+
// Sometimes the device handle isn't available during enumeration so we don't get the device name, so set it explicitly
67+
switch (device->product_id) {
68+
case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
69+
HIDAPI_SetDeviceName(device, "Nintendo GameCube Controller");
70+
break;
71+
case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
72+
HIDAPI_SetDeviceName(device, "Nintendo Switch Pro Controller");
73+
break;
74+
default:
75+
break;
76+
}
6777
return HIDAPI_JoystickConnected(device, NULL);
6878
}
6979

0 commit comments

Comments
 (0)