SDL: Fixed duplicate Joy-Con controllers on macOS (78a92)

From 78a92b4f9d86ac242e0660e3e24866becdb7f7a9 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 22 May 2023 13:54:15 -0700
Subject: [PATCH] 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

(cherry picked from commit 61ef4efdfae7e384b0d24b1b171a9ee6203a3f0d)
---
 src/joystick/iphoneos/SDL_mfijoystick.m | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/joystick/iphoneos/SDL_mfijoystick.m b/src/joystick/iphoneos/SDL_mfijoystick.m
index b6b0954be776..8ed87e6fdb20 100644
--- a/src/joystick/iphoneos/SDL_mfijoystick.m
+++ b/src/joystick/iphoneos/SDL_mfijoystick.m
@@ -281,6 +281,7 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
             (is_ps4 && HIDAPI_IsDeviceTypePresent(SDL_CONTROLLER_TYPE_PS4)) ||
             (is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_CONTROLLER_TYPE_PS5)) ||
             (is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_CONTROLLER_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_CONTROLLER_TYPE_GOOGLE_STADIA))) {
             /* The HIDAPI driver is taking care of this device */
             return FALSE;
@@ -434,6 +435,17 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
         BOOL is_switch_joyconR = IsControllerSwitchJoyConR(controller);
         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) {
             vendor = USB_VENDOR_NINTENDO;
             product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT;