[PATCH] dinput: Assume a 1-to-1 axes map when no axes match

Bruno Jesus bjesus at codeweavers.com
Sun Apr 9 20:25:35 CDT 2017


The wiimote is a well known problematic device, mainly because it is not a joystick. It is a USB device. But the classic controller is at least advertised as a joystick with 6 axes and 11 buttons (js driver only, NO event). Unfortunately its axes start at 18 while Wine expects it to be < 8. There is no formal way to declare axes in the old API but at least this allows this specific case to work. This change should only affect the wii classic controller, it was tested on:

Wii classic controller - new path
Xbox 360 controller - correct path
Generic dpad + 8 button - correct path
PS2 controller on usb converter - correct path
SNES generic controller - correct path

Signed-off-by: Bruno Jesus <bjesus at codeweavers.com>
---
 dlls/dinput/joystick_linux.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 1f8f94d738..1032659621 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -228,19 +228,36 @@ static INT find_joystick_devices(void)
         else
             if ((joydev.dev_axes_map = HeapAlloc(GetProcessHeap(), 0, joydev.axis_count * sizeof(int))))
             {
-                INT j;
+                INT j, found_axes = 0;
 
                 /* Remap to DI numbers */
                 for (j = 0; j < joydev.axis_count; j++)
+                {
                     if (axes_map[j] < 8)
+                    {
                         /* Axis match 1-to-1 */
                         joydev.dev_axes_map[j] = j;
+                        found_axes++;
+                    }
                     else if (axes_map[j] == 16 ||
                              axes_map[j] == 17)
+                    {
                         /* POV axis */
                         joydev.dev_axes_map[j] = 8;
+                        found_axes++;
+                    }
                     else
                         joydev.dev_axes_map[j] = -1;
+                }
+
+                /* If no axes were configured but there are axes assume a 1-to-1 (wii controller) */
+                if (joydev.axis_count && !found_axes)
+                {
+                    ERR("Incoherent joystick data, advertised %d axes, detected 0. Assuming 1-to-1.\n",
+                         joydev.axis_count);
+                    for (j = 0; j < joydev.axis_count; j++)
+                        joydev.dev_axes_map[j] = j;
+                }
             }
 
         /* Find vendor_id and product_id in sysfs */
-- 
2.11.0




More information about the wine-patches mailing list