From 5da80062d9de17a4fdcfdb993021da4c27115cc0 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 1 May 2020 00:34:00 +0300 Subject: [PATCH] Fix WUP-028 on Catalina, make controller configuration compatible between macOS versions --- JoyKit/JOYElement.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/JoyKit/JOYElement.m b/JoyKit/JOYElement.m index 56fcb36..6539c2e 100644 --- a/JoyKit/JOYElement.m +++ b/JoyKit/JOYElement.m @@ -41,6 +41,24 @@ IOHIDElementRef parent = IOHIDElementGetParent(element); _parentID = parent? (uint32_t)IOHIDElementGetCookie(parent) : -1; _device = IOHIDElementGetDevice(element); + + /* Catalina added a new input type in a way that breaks cookie consistency across macOS versions, + we shall adjust our cookies to to compensate */ + unsigned cookieShift = 0, parentCookieShift = 0; + NSArray *nones = CFBridgingRelease(IOHIDDeviceCopyMatchingElements(IOHIDElementGetDevice(element), + (__bridge CFDictionaryRef)@{@(kIOHIDElementTypeKey): @(kIOHIDElementTypeInput_NULL)}, + 0)); + for (id none in nones) { + if (IOHIDElementGetCookie((__bridge IOHIDElementRef) none) < _uniqueID) { + cookieShift++; + } + if (IOHIDElementGetCookie((__bridge IOHIDElementRef) none) < (int32_t)_parentID) { + parentCookieShift++; + } + } + + _uniqueID -= cookieShift; + _parentID -= parentCookieShift; } return self; }