Aric Stewart : dinput: OS/X joystick: Sort buttons based on usage as some controllers report the buttons out of order .

Alexandre Julliard julliard at winehq.org
Fri Mar 13 09:14:00 CDT 2009


Module: wine
Branch: master
Commit: 79859cb3ac62e6bc3866187605fcd1da19f8177f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=79859cb3ac62e6bc3866187605fcd1da19f8177f

Author: Aric Stewart <aric at codeweavers.com>
Date:   Thu Mar 12 08:03:04 2009 -0500

dinput: OS/X joystick: Sort buttons based on usage as some controllers report the buttons out of order.

Makes the xbox 360 controller button mapping more logical.

---

 dlls/dinput/joystick_osx.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c
index 21f8ca3..d5a5f17 100644
--- a/dlls/dinput/joystick_osx.c
+++ b/dlls/dinput/joystick_osx.c
@@ -284,6 +284,27 @@ static int get_osx_device_name(int id, char *name, int length)
     return 0;
 }
 
+static void insert_sort_button(int header, IOHIDElementRef tIOHIDElementRef,
+                                CFMutableArrayRef elementCFArrayRef, int index,
+                                int target)
+{
+    IOHIDElementRef targetElement;
+    int usage;
+
+    CFArraySetValueAtIndex(elementCFArrayRef, header+index, NULL);
+    targetElement = ( IOHIDElementRef ) CFArrayGetValueAtIndex( elementCFArrayRef, header+target);
+    if (targetElement == NULL)
+    {
+        CFArraySetValueAtIndex(elementCFArrayRef, header+target,tIOHIDElementRef);
+        return;
+    }
+    usage = IOHIDElementGetUsage( targetElement );
+    usage --; /* usage 1 based index */
+
+    insert_sort_button(header, targetElement, elementCFArrayRef, target, usage);
+    CFArraySetValueAtIndex(elementCFArrayRef, header+target,tIOHIDElementRef);
+}
+
 static void get_osx_device_elements(JoystickImpl *device, int axis_map[8])
 {
     IOHIDDeviceRef  tIOHIDDeviceRef;
@@ -382,6 +403,18 @@ static void get_osx_device_elements(JoystickImpl *device, int axis_map[8])
     device->generic.devcaps.dwAxes = axes;
     device->generic.devcaps.dwButtons = buttons;
     device->generic.devcaps.dwPOVs = povs;
+
+    /* Sort buttons into correct order */
+    for (buttons = 0; buttons < device->generic.devcaps.dwButtons; buttons++)
+    {
+        IOHIDElementRef tIOHIDElementRef = ( IOHIDElementRef ) CFArrayGetValueAtIndex( device->elementCFArrayRef, axes+povs+buttons);
+        uint32_t usage = IOHIDElementGetUsage( tIOHIDElementRef );
+        usage --; /* usage is 1 indexed we need 0 indexed */
+        if (usage == buttons)
+            continue;
+
+        insert_sort_button(axes+povs, tIOHIDElementRef, device->elementCFArrayRef,buttons,usage);
+    }
 }
 
 static void get_osx_device_elements_props(JoystickImpl *device)




More information about the wine-cvs mailing list