Skip to content

Commit

Permalink
Linux: Add hint for disabling deadzones
Browse files Browse the repository at this point in the history
  • Loading branch information
kakra committed Jul 21, 2020
1 parent 86517d3 commit c3ecf18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions include/SDL_hints.h
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/joystick/linux/SDL_sysjoystick.c
Expand Up @@ -38,6 +38,7 @@
#include <linux/joystick.h>

#include "SDL_assert.h"
#include "SDL_hints.h"
#include "SDL_joystick.h"
#include "SDL_endian.h"
#include "SDL_timer.h"
Expand Down Expand Up @@ -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;
Expand All @@ -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] =
Expand Down

0 comments on commit c3ecf18

Please sign in to comment.