wine-staging/patches/dinput-remap-joystick/0001-dinput-Allow-remapping-of-joystick-buttons.patch

138 lines
5.3 KiB
Diff
Raw Normal View History

From 2c404d618908f4655623611ce720b6b27d0c1de6 Mon Sep 17 00:00:00 2001
2019-02-27 13:44:06 -08:00
From: Andrew Church <achurch@achurch.org>
Date: Mon, 25 Feb 2019 11:21:03 +1100
Subject: [PATCH] dinput: Allow remapping of joystick buttons
Changed
- Change the array to store the origial button.
- Remove lookup loops.
- Changed max Buttons to 128 to match DIJOYSTATE2 structure.
2019-02-27 13:44:06 -08:00
Wine-bug: https://bugs.winehq.org/show_bug.cgi?id=35815
---
dlls/dinput/joystick.c | 29 +++++++++++++++++++++++++++++
dlls/dinput/joystick_linux.c | 7 +++++--
dlls/dinput/joystick_linuxinput.c | 2 ++
dlls/dinput/joystick_osx.c | 2 ++
dlls/dinput/joystick_private.h | 4 ++++
5 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c
index 2354ff3b822..36086f0035f 100644
2019-02-27 13:44:06 -08:00
--- a/dlls/dinput/joystick.c
+++ b/dlls/dinput/joystick.c
@@ -1034,6 +1034,7 @@ HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_
2019-02-27 13:44:06 -08:00
int tokens = 0;
int axis = 0;
int pov = 0;
+ int button;
get_app_key(&hkey, &appkey);
@@ -1045,6 +1046,34 @@ HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_
2019-02-27 13:44:06 -08:00
TRACE("setting default deadzone to: \"%s\" %d\n", buffer, This->deadzone);
}
+ for (button = 0; button < MAX_MAP_BUTTONS; button++)
+ This->button_map[button] = button;
+
+ if (!get_config_key(hkey, appkey, "ButtonMap", buffer, sizeof(buffer)))
+ {
+ static const char *delim = ",";
+ int button = 0;
+ char *token;
+
+ TRACE("ButtonMap = \"%s\"\n", buffer);
+ for (token = strtok(buffer, delim);
+ token != NULL && button < MAX_MAP_BUTTONS;
+ token = strtok(NULL, delim), button++)
+ {
+ char *s;
+ int value = strtol(token, &s, 10);
+ if (value < 0 || *s != '\0')
+ {
+ ERR("invalid button number: \"%s\"", token);
+ }
+ else
+ {
+ TRACE("mapping physical button %d to DInput button %d", value, button);
+ This->button_map[value] = button;
+ }
+ }
+ }
+
This->axis_map = HeapAlloc(GetProcessHeap(), 0, This->device_axis_count * sizeof(int));
if (!This->axis_map) return DIERR_OUTOFMEMORY;
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index ec4cb94c034..7dc9deff8c4 100644
2019-02-27 13:44:06 -08:00
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -856,10 +856,13 @@ static void joy_polldev( IDirectInputDevice8W *iface )
2019-02-27 13:44:06 -08:00
jse.type,jse.number,jse.value);
if (jse.type & JS_EVENT_BUTTON)
{
+ int button;
if (jse.number >= This->generic.devcaps.dwButtons) return;
- inst_id = DIDFT_MAKEINSTANCE(jse.number) | DIDFT_PSHBUTTON;
- This->generic.js.rgbButtons[jse.number] = value = jse.value ? 0x80 : 0x00;
+ button = This->generic.button_map[jse.number];
+
+ inst_id = DIDFT_MAKEINSTANCE(button) | DIDFT_PSHBUTTON;
+ This->generic.js.rgbButtons[button] = value = jse.value ? 0x80 : 0x00;
}
else if (jse.type & JS_EVENT_AXIS)
{
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index ef7b160ba58..7830cce3ced 100644
2019-02-27 13:44:06 -08:00
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -908,6 +908,8 @@ static void joy_polldev( IDirectInputDevice8W *iface )
2019-02-27 13:44:06 -08:00
if (btn & 0x80)
{
btn &= 0x7F;
+ btn = This->generic.button_map[btn];
+
inst_id = DIDFT_MAKEINSTANCE(btn) | DIDFT_PSHBUTTON;
This->generic.js.rgbButtons[btn] = value = ie.value ? 0x80 : 0x00;
}
diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c
index 174a78b7fd4..60e3967d921 100644
2019-02-27 13:44:06 -08:00
--- a/dlls/dinput/joystick_osx.c
+++ b/dlls/dinput/joystick_osx.c
@@ -844,6 +844,8 @@ static void poll_osx_device_state( IDirectInputDevice8W *iface )
2019-02-27 13:44:06 -08:00
TRACE("valueRef %s val %d oldVal %d newVal %d\n", debugstr_cf(valueRef), val, oldVal, newVal);
if (oldVal != newVal)
{
+ button_idx = device->generic.button_map[button_idx];
+
inst_id = DIDFT_MAKEINSTANCE(button_idx) | DIDFT_PSHBUTTON;
queue_event(iface,inst_id,newVal,GetCurrentTime(),device->generic.base.dinput->evsequence++);
}
diff --git a/dlls/dinput/joystick_private.h b/dlls/dinput/joystick_private.h
index 0f191787158..606475759ef 100644
2019-02-27 13:44:06 -08:00
--- a/dlls/dinput/joystick_private.h
+++ b/dlls/dinput/joystick_private.h
@@ -33,6 +33,9 @@
#define MAX_PROPS 164
struct JoystickGenericImpl;
+/* Number of buttons for which to allow remapping */
+#define MAX_MAP_BUTTONS 128
2019-02-27 13:44:06 -08:00
+
typedef void joy_polldev_handler( IDirectInputDevice8W *iface );
2019-02-27 13:44:06 -08:00
typedef struct JoystickGenericImpl
@@ -47,6 +50,7 @@ typedef struct JoystickGenericImpl
char *name;
int device_axis_count; /* Total number of axes in the device */
int *axis_map; /* User axes remapping */
+ int button_map[MAX_MAP_BUTTONS]; /* User button remapping */
LONG deadzone; /* Default dead-zone */
joy_polldev_handler *joy_polldev;
--
2.30.2
2019-02-27 13:44:06 -08:00