Skip to content
Permalink
Browse files

Fixed bug 5161 - Autodetect controller mappings based on the Linux Ga…

…mepad Specification

Jan Bujak

I wrote a new driver for my gamepad on Linux. I'd like SDL to support it out-of-box, as currently it just treats it as a generic joystick instead of a gamepad. From what I can see the only way to do that is to either 1) pick one of the already supported controllers' PID, VID and button layouts and have my driver send that (effectively lying that it's something else), or 2) submit a preconfigured, hardcoded mapping to SDL.

Both of those, in my opinion, are silly when we already have the Linux Gamepad Specification which standarizes this:

https://www.kernel.org/doc/html/v4.15/input/gamepad.html

Unfortunately SDL doesn't make use of it currently. So I've took it upon myself to add it; patch is in the attachments.

Basically what the patch does is that if SDL finds no built-it controller mappings for a given joystick it then asks the joystick backend to autodetect it, and that uses the relevant evdev bits to figure out which button/axis is which. (See the specs for more details.)

With this patch applied my own driver for my controller works out-of-box with SDL with no extra configuration and is correctly recognized as a gamepad; this is also going to be the case for any other driver which follows the Linux Gamepad Specification.
  • Loading branch information
slouken committed May 29, 2020
1 parent e2dbed9 commit 345b4d7e14a7ac1249bb39fcde71a592f4c66648

File 18 of 18 in 345b4d7

@@ -555,6 +555,12 @@ WINDOWS_JoystickQuit(void)
s_bDeviceRemoved = SDL_FALSE;
}

static SDL_bool
WINDOWS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
{
return SDL_FALSE;
}

SDL_JoystickDriver SDL_WINDOWS_JoystickDriver =
{
WINDOWS_JoystickInit,
@@ -570,6 +576,7 @@ SDL_JoystickDriver SDL_WINDOWS_JoystickDriver =
WINDOWS_JoystickUpdate,
WINDOWS_JoystickClose,
WINDOWS_JoystickQuit,
WINDOWS_JoystickGetGamepadMapping
};

#endif /* SDL_JOYSTICK_DINPUT || SDL_JOYSTICK_XINPUT */

0 comments on commit 345b4d7

Please sign in to comment.