Linux: Add hint for disabling deadzones
authorKai Krakow
Tue, 21 Jul 2020 23:38:42 +0200
changeset 13984369fea168258
parent 13983 15a0bc9612e9
child 13985 42ad9fbf1f23
Linux: Add hint for disabling deadzones
include/SDL_hints.h
src/joystick/linux/SDL_sysjoystick.c
     1.1 --- a/include/SDL_hints.h	Mon Aug 10 08:42:35 2020 -0700
     1.2 +++ b/include/SDL_hints.h	Tue Jul 21 23:38:42 2020 +0200
     1.3 @@ -696,6 +696,18 @@
     1.4    */
     1.5  #define SDL_HINT_JOYSTICK_RAWINPUT "SDL_JOYSTICK_RAWINPUT"
     1.6  
     1.7 + /**
     1.8 +  *  \brief  A variable controlling whether Linux joysticks adhere their HID-defined deadzones or return unfiltered values.
     1.9 +  *      This is useful for Wine which implements its own deadzone handler if requested by games, also it enables xinput
    1.10 +  *      games to receive unfiltered values as required from the API.
    1.11 +  *
    1.12 +  *  This variable can be set to the following values:
    1.13 +  *    "0"       - Linux deadzones are not used by SDL
    1.14 +  *    "1"       - Linux deadzones are used by SDL (the default)
    1.15 +  *
    1.16 +  */
    1.17 +#define SDL_HINT_LINUX_JOYSTICK_DEADZONES "SDL_LINUX_JOYSTICK_DEADZONES"
    1.18 +
    1.19  /**
    1.20   *  \brief If set to "0" then never set the top most bit on a SDL Window, even if the video mode expects it.
    1.21   *      This is a debugging aid for developers and not expected to be used by end users. The default is "1"
     2.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Mon Aug 10 08:42:35 2020 -0700
     2.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Tue Jul 21 23:38:42 2020 +0200
     2.3 @@ -38,6 +38,7 @@
     2.4  #include <linux/joystick.h>
     2.5  
     2.6  #include "SDL_assert.h"
     2.7 +#include "SDL_hints.h"
     2.8  #include "SDL_joystick.h"
     2.9  #include "SDL_endian.h"
    2.10  #include "SDL_timer.h"
    2.11 @@ -706,6 +707,7 @@
    2.12              }
    2.13              if (test_bit(i, absbit)) {
    2.14                  struct input_absinfo absinfo;
    2.15 +                SDL_bool hint_used = SDL_GetHintBoolean(SDL_HINT_LINUX_JOYSTICK_DEADZONES, SDL_TRUE);
    2.16  
    2.17                  if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
    2.18                      continue;
    2.19 @@ -721,7 +723,7 @@
    2.20                  if (absinfo.minimum == absinfo.maximum) {
    2.21                      joystick->hwdata->abs_correct[i].used = 0;
    2.22                  } else {
    2.23 -                    joystick->hwdata->abs_correct[i].used = 1;
    2.24 +                    joystick->hwdata->abs_correct[i].used = hint_used;
    2.25                      joystick->hwdata->abs_correct[i].coef[0] =
    2.26                          (absinfo.maximum + absinfo.minimum) - 2 * absinfo.flat;
    2.27                      joystick->hwdata->abs_correct[i].coef[1] =