We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5161 - [PATCH] Autodetect controller mappings based on the Linux Gamepad Specification
Summary: [PATCH] Autodetect controller mappings based on the Linux Gamepad Specification
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: HG 2.1
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-26 20:18 UTC by Jan Bujak
Modified: 2020-05-29 20:38 UTC (History)
0 users

See Also:


Attachments
Patch v1 (24.30 KB, patch)
2020-05-26 20:18 UTC, Jan Bujak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Bujak 2020-05-26 20:18:52 UTC
Created attachment 4358 [details]
Patch v1

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.

Obviously please let me know if you'd like me to fix something in my patch or do something differently.
Comment 1 Sam Lantinga 2020-05-29 20:38:22 UTC
This is a great idea. I've applied your patch and I'll use this for the other default mappings as well:
https://hg.libsdl.org/SDL/rev/75c33f89d791