David Lawrie : winejoystick.drv: Sort devices by location ID on the Mac.
Alexandre Julliard
julliard at winehq.org
Thu Jul 14 08:58:04 CDT 2016
Module: wine
Branch: master
Commit: b69b9a6ead7af50ebee4a63373414e5a4b0f16d9
URL: http://source.winehq.org/git/wine.git/?a=commit;h=b69b9a6ead7af50ebee4a63373414e5a4b0f16d9
Author: David Lawrie <david.dljunk at gmail.com>
Date: Mon Jul 11 04:06:04 2016 -0700
winejoystick.drv: Sort devices by location ID on the Mac.
Signed-off-by: David Lawrie <david.dljunk at gmail.com>
Signed-off-by: Ken Thomases <ken at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/winejoystick.drv/joystick_osx.c | 42 ++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 11 deletions(-)
diff --git a/dlls/winejoystick.drv/joystick_osx.c b/dlls/winejoystick.drv/joystick_osx.c
index bda9163..7e2e97f 100644
--- a/dlls/winejoystick.drv/joystick_osx.c
+++ b/dlls/winejoystick.drv/joystick_osx.c
@@ -314,6 +314,33 @@ static CFIndex find_top_level(IOHIDDeviceRef hid_device, CFMutableArrayRef main_
}
/**************************************************************************
+ * device_location_comparator
+ *
+ * Helper to sort device array by location ID since location IDs are consistent across boots & launches
+ */
+static CFComparisonResult device_location_comparator(const void *val1, const void *val2, void *context)
+{
+ IOHIDDeviceRef device1 = (IOHIDDeviceRef)val1, device2 = (IOHIDDeviceRef)val2;
+ long loc1 = get_device_location_ID(device1), loc2 = get_device_location_ID(device2);
+
+ if (loc1 < loc2)
+ return kCFCompareLessThan;
+ else if (loc1 > loc2)
+ return kCFCompareGreaterThan;
+ return kCFCompareEqualTo;
+}
+
+/**************************************************************************
+ * copy_set_to_array
+ *
+ * Helper to copy the CFSet to a CFArray
+ */
+static void copy_set_to_array(const void *value, void *context)
+{
+ CFArrayAppendValue(context, value);
+}
+
+/**************************************************************************
* find_osx_devices
*/
static int find_osx_devices(void)
@@ -358,20 +385,13 @@ static int find_osx_devices(void)
if (devset)
{
CFIndex num_devices, num_main_elements;
- const void** refs;
- CFArrayRef devices;
+ CFMutableArrayRef devices;
num_devices = CFSetGetCount(devset);
- refs = HeapAlloc(GetProcessHeap(), 0, num_devices * sizeof(*refs));
- if (!refs)
- {
- CFRelease(devset);
- goto fail;
- }
+ devices = CFArrayCreateMutable(kCFAllocatorDefault, num_devices, &kCFTypeArrayCallBacks);
+ CFSetApplyFunction(devset, copy_set_to_array, (void *)devices);
+ CFArraySortValues(devices, CFRangeMake(0, num_devices), device_location_comparator, NULL);
- CFSetGetValues(devset, refs);
- devices = CFArrayCreate(NULL, refs, num_devices, &kCFTypeArrayCallBacks);
- HeapFree(GetProcessHeap(), 0, refs);
CFRelease(devset);
if (!devices)
goto fail;
More information about the wine-cvs
mailing list