-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linux: Improve gamepad mapping heuristic to accept Android conventions #7797
Conversation
The bitfield `mapped` has two different sets of meanings, depending whether we're setting up the triggers or the d-pad. Represent them as symbolic constants rather than opaque integers. Signed-off-by: Simon McVittie <[email protected]>
This heuristic for gamepads without a more specific mapping already tried two incompatible conventions for handling triggers: the Linux Gamepad Specification uses hat switch 2 for the triggers (for whatever reason), but the de facto standard set by the drivers for older Xbox and Playstation controllers represents each trigger as the Z-axis of the nearest analog stick. Android documentation encourages Bluetooth gamepad manufacturers to use a third incompatible convention where the left and right triggers are represented as the brake and gas pedals of a driving simulator controller. The Android convention also changes the representation of the right stick: instead of using X and Y rotation as a second pair of axes, Android uses Z position as a second horizontal axis, and Z rotation as a second vertical axis. Try to cope gracefully with all of these. This will hopefully resolve the issue described in libsdl-org#5406 (when using unpatched kernels). Signed-off-by: Simon McVittie <[email protected]>
@jelly, please could you try reverting your local SDL changes and using an unpatched kernel, then applying this? If you also apply --- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -80,7 +80,7 @@
#define DEBUG_INPUT_EVENTS 1
#endif
-#if 0
+#if 1
#define DEBUG_GAMEPAD_MAPPING 1
#endif then |
I can at least confirm that if I comment out all the entries in I don't think I have any hardware that follows one of the other two conventions for how triggers and the right stick are represented. #7791 suggests that the 8BitDo SNES30 via Bluetooth would be another suitable test device for the Android convention. |
This looks good to me, FYI. |
The only downside to this approach is that we might start interpreting wheels as gamepads and break them in racing games under Proton. Since there are many more gamepads than wheels, I think this could be okay, we just have to make sure that the controller isn't a known wheel or other type of controller before trying to apply an automatic gamepad mapping. |
I believe this should be reasonably regression-proof, because the code I've changed in this PR doesn't alter whether a device is considered to be a gamepad or whether we return a mapping: it only alters the level of completeness of the mapping it gets. We early-return if Steering wheels designed for games consoles already identify as an oddly-shaped gamepad (the same behaviour as Guitar Hero controllers and other games console accessories), for example (I don't have any of these devices myself, so the only way I can help you to identify them is by curating other people's sample data.) The only way I can see that this change could cause a regression is that if we have both If gamepads exist that have If you're worried about such devices maybe existing, we could tighten the conditions, for example only using If we refactor this heuristic so it can act on mock data rather than literally having to open a joystick device (like the way I tested |
For Proton specifically, Proton specifically excludes anything that SDL identifies as a |
Yeah, good point about I like the idea of refactoring it to work on test data. It would be interesting to see the mappings that are generated for the existing set of device data. |
I've marked this as not a draft, but I'd really appreciate some testing from @jelly, since this is a fix for hardware that I don't have. |
I was able to test and confirm this patch fixes the issue in #5406 Thanks! |
Please review and test carefully: I do not have the affected hardware, so I am unable to test this.
Description
linux: Reduce magic numbers when mapping gamepad axes
The bitfield
mapped
has two different sets of meanings, dependingwhether we're setting up the triggers or the d-pad. Represent them
as symbolic constants rather than opaque integers.
linux: Improve gamepad mapping heuristic to accept Android conventions
This heuristic for gamepads without a more specific mapping already
tried two incompatible conventions for handling triggers: the Linux
Gamepad Specification uses hat switch 2 for the triggers (for whatever
reason), but the de facto standard set by the drivers for older Xbox
and Playstation controllers represents each trigger as the Z-axis of
the nearest analog stick.
Android documentation encourages Bluetooth gamepad manufacturers to use
a third incompatible convention where the left and right triggers are
represented as the brake and gas pedals of a driving simulator
controller. The Android convention also changes the representation of
the right stick: instead of using X and Y rotation as a second pair
of axes, Android uses Z position as a second horizontal axis, and
Z rotation as a second vertical axis.
Try to cope gracefully with all of these. This will hopefully resolve
the issue described in Add Xbox Series X controller bluetooth profile #5406 (when using unpatched kernels).
Existing Issue(s)
There is no clear issue report as far as I know, but #5406 is trying to solve the same issue differently.