Add support for USB vendor/product IDs to Emscripten joysticks#14003
Merged
slouken merged 2 commits intolibsdl-org:mainfrom Sep 22, 2025
Merged
Add support for USB vendor/product IDs to Emscripten joysticks#14003slouken merged 2 commits intolibsdl-org:mainfrom
slouken merged 2 commits intolibsdl-org:mainfrom
Conversation
19 tasks
Collaborator
|
This looks good to me, @icculus? |
Collaborator
|
There's no guarantee these strings won't change tomorrow, but the layout is guaranteed regardless of the controller in use...so do we want this? |
Collaborator
Yes. It's very useful to know the vendor and product and have a real controller GUID. |
Contributor
Author
|
I found several small issues with the code, I should be able to fix them later today! |
Adds support for USB vendor/product IDs to Emscripten joystick backend.
slouken
reviewed
Sep 22, 2025
Collaborator
|
Merged, thanks! |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add support for USB vendor/product IDs to Emscripten joystick backend for browsers that provide this information (all major desktop browsers should support this, I haven't tested it yet on mobile browsers and desktop browsers other than Microsoft Edge).
This will also allow us to create custom gamepad mappings for different controllers on web in the future.
This patch has been tested with Godot Engine in this PR: godotengine/godot#109645
Here's a piece of code I used to print joystick information in Godot (where
Input.get_joy_info(i)containsvendor_idfield that usesSDL_GetJoystickVendorandproduct_idfield that usesSDL_GetJoystickProduct, both of them are in base 10, not hex):Here's the result on Windows for my DualShock 4 controller:
And here's the result in Microsoft Edge with the same controller and this patch applied:
(Here the name is not "Standard Gamepad" because in my Godot PR I changed the web gamepad mapping a little bit so we can see the controller names, this change can be ignored here)
I've also tested several other controllers (
usb gamepad (Vendor: 0810 Product: e501)and 8BitDo adapter with DualShock 4 in different modes:Xbox 360 Controller (XInput STANDARD GAMEPAD),Controller (Vendor: 054c Product: 0cda)(PlayStation Classic mode)) and I can confirm that the vendor/product IDs between Microsoft Edge and Windows Godot versions match (except for theXbox 360 Controller (XInput STANDARD GAMEPAD)).It also detects
xinput_indexthat usesSDL_GetJoystickPlayerIndexbehind the scenes, so I'm not sure why it reports 0 on web, but that's a different issue. 😅In this PR I decided to use JavaScript instead of C for detecting vendor and product IDs, because, for some reason,
gamepadEvent->idgets cut off at the end (you can see that by looking at the code results above, it's supposed to sayWireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 09cc), butc)at the end gets cut off) and JS has easy to use string manipulation methods.Relevant information links regarding
Gamepad.idhaving vendor/product IDs inside: https://stackoverflow.com/questions/66885705/how-to-get-vendor-and-productid-of-joystick-device-with-javascript , https://gist.github.com/Enichan/de1618d2c481523bd0c1123800bfe747 , https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_APIWould using Regex instead be a better solution or the current one should be good enough?
TODO:
Some buttons might be detected as axes (for analog triggers) or some buttons might be removed incorrectly (dpad gets detected as a hat) for non-standard controllers, but it probably should be fixed in a follow-up PRI just checked the code and it checks if a controller's mapping is standard to apply these featuresExisting Issue(s)
I haven't found any.