[v2 2/3] dinput: Sort devices by location ID on the Mac

David Lawrie david.dljunk at gmail.com
Thu Jun 30 03:40:18 CDT 2016


Tested on OS X 10.10.5.

Signed-off-by: David Lawrie <david.dljunk at gmail.com>
---
Fixes https://bugs.winehq.org/show_bug.cgi?id=38997
for dinput joysticks

 dlls/dinput/joystick_osx.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c
index 7885988..ec0292b 100644
--- a/dlls/dinput/joystick_osx.c
+++ b/dlls/dinput/joystick_osx.c
@@ -207,6 +207,20 @@ static void CFSetApplierFunctionCopyToCFArray(const void *value, void *context)
     CFArrayAppendValue( ( CFMutableArrayRef ) context, value );
 }
 
+static CFComparisonResult device_location_comparator(const void *val1, const void *val2, void *context)
+{
+    CFComparisonResult result = kCFCompareEqualTo;
+
+    long loc1 = get_device_location_ID(val1);
+    long loc2 = get_device_location_ID(val2);
+
+    if (loc1 < loc2)
+        result = kCFCompareLessThan;
+    else if (loc1 > loc2)
+        result = kCFCompareGreaterThan;
+    return result;
+}
+
 static const char* debugstr_cf(CFTypeRef t)
 {
     CFStringRef s;
@@ -481,6 +495,7 @@ static int find_osx_devices(void)
         CFSetApplyFunction(devset, CFSetApplierFunctionCopyToCFArray, devices);
         CFRelease( devset);
         num_devices = CFArrayGetCount(devices);
+        CFArraySortValues(devices, CFRangeMake(0, num_devices), device_location_comparator, 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