Aric Stewart : dinput: Map OS/ X joystick axes so even if they come out of order on the device we recognize them correctly .

Alexandre Julliard julliard at winehq.org
Wed Mar 11 10:04:37 CDT 2009


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

Author: Aric Stewart <aric at codeweavers.com>
Date:   Tue Mar 10 14:59:56 2009 -0500

dinput: Map OS/X joystick axes so even if they come out of order on the device we recognize them correctly.

---

 dlls/dinput/joystick_osx.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c
index e0213b6..4faf621 100644
--- a/dlls/dinput/joystick_osx.c
+++ b/dlls/dinput/joystick_osx.c
@@ -284,7 +284,7 @@ static int get_osx_device_name(int id, char *name, int length)
     return 0;
 }
 
-static void get_osx_device_elements(JoystickImpl *device)
+static void get_osx_device_elements(JoystickImpl *device, int axis_map[8])
 {
     IOHIDDeviceRef  tIOHIDDeviceRef;
     CFArrayRef      gElementCFArrayRef;
@@ -351,6 +351,7 @@ static void get_osx_device_elements(JoystickImpl *device)
                         case kHIDUsage_GD_Rz:
                         {
                             CFArrayInsertValueAtIndex(device->elementCFArrayRef, axes, tIOHIDElementRef);
+                            axis_map[axes]=usage;
                             axes++;
                             break;
                         }
@@ -583,6 +584,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
     HRESULT hr;
     LPDIDATAFORMAT df = NULL;
     int idx = 0;
+    int axis_map[8]; /* max axes */
 
     TRACE("%s %p %p %p %hu\n", debugstr_guid(rguid), jvt, dinput, pdev, index);
 
@@ -606,7 +608,8 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
     newDevice->generic.name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1);
     strcpy(newDevice->generic.name, name);
 
-    get_osx_device_elements(newDevice);
+    memset(axis_map, 0, sizeof(axis_map));
+    get_osx_device_elements(newDevice, axis_map);
 
     TRACE("%i axes %i buttons %i povs\n",newDevice->generic.devcaps.dwAxes,newDevice->generic.devcaps.dwButtons,newDevice->generic.devcaps.dwPOVs);
 
@@ -632,8 +635,20 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
 
     for (i = 0; i < newDevice->generic.devcaps.dwAxes; i++)
     {
-        memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i], df->dwObjSize);
-        df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_ABSAXIS;
+        int wine_obj = -1;
+        switch (axis_map[i])
+        {
+            case kHIDUsage_GD_X: wine_obj = 0; break;
+            case kHIDUsage_GD_Y: wine_obj = 1; break;
+            case kHIDUsage_GD_Z: wine_obj = 2; break;
+            case kHIDUsage_GD_Rx: wine_obj = 3; break;
+            case kHIDUsage_GD_Ry: wine_obj = 4; break;
+            case kHIDUsage_GD_Rz: wine_obj = 5; break;
+        }
+        if (wine_obj < 0 ) continue;
+
+        memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
+        df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
     }
 
     for (i = 0; i < newDevice->generic.devcaps.dwPOVs; i++)




More information about the wine-cvs mailing list