Fixed duplicate Joy-Con controllers on macOS

If both Apple and HIDAPI drivers see the controller, HIDAPI will be preferred.

Fixes https://github.com/libsdl-org/SDL/issues/7479
main
Sam Lantinga 2023-05-22 13:54:15 -07:00
parent cf0abf9911
commit 61ef4efdfa
1 changed files with 12 additions and 0 deletions

View File

@ -288,6 +288,7 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
(is_ps4 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS4)) || (is_ps4 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS4)) ||
(is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS5)) || (is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS5)) ||
(is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO)) || (is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO)) ||
(is_switch_joycon_pair && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR, 0, "")) ||
(is_stadia && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_GOOGLE_STADIA))) { (is_stadia && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_GOOGLE_STADIA))) {
/* The HIDAPI driver is taking care of this device */ /* The HIDAPI driver is taking care of this device */
return FALSE; return FALSE;
@ -443,6 +444,17 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
BOOL is_switch_joyconR = IsControllerSwitchJoyConR(controller); BOOL is_switch_joyconR = IsControllerSwitchJoyConR(controller);
int nbuttons = 0; int nbuttons = 0;
#ifdef SDL_JOYSTICK_HIDAPI
if ((is_switch_joyconL && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT, 0, "")) ||
(is_switch_joyconR && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT, 0, ""))) {
/* The HIDAPI driver is taking care of this device */
return FALSE;
}
#else
(void)is_switch_joyconL;
(void)is_switch_joyconR;
#endif
if (is_switch_joyconL) { if (is_switch_joyconL) {
vendor = USB_VENDOR_NINTENDO; vendor = USB_VENDOR_NINTENDO;
product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT; product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT;