mac: Fix gamepad detection
authorRomain Roffé <rofferom@gmail.com>
Sun, 01 Mar 2020 13:01:53 -0800
changeset 13562e1a1a5a3e551
parent 13561 af818ab1c036
child 13563 75b324ae7bf6
mac: Fix gamepad detection
src/joystick/hidapi/SDL_hidapijoystick.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Sun Mar 01 13:00:50 2020 -0800
     1.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Sun Mar 01 13:01:53 2020 -0800
     1.3 @@ -43,6 +43,7 @@
     1.4  #include <CoreFoundation/CoreFoundation.h>
     1.5  #include <mach/mach.h>
     1.6  #include <IOKit/IOKitLib.h>
     1.7 +#include <IOKit/hid/IOHIDDevice.h>
     1.8  #include <IOKit/usb/USBSpec.h>
     1.9  #endif
    1.10  
    1.11 @@ -218,12 +219,15 @@
    1.12      SDL_HIDAPI_discovery.m_notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
    1.13      if (SDL_HIDAPI_discovery.m_notificationPort) {
    1.14          {
    1.15 -            CFMutableDictionaryRef matchingDict = IOServiceMatching("IOUSBDevice");
    1.16 -
    1.17 -            /* Note: IOServiceAddMatchingNotification consumes the reference to matchingDict */
    1.18              io_iterator_t portIterator = 0;
    1.19              io_object_t entry;
    1.20 -            if (IOServiceAddMatchingNotification(SDL_HIDAPI_discovery.m_notificationPort, kIOMatchedNotification, matchingDict, CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator) == 0) {
    1.21 +            IOReturn result = IOServiceAddMatchingNotification(
    1.22 +                SDL_HIDAPI_discovery.m_notificationPort,
    1.23 +                kIOFirstMatchNotification,
    1.24 +                IOServiceMatching(kIOHIDDeviceKey),
    1.25 +                CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator);
    1.26 +
    1.27 +            if (result == 0) {
    1.28                  /* Must drain the existing iterator, or we won't receive new notifications */
    1.29                  while ((entry = IOIteratorNext(portIterator)) != 0) {
    1.30                      IOObjectRelease(entry);
    1.31 @@ -234,12 +238,15 @@
    1.32              }
    1.33          }
    1.34          {
    1.35 -            CFMutableDictionaryRef matchingDict = IOServiceMatching("IOBluetoothDevice");
    1.36 -
    1.37 -            /* Note: IOServiceAddMatchingNotification consumes the reference to matchingDict */
    1.38              io_iterator_t portIterator = 0;
    1.39              io_object_t entry;
    1.40 -            if (IOServiceAddMatchingNotification(SDL_HIDAPI_discovery.m_notificationPort, kIOMatchedNotification, matchingDict, CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator) == 0) {
    1.41 +            IOReturn result = IOServiceAddMatchingNotification(
    1.42 +                SDL_HIDAPI_discovery.m_notificationPort,
    1.43 +                kIOTerminatedNotification,
    1.44 +                IOServiceMatching(kIOHIDDeviceKey),
    1.45 +                CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator);
    1.46 +
    1.47 +            if (result == 0) {
    1.48                  /* Must drain the existing iterator, or we won't receive new notifications */
    1.49                  while ((entry = IOIteratorNext(portIterator)) != 0) {
    1.50                      IOObjectRelease(entry);