From 534621636845137e72df2000a4e5e2aacfec90a3 Mon Sep 17 00:00:00 2001 From: Romain Roff? Date: Sun, 1 Mar 2020 13:01:53 -0800 Subject: [PATCH] mac: Fix gamepad detection --- src/joystick/hidapi/SDL_hidapijoystick.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index de87fbcb8f6e1..ada3088a73bf4 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #endif @@ -218,12 +219,15 @@ HIDAPI_InitializeDiscovery() SDL_HIDAPI_discovery.m_notificationPort = IONotificationPortCreate(kIOMasterPortDefault); if (SDL_HIDAPI_discovery.m_notificationPort) { { - CFMutableDictionaryRef matchingDict = IOServiceMatching("IOUSBDevice"); - - /* Note: IOServiceAddMatchingNotification consumes the reference to matchingDict */ io_iterator_t portIterator = 0; io_object_t entry; - if (IOServiceAddMatchingNotification(SDL_HIDAPI_discovery.m_notificationPort, kIOMatchedNotification, matchingDict, CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator) == 0) { + IOReturn result = IOServiceAddMatchingNotification( + SDL_HIDAPI_discovery.m_notificationPort, + kIOFirstMatchNotification, + IOServiceMatching(kIOHIDDeviceKey), + CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator); + + if (result == 0) { /* Must drain the existing iterator, or we won't receive new notifications */ while ((entry = IOIteratorNext(portIterator)) != 0) { IOObjectRelease(entry); @@ -234,12 +238,15 @@ HIDAPI_InitializeDiscovery() } } { - CFMutableDictionaryRef matchingDict = IOServiceMatching("IOBluetoothDevice"); - - /* Note: IOServiceAddMatchingNotification consumes the reference to matchingDict */ io_iterator_t portIterator = 0; io_object_t entry; - if (IOServiceAddMatchingNotification(SDL_HIDAPI_discovery.m_notificationPort, kIOMatchedNotification, matchingDict, CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator) == 0) { + IOReturn result = IOServiceAddMatchingNotification( + SDL_HIDAPI_discovery.m_notificationPort, + kIOTerminatedNotification, + IOServiceMatching(kIOHIDDeviceKey), + CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator); + + if (result == 0) { /* Must drain the existing iterator, or we won't receive new notifications */ while ((entry = IOIteratorNext(portIterator)) != 0) { IOObjectRelease(entry);