Add support for SDL-compatible joypad GUID and Input.get_joy_info() on Android#114338
Add support for SDL-compatible joypad GUID and Input.get_joy_info() on Android#114338Nintorch wants to merge 1 commit intogodotengine:masterfrom
Input.get_joy_info() on Android#114338Conversation
platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
de7dcb7 to
07288ea
Compare
platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
m4gr3d
left a comment
There was a problem hiding this comment.
Alongside manual testing, can you add unit tests to validate the added logic.
|
Thank you for your review, m4gr3d! I will be able to fix the code later today! |
07288ea to
d7bbdc3
Compare
60d7a23 to
c258401
Compare
platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
c258401 to
0200b51
Compare
| // Generate GUID for compatibility with SDL controller mappings. | ||
| void generate_joy_guid(char *p_buf, int p_buf_len, int p_vendor_id, int p_product_id, int p_button_mask, int p_axis_mask) { | ||
| if (p_vendor_id != 0 || p_product_id != 0) { | ||
| snprintf(p_buf, p_buf_len, "05000000%04x0000%04x0000%04x%04x", BSWAP16(p_vendor_id), BSWAP16(p_product_id), BSWAP16(p_button_mask), BSWAP16(p_axis_mask)); |
There was a problem hiding this comment.
Summary, Regressions Xbox Series Controller :
- XBox Button is not recognized
- The back button is not recognized
- The Share button is displayed as a back button in the official demo.
The RL and LT buttons are swapped; this was incorrect before, either due to incorrect testing and configuration on my part or caused by other changes. (Probably the first; I pressed both buttons simultaneously during testing, and didn't notice that they were swapped.)
Tests, Rc2 and this PR
Godot Engine v4.6.rc2.official.78c6632eb
Found joypad #0: Xbox Series X Controller - 58626f7820576972656c65737320436f
godot/core/input/gamecontrollerdb.txt
Line 2112 in 89cea14
I overwrote it some time ago with this configuration (godotcontrollerdb.txt):
This PR: Godot Engine v4.6.rc.gh-114338.5db637116
Found joypad #0: Xbox Series Controller - 050000005e040000130b0000ffff3f00
i see also now:
print(Input.get_joy_info(joypad))
{ "raw_name": "Xbox Wireless Controller 4416", "vendor_id": "1118", "product_id": "2835" }
godot/core/input/gamecontrollerdb.txt
Line 2122 in 89cea14
This PR adds support for SDL-compatible joypad GUIDs on Android, so now we should be able to use SDL controller mapping database for Android controllers.
I wasn't aware that the GUIDs were incompatible, but in this official (?) SDL file I also see many GUIDs that don't start with 05000000. Will there be more regressions if they are no longer found as before?
Godot configuration: Should we clean it up now?
Perhaps we should clean up the Godot configuration here now. Back then, I copied more GUIDs from the SDL configuration and adjusted them to match my controller. I asked several people in the community, and they all had the same GUIDs as me. According to the Git-Blame, Default Android Gamepad was added six years ago. It was last updated two months ago, but I'm not sure what effect this pull request has on this controller.
https://github.com/godotengine/godot/blob/master/core/input/godotcontrollerdb.txt#L7-L20
# Android
Default Android Gamepad,Default Controller,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a4,x:b2,dpup:h0.1,back:b4,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a5,b:b1,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,platform:Android,
58626f7820576972656c65737320436f,Xbox Series X Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
050000005e04000091020000ff073f00,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
050000005e04000091020000ff073f80,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
050000005e040000e00200000ffe3f00,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
050000005e040000e00200000ffe3f80,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
050000005e040000e0020000ffff3f00,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
050000005e040000e0020000ffff3f80,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
050000005e040000fd020000ffff3f00,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
33356661323266333733373865656366,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
34356136633366613530316338376136,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
35623965373264386238353433656138,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
36616131643361333337396261666433,Xbox One Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:+a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:+a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
There was a problem hiding this comment.
I wasn't aware that the GUIDs were incompatible, but in this official (?) SDL file I also see many GUIDs that don't start with
05000000
The GUIDs were indeed incompatible with the ones that start with 0500. I'm not entirely sure how we can check for more regressions other than just testing each controller :(
We can also modify the GUIDs in godotcontrollerdb.txt to match the new ones, if that's okay!
But, for example, this change makes my DualShock 4 behave better on Android, it gets a proper name ("PS4 Controller") and now when I press the left trigger Godot doesn't register it as also pressing the Back key (I need to retest it though, but I remember it surely fixed that problem)
About the Xbox controller regression, maybe that's an actual problem with the mappings that has to be reported in the mappings db repository? I see that the previous mapping that you overwrote and the one that is currently used are the same. I also have an old PR that "actually" integrated SDL so we can check if that's not entirely a Godot problem. I can share a link to it soon.
There was a problem hiding this comment.
Here's the link to the PR I mentioned: #109645
There was a problem hiding this comment.
I found something interesting: in SDL's internal gamepad mapping database there's a mapping for your exact GUID and the mapping itself is identical to the one you made in godotcontrollerdb.txt!
https://github.com/libsdl-org/SDL/blob/58c30a4451b715b7260c8a9b6dac846a3ef28cfb/src/joystick/SDL_gamepad_db.h#L821C6-L821C38
"050000005e040000130b0000ffff3f00,Xbox Series X Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
Maybe I should make the code use this mapping database in this PR
There was a problem hiding this comment.
Yes, maybe. Unfortunately, I don't know the reasons why this external file from the SDL_GameControllerDB project is used; it seems to be incorrectly configured for my Xbox controller on Android. CC @akien-mga
How much effort would it take to eliminate the dependency?
Lines 8 to 18 in 63227bb
https://github.com/mdqinc/SDL_GameControllerDB/blob/master/gamecontrollerdb.txt
050000005e040000130b0000ffff3f00,Xbox Series Controller,a:b0,b:b1,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
--> back:b15 and without b4. This is the reason for this behavior.

We last synchronized the gamecontrollerdb.txt file 7 months ago; it would still be incorrect for my controller if we did it again today. This might be different for other controllers, though. I think the Windows configuration is much more important for gamers.
There was a problem hiding this comment.
Notice:
https://github.com/libsdl-org/SDL/blob/58c30a4451b715b7260c8a9b6dac846a3ef28cfb/src/joystick/SDL_gamepad_db.h#L821C6-L821C38
"050000005e040000130b0000ffff3f00,Xbox Series X Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
Maybe I should make the code use this mapping database in this PR
misc1:b15 is not configured there (share button).
I believe Xbox One controllers are without this button and the Series X have a share button.
Xbox One
There was a problem hiding this comment.
I can make a PR for SDL to include misc1 :D
There was a problem hiding this comment.
If 050000005e040000130b0000ffff3f00 is present in both internal SDL and SDL_GameControllerDB, then it might be a bug that it's in SDL_GameControllerDB and it should likely be removed.
It seems like it was added in SDL_GameControllerDB in 2020 with mdqinc/SDL_GameControllerDB@d1f0e1e, and later to SDL itself in 2021 with libsdl-org/SDL@afd100f.
They're not too keen on receiving PRs from Godot contributors (understandably, as for several years we had our own non-SDL implementation and misunderstood the scope of that repo, and sent custom mappings that Godot needed but SDL itself didn't need). But I'll open an issue about it as I believe it's not a Godot specific issue, just one we happened to discover.
Edit: Done: mdqinc/SDL_GameControllerDB#913.
For Godot, we can override the invalid gamecontrollerdb.txt mapping with the latest SDL one in godotcontrollerdb.txt, until we switch to proper SDL on Android too, in which case the solution can be to instead remove the mapping from both gamecontrollerdb.txt and godotcontrollerdb.txt.
There was a problem hiding this comment.
I can make a PR for SDL to include misc1 :D
Done! libsdl-org/SDL#14921
There was a problem hiding this comment.
Now this PR reads the internal SDL Android mappings database and fixes the regression for Xbox Series X's Share button
| "uinput-atrus", | ||
| }; | ||
|
|
||
| private static final int[] JOYPAD_BUTTON_MASK_KEYS = new int[] { |
There was a problem hiding this comment.
Note: This was my PR 8 months ago to fix some issues with the buttons.
case KeyEvent.KEYCODE_BUTTON_MODE: // Home/Xbox Button on Xbox controllers
button = 5;
break;
case KeyEvent.KEYCODE_MEDIA_RECORD: // Share Button on Xbox controllers
button = 15;
break;and additionally: back:b4,misc1:b15 (file: godotcontrollerdb.txt),
to fix the issues I listed above --> #114338 (comment)
f2de833 to
39bc943
Compare
39bc943 to
dadf887
Compare
|
I'll probably have time again on Monday when an Xbox controller needs to be tested on Android. https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_MEDIA_RECORD I don't see |
|
I think adding a new key in |
e83ff26 to
1313dfe
Compare
There was a problem hiding this comment.
All keys are recognized, but LT and RT are swapped.
Godot Engine v4.7.dev.gh-114338.b25248d22 (2026-02-06 11:08:17 UTC) - https://godotengine.org
OpenGL API OpenGL ES 3.2 V@0502.0 (GIT@193b2ee, I593c16c433, 1633593732) (Date:10/07/21) - Compatibility - Using Device: Qualcomm - Adreno (TM) 650
+ Found newly connected joypad #0: Xbox Series X Controller - 050000005e040000130b0000ffff3f00
{ "raw_name": "Xbox Wireless Controller 4416", "vendor_id": "1118", "product_id": "2835" }
I think this is coming from the header file, but when I tested your SDL-PR a few days ago using the Android SDL test app, everything was OK, so it seems it's not compatible with Godot.
"050000005e040000130b0000ffff3f00,Xbox Series X Controller,a:b0,b:b1,back:b4,misc1:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
And I think we need to change the order; godotcontrollerdb.txt needs to be at the very bottom, right? So that we can override it properly.
controller_databases = [
"gamecontrollerdb.txt",
"godotcontrollerdb.txt",
"../../thirdparty/sdl/joystick/SDL_gamepad_db.h",
]|
Thank you for your review! I will see what I can do to fix this issue later when I can! |
|
That does sound like a good solution that doesn't introduce any more regressions (besides, well, what this PR does for controller mappings that don't start with |
|
I just noticed that the triggers for the older GUID for your controller are mapped with I will see what I can do. |
In my PR I used this to solve a different problem; that shouldn't be necessary anymore. Issue #99191 (lefttrigger:+a4,righttrigger:+a5)
|
|
But that's still strange that the trigger mapping hasn't changed between the previous used mapping and the current one aside of the +, but now they're swapped 😅 |
|
Ohh I see, thank you for testing! :D EDIT: The triggers are not swapped on my controller, but they are mapped to [-1;1], this will also need to be fixed without breaking my Dualshock 4 triggers |
|
So I found some differences between how Godot handles Android joypad axes and how SDL handles them. List<InputDevice.MotionRange> ranges = joystickDevice.getMotionRanges();
Collections.sort(ranges, new RangeComparator());
for (InputDevice.MotionRange range : ranges) {
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
if (range.getAxis() == MotionEvent.AXIS_HAT_X || range.getAxis() == MotionEvent.AXIS_HAT_Y) {
joystick.hats.add(range);
} else {
joystick.axes.add(range);
}
}
}Currently in master my Xbox triggers are mapped to [-1;1]. If I remove the duplicate checking functionality, they work just fine (Dualshock 4 triggers too). This functionality was added in #45771 to fix #45712 , but to me the original issue looks more like a mapping issue that needs to be checked in SDL testcontroller too, just in case. It also provides a way to setup a mapping for the device, maybe that would be helpful too! Or if it doesn't help, we can leave the duplicate checking functionality only for Nvidia Shield controller. I'm gonna add a commit to remove the duplicate checking functionality here. May I ask if you can test your controller with that commit too, please? And I also just checked and #56181 was reported only after #45771 was merged. It may be a coincidence, or may be not :D |
a386f60 to
83fa59a
Compare
a211339 to
fb27976
Compare
This PR adds support for SDL-compatible joypad GUIDs on Android, so now we should be able to use SDL controller mapping database for Android controllers. This PR adds support for Input.get_joy_info() for Android as well.
fb27976 to
3bdd5b3
Compare
|
I came up with a way to keep the joypad mapping system backwards-compatible with the old GUID format, see the changes in |




Related to #56181 (if this PR doesn't fix this issue, then we need to create a mapping for Xbox controllers ourselves)
This PR adds support for SDL-compatible joypad GUIDs on Android, so now we should be able to use the mappings from SDL controller mapping database for Android controllers that start with
0500, while still keeping the compatibility with mappings that use the older GUID format (if a mapping with the new format can't be found, the code tries to find one with the old format).This PR adds support for
Input.get_joy_info()for Android as well.See also SDL's
Android_AddJoystick, SDL'sSDLControllerManager, and the way GUID was constructed in Godot's Linux joypad driver prior to the SDL3 joystick driver PR here.DualShock 4 GUID before this PR
(Ignore that there's no fingerprint sensor here, it's a screenshot with a different PR applied)

DualShock 4 GUID after this PR + Input.get_joy_info()
TODO: