From c3ecf18cc43881cd4060f3af6f1903b28cc284b7 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 21 Jul 2020 23:38:42 +0200 Subject: [PATCH] Linux: Add hint for disabling deadzones --- include/SDL_hints.h | 12 ++++++++++++ src/joystick/linux/SDL_sysjoystick.c | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index fd55a55d2..44db3c5e4 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -696,6 +696,18 @@ extern "C" { */ #define SDL_HINT_JOYSTICK_RAWINPUT "SDL_JOYSTICK_RAWINPUT" + /** + * \brief A variable controlling whether Linux joysticks adhere their HID-defined deadzones or return unfiltered values. + * This is useful for Wine which implements its own deadzone handler if requested by games, also it enables xinput + * games to receive unfiltered values as required from the API. + * + * This variable can be set to the following values: + * "0" - Linux deadzones are not used by SDL + * "1" - Linux deadzones are used by SDL (the default) + * + */ +#define SDL_HINT_LINUX_JOYSTICK_DEADZONES "SDL_LINUX_JOYSTICK_DEADZONES" + /** * \brief If set to "0" then never set the top most bit on a SDL Window, even if the video mode expects it. * This is a debugging aid for developers and not expected to be used by end users. The default is "1" diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 58471d4e8..b5fa7901f 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -38,6 +38,7 @@ #include #include "SDL_assert.h" +#include "SDL_hints.h" #include "SDL_joystick.h" #include "SDL_endian.h" #include "SDL_timer.h" @@ -706,6 +707,7 @@ ConfigJoystick(SDL_Joystick * joystick, int fd) } if (test_bit(i, absbit)) { struct input_absinfo absinfo; + SDL_bool hint_used = SDL_GetHintBoolean(SDL_HINT_LINUX_JOYSTICK_DEADZONES, SDL_TRUE); if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) { continue; @@ -721,7 +723,7 @@ ConfigJoystick(SDL_Joystick * joystick, int fd) if (absinfo.minimum == absinfo.maximum) { joystick->hwdata->abs_correct[i].used = 0; } else { - joystick->hwdata->abs_correct[i].used = 1; + joystick->hwdata->abs_correct[i].used = hint_used; joystick->hwdata->abs_correct[i].coef[0] = (absinfo.maximum + absinfo.minimum) - 2 * absinfo.flat; joystick->hwdata->abs_correct[i].coef[1] =