From ff85d4fbe5c013093a956f1126017e61d9ed37cd Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 8 Sep 2021 17:51:47 -0700 Subject: [PATCH] Fixed Xbox Series X controller being detected by both IOKit and GCController on macOS --- src/joystick/iphoneos/SDL_mfijoystick.m | 27 ++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/joystick/iphoneos/SDL_mfijoystick.m b/src/joystick/iphoneos/SDL_mfijoystick.m index 5283199f4..6563c9141 100644 --- a/src/joystick/iphoneos/SDL_mfijoystick.m +++ b/src/joystick/iphoneos/SDL_mfijoystick.m @@ -1491,7 +1491,32 @@ IOS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out) SDL_bool IOS_SupportedHIDDevice(IOHIDDeviceRef device) { if (is_macos11()) { - return [GCController supportsHIDDevice:device] ? SDL_TRUE : SDL_FALSE; + if ([GCController supportsHIDDevice:device]) { + return SDL_TRUE; + } + + /* GCController supportsHIDDevice may return false if the device hasn't been + * seen by the framework yet, so check a few controllers we know are supported. + */ + { + Sint32 vendor = 0; + Sint32 product = 0; + CFTypeRef refCF = NULL; + + refCF = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)); + if (refCF) { + CFNumberGetValue(refCF, kCFNumberSInt32Type, &vendor); + } + + refCF = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey)); + if (refCF) { + CFNumberGetValue(refCF, kCFNumberSInt32Type, &product); + } + + if (vendor == USB_VENDOR_MICROSOFT && SDL_IsJoystickXboxSeriesX(vendor, product)) { + return SDL_TRUE; + } + } } return SDL_FALSE; }