[v1 2/2] dinput/joystick_osx.c: sorts devices by location ID

David Lawrie david.dljunk at gmail.com
Fri Jun 24 20:33:16 CDT 2016


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 <david.dljunk at gmail.com>
---
 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)




More information about the wine-patches mailing list