diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 6824726f..e333ab7e 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -319,8 +319,9 @@ void _glfwInitJoysticks(void) while ((ioHIDDeviceObject = IOIteratorNext(objectIterator))) { + CFMutableDictionaryRef propsRef = NULL; + CFTypeRef valueRef = NULL; kern_return_t result; - CFTypeRef valueRef = 0; IOCFPlugInInterface** ppPlugInInterface = NULL; HRESULT plugInResult = S_OK; @@ -329,26 +330,29 @@ void _glfwInitJoysticks(void) long usagePage, usage; // Check device type - valueRef = IORegistryEntryCreateCFProperty(ioHIDDeviceObject, - CFSTR(kIOHIDPrimaryUsagePageKey), + result = IORegistryEntryCreateCFProperties(ioHIDDeviceObject, + &propsRef, kCFAllocatorDefault, kNilOptions); + + if (result != kIOReturnSuccess) + continue; + + valueRef = CFDictionaryGetValue(propsRef, CFSTR(kIOHIDPrimaryUsagePageKey)); if (valueRef) { CFNumberGetValue(valueRef, kCFNumberLongType, &usagePage); if (usagePage != kHIDPage_GenericDesktop) { // This device is not relevant to GLFW + CFRelease(valueRef); continue; } CFRelease(valueRef); } - valueRef = IORegistryEntryCreateCFProperty(ioHIDDeviceObject, - CFSTR(kIOHIDPrimaryUsageKey), - kCFAllocatorDefault, - kNilOptions); + valueRef = CFDictionaryGetValue(propsRef, CFSTR(kIOHIDPrimaryUsageKey)); if (valueRef) { CFNumberGetValue(valueRef, kCFNumberLongType, &usage); @@ -358,6 +362,7 @@ void _glfwInitJoysticks(void) usage != kHIDUsage_GD_MultiAxisController)) { // This device is not relevant to GLFW + CFRelease(valueRef); continue; } @@ -393,10 +398,7 @@ void _glfwInitJoysticks(void) joystick); // Get product string - valueRef = IORegistryEntryCreateCFProperty(ioHIDDeviceObject, - CFSTR(kIOHIDProductKey), - kCFAllocatorDefault, - kNilOptions); + valueRef = CFDictionaryGetValue(propsRef, CFSTR(kIOHIDProductKey)); if (valueRef) { CFStringGetCString(valueRef, @@ -410,10 +412,7 @@ void _glfwInitJoysticks(void) joystick->buttonElements = CFArrayCreateMutable(NULL, 0, NULL); joystick->hatElements = CFArrayCreateMutable(NULL, 0, NULL); - valueRef = IORegistryEntryCreateCFProperty(ioHIDDeviceObject, - CFSTR(kIOHIDElementKey), - kCFAllocatorDefault, - kNilOptions); + valueRef = CFDictionaryGetValue(propsRef, CFSTR(kIOHIDElementKey)); if (CFGetTypeID(valueRef) == CFArrayGetTypeID()) { CFRange range = { 0, CFArrayGetCount(valueRef) };