Skip to content

launcher: A/B buttons setting for the Nintendo or Xbox / PlayStation layout - #634

Closed
oliverames wants to merge 4 commits into
seedds:mainfrom
oliverames:feat-pad-ab
Closed

oliverames wants to merge 4 commits into
seedds:mainfrom
oliverames:feat-pad-ab

Conversation

@oliverames

@oliverames oliverames commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The face-button layout is fixed today: physical controllers map by position (right = A, bottom = B), a Nintendo pad by its labels (dm_pad_labelled), and the iPhone touch gamepad draws A on the right, as on a Switch controller. On an Xbox or PlayStation controller the printed A / Cross is at the bottom, so pressing it sends the game's B (cancel), and the touch gamepad shows the opposite of the controller's labels.

This adds a Controls → A/B buttons launcher row (DM_PAD_AB), so every game gets it:

  • Nintendo (default): A on the right, B at the bottom. The existing behavior, unchanged.
  • Xbox / PlayStation: A (Cross) at the bottom, B (Circle) on the right.

The iPhone touch gamepad moves the A and B keys to the chosen positions; physical controllers on iOS and the Mac swap their A/B mapping. X and Y keep their positions. The value is read once at launch, like the other launcher settings.

This is the player-facing choice. #180 (controller detection) and #102 (the Mac-only DM_PAD_LAYOUT=letters) are both closed, and main now detects a Nintendo controller by its labels (dm_pad_labelled). An explicit DM_PAD_AB=xbox should win over that detection because the player chose it.

Checked

  • Tests: python3 -m unittest dm.tools.tests.test_launcher_settings dm.tools.tests.test_env_switches dm.tools.tests.test_docs: 27 passed before the rebase onto main. After it, test_docs, test_settings and test_launcher_settings pass, t_pad_hid (30 checks) and t_pad_apple pass, and test_env_switches failed only for names that failed on main too at the time (DM_NVN_BC_ALIAS and docs quoting removed switches); it passes on main now.
  • Build: make -C dm/host GAME=01007EF00011E000, passes. DmGamepad.m passes an iOS SDK syntax check (xcrun --sdk iphoneos clang -fsyntax-only ...).
  • Games run: none. This is a minor change and device/controller testing was not requested.
  • Devices and OS: build checks on the Mac only; no controller, iPhone or game acceptance.
  • scripts/regress.py check --games: not run (input-only change; no rendering, shader or game-facing host path).

Front ends

None: no front end has to act on this. The choice reaches the front ends as the DM_PAD_AB env switch and a settings row, which git shows (docs/env_switches.tsv, dm/games/settings.tsv); front.h is unchanged.

Docs

  • The setting is in docs/settings.md (Controls and the env table), docs/playing.md, and docs/env_switches.tsv; no game note or symptom entry applies.
  • A chain tool changed: dmsh_chain.py --header was run and dm/gfx/nvn/dmsh_chain.h is part of the change. Not applicable: no chain tool changed.
  • No game files, keys or data extracted from a game in the change.

Rebased onto main fd8188c9 on 2026-11-10 with no conflicts (head 4b876627). On that head test_env_switches (1), test_docs (6), test_launcher_settings (17), test_xcode_workflow (7) and test_settings (3) pass, t_pad_hid passes 30 checks and t_pad_apple passes, the host builds, the unsigned iOS app builds, and clang-tidy has no finding in the changed files. The first commit carried the wrong author address by mistake; all commits are now under mine.

@tomcool420

Copy link
Copy Markdown

I think you might want to handle the pad_hid case also?

@oliverames

Copy link
Copy Markdown
Contributor Author

Thanks @tomcool420, good catch. The raw HID gamepad path (pad_hid.h) ignored DM_PAD_AB. pad_hid_init now takes the xbox flag and swaps the default A and B (usage 1 becomes A, usage 2 becomes B); DM_HID_MAP entries still apply over it. t_pad_hid covers both layouts and the override (22 checks), and the docs and launcher-settings tests pass. Pushed as aebe3e5d, rebased onto current main. I have not tried it on a physical HID pad.

@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios) mac The Mac front end and app (dm/mac, front_mac.m) docs Documentation labels Nov 3, 2026
@oliverames
oliverames force-pushed the feat-pad-ab branch 2 times, most recently from 04e2f96 to ac05703 Compare November 5, 2026 14:49
@oliverames
oliverames force-pushed the feat-pad-ab branch 2 times, most recently from b7e81b9 to c020c14 Compare November 7, 2026 19:37
@oliverames

Copy link
Copy Markdown
Contributor Author

Rebased onto main 7f50222 with no conflicts (main's Pro Controller/HID changes kept; the DM_PAD_AB hook sits beside them in pad_hid_mac.h). t_pad_hid (30 checks), t_pad_apple, test_docs/test_settings/test_launcher_settings pass.

Oliver Ames added 2 commits November 10, 2026 08:29
…layout

DM_PAD_AB=nintendo (the default) keeps the Switch's face buttons, A on the
right and B at the bottom. DM_PAD_AB=xbox puts A (Cross) at the bottom and B
(Circle) on the right, as Xbox and PlayStation controllers print them.

The row is in dm/games/settings.tsv, so every generated launcher.json offers
it on the iPhone and the Mac. The iPhone touch gamepad moves the A and B keys
to the chosen positions, and physical controllers on both front ends swap
their A/B mapping. X and Y keep their positions.

Checked: test_launcher_settings, test_env_switches and test_docs (27 tests);
the Mac host builds for Breath of the Wild; DmGamepad.m passes an iOS SDK
syntax check. No device or controller testing (minor change, not requested).
khalilgharbaoui pushed a commit to khalilgharbaoui/nxnative-ultimate that referenced this pull request Nov 15, 2026
…ts with its B, so couch play needs no mouse; the press that starts the game does not reach it and A never answers the cloud-save question

## What and why

The Mac settings window (`dm/mac/Launcher.swift`) could only be answered with the mouse or the keyboard (Play / Return, Quit / closing the window). With a controller only, the player had to reach for the Mac to start the game.

Now a controller's A is Play and its B is Quit. They are GameController's `buttonA` and `buttonB` on any controller, as the host's own quit and player prompts take them (`front_mac.m` `hq_buttons`, `cp_buttons`); main has no A/B layout setting (seedds#634 is open), so none is added. The decisions are a small pure struct, `LauncherPad`, which a 60 Hz timer in common run-loop modes feeds with the buttons of every controller GameController lists:

- A button counts on its **release**, after a press the window took. The settings go into the environment and the host is spawned only after that (`launcher.c`), in a new process whose GameController reads the controllers from scratch (`pads_changed` reads each one's state at its connection; with `DM_PAD_PRESS_TO_JOIN` a controller joins on a value change). The button is up by then, so the press that started the game reaches it neither as a button nor as a join.
- A button already down when the window starts taking input (held at launch, or through an alert) counts only after it was seen up.
- The window takes no button while it is not key, while an alert or a panel is modal (`NSApp.modalWindow`), with a sheet attached, or while a menu tracks (`RunLoop.current.currentMode == .eventTracking`). A press is dropped when any of these starts. So A never picks a save: the save-sync conflict alert keeps no default button on purpose (`SaveCheck.ask`), and it stays a mouse or keyboard choice.
- A follows the Play button's state: it does nothing during the cloud-save check (Play disabled); B works then, as the Quit button does.
- Play from A goes through the same `start()` as the button, so the cloud-save check and its questions still come first.

The window logs `launcher: Play from a controller (A)` / `launcher: Quit from a controller (B)`.

Mac only. The iPhone/iPad launcher (`dm/ios/Sources/Launcher.swift`) runs the host in the same process, whose `DmGamepad.m` handlers take the controllers when the game starts, and an iOS app has no Quit. It needs its own check of those handlers and a device test, which an unsigned IPA cannot get from this change, so it is left for a separate PR. Moving through the settings rows with the d-pad is not part of this change either.

Not covered: controllers the host reads outside GameController (raw HID pads, `pad_hid_mac.h`; Switch 2 controllers over the host's own transport) are not seen by the window.

## Checked

- Tests: `dm/ios/tests/test_launcher_storage.py` now also compiles `launcher_pad_check.swift`: 14 decisions (release, not press; B; a button held at the start; after it is let go; a press across an alert, in an alert, held after it; a new press after an alert; the first sample after an alert; A while Play is disabled; B during the cloud-save check; a Play disabled before the release; A and B together; each button its own click). On main the check does not compile (`LauncherPad` does not exist), so all 14 fail. `test_docs.py` (6), `test_nsp_mac_app.py` (63), `test_launcher_settings.py` (17), every `dm/ios/tests/test_*.py`: pass. The launcher sources typecheck with no warning in Swift 5 mode.
- The Mac launcher built with `pack_app.py`'s `build_launcher` (macOS 26.6 target), in a copy of Ocarina of Time's app (0400486024DEC000) with its own bundle ID and home folder: the window opens (`launcher: 18 settings shown`, a 560 × 737 window on screen), and the idle timer costs about 0.4 % of a core while the window is not key and about 0.5 % while it is key and in front (CPU time over 10 s). Return and Play were not pressed in this run: keys posted to the app from a script were not delivered (the script has no accessibility permission), so the game was not started from the window. The Play button and its Return shortcut are unchanged lines.
- **Not tested: a real controller press.** No controller was connected to this Mac (an 8BitDo and a DualSense are paired but not connected), and macOS has no `GCVirtualController`. A press on a real controller, and the host seeing nothing of it, still have to be tried.
- Devices and OS: Apple silicon Mac, macOS 27.2.
- regress.py: not run; the change is in the Mac app's settings window and its packer only, which no game run in `regress.py` goes through.
- Lint: not run.

## Docs

- `docs/settings.md` (The Mac settings window): A is Play, B is Quit, on release; held buttons and the cloud-save question; what it does not do.
- `docs/playing.md` (On the Mac): one line.

(cherry picked from commit ccff249)
@cagatay-io

cagatay-io commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Checked on a device: iPhone (A20 Pro, iOS 27.2) with a SCUF NOMAD mobile controller (Xbox-style labels, A at the bottom), Zelda: Ocarina of Time 0400486024DEC000, this PR carried on top of main 2da2c14, A/B buttons set to Xbox / PlayStation in the settings screen. From the log: A/B buttons: Xbox / PlayStation was in effect and the controller came in as player 1. From the player's report (not logged): the face buttons worked as expected in play; no button-by-button check was recorded.

One difference to note: the build we ran also mapped X and Y by label (A=B, B=A, X=Y, Y=X, the same as the Mac's "Xbox Labels" Button Mapping preset), and the touch gamepad drew X left / Y top to match. In this PR X/Y stay positional (t_pad_apple expects a physical Xbox X to send the game's Y in xbox mode), so on an Xbox-labelled pad X and Y still come out swapped against their labels. If you want X/Y by label as well, I can send that commit here or as a follow-up.

@oliverames

Copy link
Copy Markdown
Contributor Author

@seedds I merged current main into this branch in f0b0d00. Main moved the HID code to per-layout button maps, so pad_hid_init now swaps A and B in whichever layout's map applies, before any DM_HID_MAP entries, and pad_hid_mac.h passes the setting in from DM_PAD_AB. pad_apple.h keeps both the face-button helpers and main's dm_pad_lights.

t_pad_hid passes all 172 checks, including new Xbox-layout checks on the Nintendo map and report 0x30, and t_pad_apple, the docs and settings tests and the iOS compile check pass too. I haven't tried the swap on a physical pad with the new X360, wired Switch and Nintendo layouts.

@seedds

seedds commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Thanks @oliverames for the work on this and for keeping the branch rebased against the recent HID changes!

Closing this PR because automatic Nintendo face-button detection is already on main (commit 90eca2f), and for a manual override we want all four face buttons (both A/B and X/Y) covered rather than an A/B-only switch, as noted in #386 and now implemented across GameController, raw HID, and Steam Controller paths in #3387. We checked current main, #386, and #3387.

Still open: landing the four-button manual override (#3387 / shared controls in #386), and deciding whether the iPhone touch gamepad should also offer an alternate face-button layout.

@seedds seedds closed this Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios) mac The Mac front end and app (dm/mac, front_mac.m)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants