Skip to content

Add flexible Emscripten joystick mapping#15823

Open
Nintorch wants to merge 1 commit into
libsdl-org:mainfrom
Nintorch:add-flexible-web-mapping
Open

Add flexible Emscripten joystick mapping#15823
Nintorch wants to merge 1 commit into
libsdl-org:mainfrom
Nintorch:add-flexible-web-mapping

Conversation

@Nintorch

@Nintorch Nintorch commented Jun 13, 2026

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Description

This PR adds a new flexible gamepad mapping by using the JoystickGetGamepadMapping function.
By "flexible" here I mean that the mapping automatically adapts to the controller's button count, by providing additional misc SDL buttons for non-standard buttons if necessary. This allows the mapping to recognize the PS4/PS5 touchpad button and, for example, JoyCon pair SL/SR buttons.
This code doesn't check if the controller has a standard button mapping from the browser to preserve the previous behavior.

This PR also documents the rules for gamepad mappings for the Emscripten backend that I propose (they can be changed if necessary):

  • If the controller has a standard mapping (the second to last digit of the GUID is 0x8), then it shouldn't have a custom SDL mapping. If you believe the standard mapping provided by the browser is incorrect, please file a bug report to the browser.
  • If the controller doesn't have a standard mapping (the second to last digit of the GUID is 0x0), then the same rules as on other platforms apply. (For example, the controller shouldn't be a "generic" controller, it's name string shouldn't contain something similar to "usb gamepad")

This PR was tested in Chromium (Microsoft Edge) and Firefox, everything seems to work as expected (the only problem is that Firefox doesn't recognize JoyCon controllers for me, but that's a different problem)

See also the discussion at #15819 (comment)

Existing Issue(s)

None

@Nintorch Nintorch force-pushed the add-flexible-web-mapping branch from 49579ff to 296f0cc Compare June 13, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant