From: David Lawrie Subject: [v1 2/2] dinput/joystick_osx.c: sorts devices by location ID Message-Id: <1466818397-52671-3-git-send-email-david.dljunk@gmail.com> Date: Fri, 24 Jun 2016 18:33:16 -0700 In-Reply-To: <1466818397-52671-1-git-send-email-david.dljunk@gmail.com> References: <1466818397-52671-1-git-send-email-david.dljunk@gmail.com> Fixes https://bugs.winehq.org/show_bug.cgi?id=38997 for dinput joysticks Note: if multiple virtual joysticks have the same location ID, they will still be unordered Tested on OS X 10.10.5. Signed-off-by: David Lawrie --- dlls/dinput/joystick_osx.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c index fea72c1..f13c71a 100644 --- a/dlls/dinput/joystick_osx.c +++ b/dlls/dinput/joystick_osx.c @@ -208,6 +208,22 @@ static void CFSetApplierFunctionCopyToCFArray(const void *value, void *context) CFArrayAppendValue( ( CFMutableArrayRef ) context, value ); } +static CFComparisonResult CFDeviceArrayComparatorFunction(const void *val1, const void *val2, void *context) +{ +#pragma unused(context) + CFComparisonResult result = kCFCompareEqualTo; + + long loc1 = IOHIDDevice_GetLocationID((IOHIDDeviceRef)val1); + long loc2 = IOHIDDevice_GetLocationID((IOHIDDeviceRef)val2); + + if (loc1 < loc2) { + result = kCFCompareLessThan; + } else if (loc1 > loc2) { + result = kCFCompareGreaterThan; + } + return result; +} + static const char* debugstr_cf(CFTypeRef t) { CFStringRef s; @@ -482,6 +498,7 @@ static int find_osx_devices(void) CFSetApplyFunction(devset, CFSetApplierFunctionCopyToCFArray, devices); CFRelease( devset); num_devices = CFArrayGetCount(devices); + CFArraySortValues(devices, CFRangeMake(0, num_devices), CFDeviceArrayComparatorFunction, NULL); device_main_elements = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); if (!device_main_elements) -- 1.7.12.4 (Apple Git-37)