Cocoa Port: Fix a bug where HID devices would fail to be detected on startup when running on macOS High Sierra.

This commit is contained in:
rogerman 2018-08-13 23:33:24 -07:00
parent 8448b3ee10
commit 208f99f4a6
2 changed files with 28 additions and 22 deletions

View File

@ -2238,6 +2238,7 @@
[inputManager setMappingsWithMappings:userMappings];
[[inputManager hidManager] setDeviceListController:inputDeviceListController];
[[inputManager hidManager] setRunLoop:[NSRunLoop currentRunLoop]];
// Set the microphone settings per user preferences.
[[cdsCore cdsController] setHardwareMicMute:[[NSUserDefaults standardUserDefaults] boolForKey:@"Microphone_HardwareMicMute"]];

View File

@ -116,31 +116,37 @@ static NSDictionary *hidUsageTable = nil;
CFRelease(elementArray);
// Set up force feedback.
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
ioService = IOHIDDeviceGetService(hidDeviceRef);
if (ioService != MACH_PORT_NULL)
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
if (IsOSXVersionSupported(10, 6, 0))
{
IOObjectRetain(ioService);
}
#else
ioService = MACH_PORT_NULL;
CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOHIDDeviceKey);
if (matchingDict)
{
CFStringRef locationKey = CFSTR(kIOHIDLocationIDKey);
CFTypeRef deviceLocation = IOHIDDeviceGetProperty(hidDeviceRef, locationKey);
if (deviceLocation != NULL)
ioService = IOHIDDeviceGetService(hidDeviceRef);
if (ioService != MACH_PORT_NULL)
{
CFDictionaryAddValue(matchingDict, locationKey, deviceLocation);
//This eats a reference to matchingDict, so we don't need a separate release.
//The result, meanwhile, has a reference count of 1 and must be released by the caller.
ioService = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
IOObjectRetain(ioService);
}
else
}
else
#else
{
ioService = MACH_PORT_NULL;
CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOHIDDeviceKey);
if (matchingDict)
{
CFRelease(matchingDict);
CFStringRef locationKey = CFSTR(kIOHIDLocationIDKey);
CFTypeRef deviceLocation = IOHIDDeviceGetProperty(hidDeviceRef, locationKey);
if (deviceLocation != NULL)
{
CFDictionaryAddValue(matchingDict, locationKey, deviceLocation);
//This eats a reference to matchingDict, so we don't need a separate release.
//The result, meanwhile, has a reference count of 1 and must be released by the caller.
ioService = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
}
else
{
CFRelease(matchingDict);
}
}
}
#endif
@ -865,7 +871,6 @@ void HandleQueueValueAvailableCallback(void *inContext, IOReturn inResult, void
CFRelease(cfGenericControllerMatcher);
spinlockRunLoop = OS_SPINLOCK_INIT;
[self setRunLoop:[NSRunLoop currentRunLoop]];
IOReturn result = IOHIDManagerOpen(hidManagerRef, kIOHIDOptionsTypeNone);
if (result != kIOReturnSuccess)