Skip to content

Map Nintendo controller face buttons by label on macOS and iOS - #180

Closed
Nishikori-Yui wants to merge 2 commits into
seedds:mainfrom
Nishikori-Yui:fix/controller-layouts
Closed

Nishikori-Yui wants to merge 2 commits into
seedds:mainfrom
Nishikori-Yui:fix/controller-layouts

Conversation

@Nishikori-Yui

@Nishikori-Yui Nishikori-Yui commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Identify Nintendo Switch / Joy-Con controller layouts from Apple's GCController.productCategory on both macOS and iOS.
  • Preserve face-button labels for matching Nintendo categories (buttonA -> A, buttonB -> B, etc.).
  • Keep the existing Xbox-style positional mapping for all other categories.
  • Accept both Joy-Con and JoyCon spellings, as found in SDL and Chromium metadata.

Motivation

The Mac frontend previously converted face buttons by physical position for every controller. On an NS Pro Controller, pressing the printed B button (bottom position) therefore produced the game's A input. The same positional conversion also existed in the iOS frontend.

GameController exposes face buttons as buttonA, buttonB, buttonX, and buttonY. The supplied probe results show that for Nintendo-layout devices these properties can reflect the printed labels. Interpreting buttonB as the right-position input on those controllers caused the mismatch: the physical B was sent to the game as A.

Detection approach

Following the recommendation in the review discussion, this uses a Nintendo-only whitelist rather than attempting to enumerate Xbox, PlayStation, and every third-party controller. It checks Apple's productCategory, not the user-editable vendorName:

NSString *category = controller.productCategory ?: @"";
// Apple and third-party metadata use both "Joy-Con" and "JoyCon".
return [category localizedCaseInsensitiveContainsString:@"switch"] ||
       [category localizedCaseInsensitiveContainsString:@"joy-con"] ||
       [category localizedCaseInsensitiveContainsString:@"joycon"];

We accept both Joy-Con spellings because SDL reports Nintendo Switch Joy-Con (L/R), while Chromium has Nintendo Switch JoyCon (L/R). Categories that do not match retain the existing positional behavior.

Before and after

Before: every controller mapped by position

#define K(btn, bit) if (btn.isPressed) m |= bit
K(g.buttonB, DM_BTN_A);
K(g.buttonA, DM_BTN_B);
K(g.buttonY, DM_BTN_X);
K(g.buttonX, DM_BTN_Y);

This is the Xbox-style physical-position conversion for Switch games:

right  -> game A
bottom -> game B
top    -> game X
left   -> game Y

For the NS Pro Controller's printed B, GameController reports buttonB, but the old code treated that property as the right-position input and sent game A.

After: label mapping for Nintendo categories, position mapping otherwise

if (pad_uses_nintendo_labels(g.controller)) {
    K(g.buttonA, DM_BTN_A);
    K(g.buttonB, DM_BTN_B);
    K(g.buttonX, DM_BTN_X);
    K(g.buttonY, DM_BTN_Y);
} else {
    K(g.buttonB, DM_BTN_A);
    K(g.buttonA, DM_BTN_B);
    K(g.buttonY, DM_BTN_X);
    K(g.buttonX, DM_BTN_Y);
}

The same conditional mapping is implemented in iOS read_pad, using its B_A/B_B/B_X/B_Y input bits.

Device probe evidence

The reported GameController probe output:

# Nintendo Switch Pro Controller
vendorName: Pro Controller
productCategory: Switch Pro Controller
buttonA: A Button / a.circle
buttonB: B Button / b.circle
buttonX: X Button / x.circle
buttonY: Y Button / y.circle

# PlayStation DualSense
vendorName: DualSense Wireless Controller
productCategory: DualSense
buttonA: Cross Button / xmark.circle
buttonB: Circle Button / circle.circle
buttonX: Square Button / square.circle
buttonY: Triangle Button / triangle.circle

# Third-party Nintendo-layout controller
vendorName: Pro Controller
productCategory: Switch Pro Controller
buttonA: A Button / a.circle
buttonB: B Button / b.circle
buttonX: X Button / x.circle
buttonY: Y Button / y.circle

Both the original and third-party Switch-layout controllers report Switch Pro Controller, while DualSense reports DualSense. This supports using Apple's category as the auto-detection signal instead of matching a user-editable name.

Mapping details

Category GameController input Game input
Contains Switch, Joy-Con, or JoyCon buttonA A
Contains Switch, Joy-Con, or JoyCon buttonB B
Contains Switch, Joy-Con, or JoyCon buttonX X
Contains Switch, Joy-Con, or JoyCon buttonY Y
Any other category buttonB (right position) A
Any other category buttonA (bottom position) B
Any other category buttonY (top position) X
Any other category buttonX (left position) Y

Shoulders, triggers, sticks, D-pad, menu/options buttons, rumble, input delivery, and player assignment are unchanged.

Verification

  • Mac host build succeeds for Ghost Trick: Phantom Detective.
  • Host test suite completes successfully.
  • iOS compile check passes: 133 files, 0 failed.
  • git diff --check passes.
  • Physical NS Pro Controller behavior was verified locally on macOS. iOS hardware testing and Joy-Con category reporting have not yet been verified.

Limitation

Auto-detection depends on Apple's productCategory. A third-party Switch-layout controller reported under an unrelated category will continue to use positional mapping. This change intentionally does not add a manual layout setting or enumerate other controller categories.

@Nishikori-Yui Nishikori-Yui reopened this Oct 25, 2026
@Nishikori-Yui
Nishikori-Yui marked this pull request as draft October 25, 2026 13:28
@Nishikori-Yui
Nishikori-Yui marked this pull request as ready for review October 25, 2026 13:38
@Nishikori-Yui

This comment was marked as outdated.

@Nishikori-Yui
Nishikori-Yui force-pushed the fix/controller-layouts branch from ea12b67 to fccf983 Compare October 26, 2026 14:53
@Nishikori-Yui

Nishikori-Yui commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated this PR based on @bingoxp's suggestion. Thanks for pointing out productCategory as a more reliable detection signal!

The implementation now uses GCController.productCategory to identify Nintendo-related controllers (Switch, Joy-Con, or JoyCon), rather than relying on vendorName or enumerating individual controller models. All other controllers retain the existing positional mapping.

The same fix is now applied to both macOS and iOS. I've also updated the PR description with the implementation details, before/after code, and device-probe results, including tests with an official and a third-party Switch Pro Controller.

@Nishikori-Yui Nishikori-Yui changed the title Map Mac controller face buttons by layout Map Nintendo controller face buttons by label on macOS and iOS Oct 26, 2026
@Nishikori-Yui

Copy link
Copy Markdown
Contributor Author

@seedds, the changes are ready for review. I'd appreciate it if you could take a look when you have a chance. Hopefully we can get this fix merged upstream soon.

@v0lumehi

Copy link
Copy Markdown
Contributor

Heads-up: #388 proposes treating controls as data that every UI writes (#388 (comment)): the key and button maps (#386's DM_KEYMAP / DM_PAD_MAP) in one per-game store, so a controls page in any launcher and an in-app panel never disagree. Mapping face buttons by label is also proposed in #295 and #382. It would help to settle it in one place.

@Nishikori-Yui

Copy link
Copy Markdown
Contributor Author

Thanks for pointing out the overlap with #295, #382, and #386. I agree that the controller work should eventually be coordinated in one place.

For #180, the intended scope is only the default behavior when no user mapping has been configured. It uses GCController.productCategory as a Nintendo-only whitelist signal (Switch, Joy-Con, and JoyCon) and preserves the labels reported by GameController for those categories. Other categories keep the existing positional mapping. The same default behavior is applied on macOS and iOS.

A future controls UI or DM_PAD_MAP-style configuration could override this automatic result and be stored in the shared per-game controls data. That would make the automatic detection a fallback, without requiring a setup step for the common case. The details of that shared configuration belong with the broader controls work; #180 can remain focused on establishing a reasonable default mapping.

@subyoung

Copy link
Copy Markdown

A data point from iPadOS for this PR: GameController reports a combined Joy-Con (L/R) pair by label too, not only the Pro Controller.

On an iPad Air 13-inch (M3), iPadOS 27.2 (productCategory Nintendo Switch Joy-Con (L/R)), I logged each press by GameController name. With the pair held sideways, the right Joy-Con's top, right, bottom and left buttons gave buttonY, buttonX, buttonA, buttonB. Those are the buttons printed Y, X, A and B, so buttonA is the button marked A.

So the joy-con / joycon match here covers the combined pair as well. #585 (Joy-Con pairs held sideways) relies on the same finding for the sideways halves and leaves the upright mapping to this PR.

@seedds

seedds commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Superseded by 90eca2f (PR #650), which implements Nintendo face-button mapping in a shared helper for Mac and iOS. Closing this overlapping implementation.

@seedds seedds closed this Oct 30, 2026
ltrdpper pushed a commit to ltrdpper/BananaNative that referenced this pull request Nov 12, 2026
…settings, Ocarina of Time on Qualcomm

- Game language: Polish (pl) and Thai (th), from SDK 21's own settings table (sdk+0xc62b5c in Ocarina of Time lists pt-BR, pl, th); the launcher list, the host's DM_LANG mapping and GetAvailableLanguageCodes. Ocarina of Time (`0400486024DEC000`) carries EUpl messages, Donkey Kong Bananza (`040074A01BF12000`) 1.1 EUpl and THth.
- Launcher: one full page per game with tabs Performance (Picture, Speed, Advanced), Game (options, Game language, Controls), Saves and Storage; rows wrap and say what they do; profile options keep their description and say when they need Prepare again.
- Recommended settings per game and phone (game.tsv recommend rows, Recommend.java): a card with Recommended / Custom and tags on the rows; facts from GLES at launcher start before the first readiness check. Ocarina of Time on Qualcomm: system driver, Performance preset, Full vegetation off.
- Resolution presets (res_preset, scene_output rows) and Scene resolution overlays from a game's own dynamic resolution palette (scene_res.py, DM_ROMFS_OVERLAY).
- Qualcomm's own driver: mesh draws through compute by default (full Ocarina of Time foliage; DM_VK_MESH=1 keeps native mesh shading).
- Mesh draws through compute: a draw takes its own record's entry, and prewarm drops mesh / pixel pairings that do not feed each other (see-through on Adreno 830, black-line flicker on Turnip, issue seedds#180).
- Texture serial map: probes past tombstones, live and tombstone counts apart (the table no longer grows with every serial ever registered).
- pack_android.py: a profile with a selected shader set builds that set on the Mac and Windows (issue seedds#178).
- PRs seedds#150, seedds#151, seedds#171 (FrenklinFish) and seedds#156, seedds#163 (Omnicrash) were merged on Forgejo before this update.
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.

4 participants