Skip to content

Commit

Permalink
mac: Fix gamepad detection
Browse files Browse the repository at this point in the history
  • Loading branch information
rofferom committed Mar 1, 2020
1 parent 51e9e98 commit 5346216
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/joystick/hidapi/SDL_hidapijoystick.c
Expand Up @@ -43,6 +43,7 @@
#include <CoreFoundation/CoreFoundation.h>
#include <mach/mach.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/hid/IOHIDDevice.h>
#include <IOKit/usb/USBSpec.h>
#endif

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 5346216

Please sign in to comment.