Repository navigation
Conversation
…dth for the settings' buttons and controls Controls (asked for in LNPANDY#27): Settings has a Controls card whose Customize... opens a sheet with every keyboard function (sticks and D-pad, then buttons and Shake) and every controller button. A key is set by clicking its field and pressing the key (Esc keeps the old one, x leaves the function on no key); one key holds one function, so the function that had it is left on none, as the host does. A controller button picks the button it sends. The layout is kept in the user defaults, and Play passes only its changes as DM_KEYMAP / DM_PAD_MAP, which the host reads from seedds/nxnative#386 on (input_map.h); a build without it ignores them. The game's own launch options win over the layout if both ever set one variable. Widths: the Settings cards' buttons all have one minimum width, so they stand in one column (Refresh, Change folder..., Check for updates, Check again). In Launch options every control has one column of one width: the two- and three-way choices share it equally, the language list fills it, and the slider with its value fits it, so the controls of a card line up whatever their labels. ControlsTests checks the defaults (nothing passed), a move onto another function's key, a swap, a move back to the default, the controller map, persistence and the labels; the visual QA capture renders the sheet.
…rts are repaired The launcher's Controls page (PR #39) writes DM_KEYMAP / DM_PAD_MAP at Play, but nothing on this side read them: the page moved the fields and every game kept its default keys. This brings seedds/nxnative#386's engine side here — dm/host/input_map.h (the key and button maps, pure so a test runs without a keyboard) and front_mac.m using it in place of the fixed key_bit() switch — so the page does what it says. #386 is still open upstream, so front_mac.m and input_map.h are carriers here (OURS for the two new files, patch_front_mac() for the changed one), and the day #386 merges, a sync finds every anchor applied already. Two more things surfaced while checking the suites: * patch_nso.py had lost the NRO header skip (issue #14). It was fixed in 4b86323 and then silently reverted by a sync, because the file was not a carrier: an NRO's text starts at 0x80, and scanning from 0 read the header's build ID as instructions and skipped the last 128 bytes of text. Restored, and patch_nso.py is a carrier now (patch_patch_nso). * patch_tests_makefile() opened with `if 'romfs_arc.c' in t: return skip(...)`, which made the touch-pad test block that follows dead code ever after. Its first addition skips on its own now, so the new t_input_map rule is not skipped as well. docs/env_switches.tsv gains the rows the tool asks for (DM_KEYMAP, DM_PAD_MAP), the two it listed with no meaning (DM_FULL_ROMFS, DM_PROFILE), and the mode change PR #41 needed. Checked: t_input_map 22/22; the full host suite (make -C dm/host/tests run) exits 0; dmhost builds; the Python suite is 350 passed, 17 skipped, 0 failed (test_env_switches and test_nro_header were both failing before this); the sync reports every patcher agreeing with the tree.
…who carries them The section said a build without the engine change ignores DM_KEYMAP / DM_PAD_MAP and plays with the default keys. That was true when PR #39 was written — seedds/nxnative#386 was open and nothing here read them — but 9f7d421 carried #386's engine side into this fork, so it reads them now. It also points at docs/env_switches.tsv, where both names are listed.
ce6fc7a to
48a08d9
Compare
|
Updated along the lines in #388 ("Controls on the same store") and rebased on current The tests and the open points are in the description. The |
|
I checked the saved controls with a real start. I packed Hades as a Mac app with this branch, started it with
Not checked: a start through the settings window. The window waits for a click, which an unattended run can't give. No |
|
Yes, please, that's a good follow-up, and building on
seedds has the final say on the format, of course. I'd wait for his review of this PR before you build on it. |
f21be82 to
97eaa98
Compare
The upstream pull request builds on seedds/nxnative#386, which is patch 0009 here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Found while running this on two Macs with NX2Apple's launcher (which ships this patch as its
The fix that worked for me: track physical keys, then combine. typedef struct { uint8_t fn[IM_KEYS]; } key_state; // each pressed key's function plus one; zero is released
static uint32_t key_state_event(key_state *s, const key_map *m, unsigned code, int down, int shift) {
if (code < IM_KEYS) {
if (!down) s->fn[code] = 0;
else if (!s->fn[code]) {
int f = key_map_fn(m, code);
if (shift && f >= 12 && f <= 15) f = f == 12 ? IM_RLEFT : f == 13 ? IM_RUP : f == 14 ? IM_RRIGHT : IM_RDOWN;
if (f >= 0) s->fn[code] = (uint8_t)(f + 1);
}
}
uint32_t held = 0;
for (int c = 0; c < IM_KEYS; c++) if (s->fn[c]) held |= 1u << (s->fn[c] - 1);
return held;
}
|
|
Reviewed head e144537. I integrated your mapping parser and saved-choice support into a local Mac build, with adaptations for the newer input paths. One parser edge worth addressing: keycodes 54–63 are modifier-only keys. AppKit reports them through flagsChanged, so accepting them while listening only for keyDown/keyUp produces assignments that never fire. The local parser rejects those codes, and the launcher and companion use the same restriction. The newer host also has Shift+arrow camera controls. I preserved that shortcut when an arrow retains its default D-pad assignment; explicit remaps take precedence. Each physical key remembers the function selected on key-down until release, regardless of later Shift changes. Held functions are recomputed from physical keys, so releasing one of two keys driving the same function does not release the other. Focus loss and input prompts clear this state. Applying the controller map once in the shared pad_set path covers GameController and raw HID, including the full-controller Switch 2 path. Separate Joy-Con device states remain unchanged; Home and controller-setup prompts retain their normal controls. Validation: 38 parser/event checks passed, including ASan/UBSan, plus 5,828 C/Python parser-parity cases and launcher saved-choice precedence tests. A packaged OOT build also loads the latest copied save, detects the connected DualSense, and reports the test A/B and right-stick mappings correctly in its native diagnostics. Physical button presses on the remapped controller have not been exercised. These integration notes build on your patch. |
… end The keyboard goes through the key map (input_map.h), with main's Shift + arrow right stick, pointer hiding and controller prompt keys kept. DM_PAD_MAP is applied in pad_set, so GameController, raw HID and Switch 2 pads all take it; main's press-to-join and pad release stay.
An Xbox or PlayStation pad maps by position by default, as Switch emulators do: the right button is A. DM_PAD_MAP=label (launcher: Face buttons, By label) maps GameController's buttonA, the bottom button an Xbox pad marks A, to the Switch's A, buttonB to B, X to X and Y to Y, as PC games read an Xbox pad, so the letters the game asks for are the pad's. Nintendo pads map name for name either way; raw HID pads keep DM_HID_MAP. On the Mac and iOS (pad_apple.h). The host also tells a build's stubs (frame step state +0xb0), for prompts that follow the layout. Other pull requests propose the same mapping under other names (seedds#1481 DM_PAD_LABELS, seedds#2196 DM_PAD_LAYOUT); seedds#386 uses the name DM_PAD_MAP for a remap. The name here can follow whichever is taken. Front-ends: new: DM_PAD_MAP (Face buttons: position, label), in launcher.json for every game Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Mac keyboard's keys were fixed in front_mac.m (key_bit, on_key), and issues seedds#1216, seedds#2572 and seedds#2346 ask to change them. They now come from a map, dm/host/keymap.h, a pure header with tests (t_keymap), as pad_hid.h and ctrl_prompt.h are: each key presses a button, a stick direction or the shake, a target may have several keys, and the default map is the previous layout, Shift + arrows as the right stick included. How it is built, and where each choice comes from: - Keys are macOS virtual key codes (Carbon's kVK_*), as front_mac.m read them before: a binding is a key's place, so AZERTY's ZQSD works as WASD. They are named by the US layout (DM_KEYMAP=A=space RUP=up DUP=1), or #<code>. - Shift, Control and Option are keys too. macOS reports them as flagsChanged, not key downs, so a modifier event is read with the device-dependent NX_DEVICE*KEYMASK bits (the trap seedds#1216's reporter names); Command (the menus'), Caps Lock and fn are never bound. - A binding can be a chord, as in a game's own keybinding screen: hold Shift, Control or Option and press a key (shift+up; shown as the menus' symbols). A key pressed with a modifier held is the chord's target when the chord is bound, else the key's own, so ZL on Shift with the D-pad on 1 is still ZL + D-pad up. Shift + arrows as the right stick (4de40e6, for Donkey Kong Bananza's camera) was a fixed branch of on_key; it is now the default map's RLEFT=shift+left ... RDOWN=shift+down, shown and editable like any other binding. Either side's modifier makes the chord. - A key goes back up as it went down, and each target counts the keys that hold it: two keys on one target, or Shift let go before an arrow, release correctly. These are the two faults reviewers found in PR seedds#386's per-function bits (jonpage0, akratch on seedds#386). - Stored as the saved choice launcher.DM_KEYMAP, the store and precedence decided on seedds#388 and landed with seedds#431 (launch environment, env.txt, saved choices, defaults; DM_SAVED_CHOICES=0). As seedds#386 proposed, the launcher checks it with the host's own parser and ignores a value the host would not take whole. PR seedds#386's form, <name>=<key code>,... with its names, reads too, so a value NX2Apple's patch of seedds#386 saved still applies. - Remapping happens where it can be tested: Window > Keyboard Map... (Cmd-Shift-K) shows the map beside the running game, a click then a key press binds it (Esc stops; right-click: No Key, or Add Key... for another key as well), and the change applies at once and is saved. The panel never takes the key window, as the Cheats panel. The settings window's Keyboard section, right below Controls, opens the same map before the game. - Presets are INI files, as controller profiles are in other emulators (one file per profile): the original layout, then ~/Library/Application Support/nxnative/keymaps/*.ini by their Name line. Save as Preset... writes one; they can be written by hand. The Preset pop-up at the top of the map names the preset the map is (Custom once changed), as emulators show the active profile. keyboard_mac.h holds the keyboard part of the front end, as home_quit_mac.h and pad_hid_mac.h hold theirs: front_mac.m's key monitor hands it each key of the game window that is no menu shortcut, and input_release, the controller applet's prompt and the text box let go of what it holds. The prompt takes the map's keys of A and B as well as Return and Escape. pack_app.py rebuilds the launcher when keymap.h changes. Tests: t_keymap (71 checks, ASan and UBSan: the default map, chords (either side, Control and Option, a key with no chord its own, a bound Shift both a button and a chord's modifier, Shift let go first), repeats, two keys on one target, errors, the full form and keymap files read back, the presets folder, seedds#386's form); test_nsp_mac_app with a new test_saved_keymap (a real launcher: the saved choice, a launch override, DM_SAVED_CHOICES=0, a value the host rejects, seedds#386's form); test_docs, test_env_switches, test_usage, test_launcher_settings; lint_c.py tidy with LLVM 23: no findings. scripts/regress.py was not run: nothing below the Mac front end changes, and its scripted input (DM_KEYS, DM_CTL) takes another path. Played on a MacBook Pro (M3 Pro, 18 GB, macOS 27.2.1) with Ocarina of Time (0400486024DEC000, v131072), handheld and docked: the map, the panel, presets and the saved choice across starts; no added input lag noticed. The host was built from this branch's front-end files on the commit the app's shader library was packed with, since main's shader chain has moved on; front_mac.m's keyboard code is the same on both. Covers the keyboard part of PR seedds#386; DM_PAD_MAP (controller buttons) is not touched. Front-ends: new: launcher.DM_KEYMAP is a saved choice, checked by the host's parser (docs/frontends.md, Saved choices) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Mac keyboard's keys were fixed in front_mac.m (key_bit, on_key), and issues seedds#1216, seedds#2572 and seedds#2346 ask to change them. They now come from a map, dm/host/keymap.h, a pure header with tests (t_keymap), as pad_hid.h and ctrl_prompt.h are: each key presses a button, a stick direction or the shake, a target may have several keys, and the default map is the previous layout, Shift + arrows as the right stick included. How it is built, and where each choice comes from: - Keys are macOS virtual key codes (Carbon's kVK_*), as front_mac.m read them before: a binding is a key's place, so AZERTY's ZQSD works as WASD. They are named by the US layout (DM_KEYMAP=A=space RUP=up DUP=1), or #<code>. - Shift, Control and Option are keys too. macOS reports them as flagsChanged, not key downs, so a modifier event is read with the device-dependent NX_DEVICE*KEYMASK bits (the trap seedds#1216's reporter names); Command (the menus'), Caps Lock and fn are never bound. - A binding can be a chord, as in a game's own keybinding screen: hold Shift, Control or Option and press a key (shift+up; shown as the menus' symbols). A key pressed with a modifier held is the chord's target when the chord is bound, else the key's own, so ZL on Shift with the D-pad on 1 is still ZL + D-pad up. Shift + arrows as the right stick (4de40e6, for Donkey Kong Bananza's camera) was a fixed branch of on_key; it is now the default map's RLEFT=shift+left ... RDOWN=shift+down, shown and editable like any other binding. Either side's modifier makes the chord. - A key goes back up as it went down, and each target counts the keys that hold it: two keys on one target, or Shift let go before an arrow, release correctly. These are the two faults reviewers found in PR seedds#386's per-function bits (jonpage0, akratch on seedds#386). - Stored as the saved choice launcher.DM_KEYMAP, the store and precedence decided on seedds#388 and landed with seedds#431 (launch environment, env.txt, saved choices, defaults; DM_SAVED_CHOICES=0). As seedds#386 proposed, the launcher checks it with the host's own parser and ignores a value the host would not take whole. PR seedds#386's form, <name>=<key code>,... with its names, reads too, so a value NX2Apple's patch of seedds#386 saved still applies. - Remapping happens where it can be tested: Window > Keyboard Map... (Cmd-Shift-K) shows the map beside the running game, a click then a key press binds it (Esc stops; right-click: No Key, or Add Key... for another key as well), and the change applies at once and is saved. The panel never takes the key window, as the Cheats panel. The settings window's Keyboard section, right below Controls, opens the same map before the game. - Presets are INI files, as controller profiles are in other emulators (one file per profile): the original layout, then ~/Library/Application Support/nxnative/keymaps/*.ini by their Name line. Save as Preset... writes one; they can be written by hand. The Preset pop-up at the top of the map names the preset the map is (Custom once changed), as emulators show the active profile. keyboard_mac.h holds the keyboard part of the front end, as home_quit_mac.h and pad_hid_mac.h hold theirs: front_mac.m's key monitor hands it each key of the game window that is no menu shortcut, and input_release, the controller applet's prompt and the text box let go of what it holds. The prompt takes the map's keys of A and B as well as Return and Escape. pack_app.py rebuilds the launcher when keymap.h changes. Tests: t_keymap (71 checks, ASan and UBSan: the default map, chords (either side, Control and Option, a key with no chord its own, a bound Shift both a button and a chord's modifier, Shift let go first), repeats, two keys on one target, errors, the full form and keymap files read back, the presets folder, seedds#386's form); test_nsp_mac_app with a new test_saved_keymap (a real launcher: the saved choice, a launch override, DM_SAVED_CHOICES=0, a value the host rejects, seedds#386's form); test_docs, test_env_switches, test_usage, test_launcher_settings; lint_c.py tidy with LLVM 23: no findings. scripts/regress.py was not run: nothing below the Mac front end changes, and its scripted input (DM_KEYS, DM_CTL) takes another path. Played on a MacBook Pro (M3 Pro, 18 GB, macOS 27.2.1) with Ocarina of Time (0400486024DEC000, v131072), handheld and docked: the map, the panel, presets and the saved choice across starts; no added input lag noticed. The host was built from this branch's front-end files on the commit the app's shader library was packed with, since main's shader chain has moved on; front_mac.m's keyboard code is the same on both. Covers the keyboard part of PR seedds#386; DM_PAD_MAP (controller buttons) is not touched. Front-ends: new: launcher.DM_KEYMAP is a saved choice, checked by the host's parser (docs/frontends.md, Saved choices) Co-Authored-By: Claude Opus 5.5 <[email protected]>

What it does
The Mac front end's keys and controller buttons were fixed in
front_mac.m. Both assignments now come fromdm/host/input_map.h, a pure header with tests:DM_KEYMAP=<name>=<key code>,…puts a button, a stick direction (the right stick too, on no key by default) orShakeon another key (macOS virtual key code, ornone). One key holds one function:A=40,B=38swaps A and B.DM_PAD_MAP=<name>=<name>,…changes what a controller's buttons send, after the default mapping by position:A=B,B=Aswaps them,nonesends nothing.Unset, both are the previous assignments. In the host, a malformed entry is left out with a
[RED]line and the rest still applies.Saved choices (the part added for #388)
launcher.DM_KEYMAPandlauncher.DM_PAD_MAPare now saved choices in the app's preferences domain, read bydm/mac/launcher.cin the same pass and order as the others (launch environment, player'senv.txt, bundleenv.txt, saved choices, tested defaults), with the sameDM_SAVED_CHOICES=0and the same log lines (launcher: env … (saved choice),… not used: … is set,… ignored: …).They are not
launcher.jsonrows, soDMSettingscannot check them. The launcher checks them with the host's own parser instead:input_map_valid(spec, pad)ininput_map.hruns the same parser as the host, without a map and without log lines, and the launcher includes the header (-I dm/hostwas already onpack_app.py's launcher compile line;input_map.handdm_input.hare now among the packer's reuse inputs). So the host and the launcher cannot disagree about what a valid value is.One difference from the host: the launcher takes a value whole or not at all. The host alone applies the good entries of a list and names the bad ones; for a saved value written by a front end, a value with any bad entry, an empty one, or one that is not a string is ignored and logged, so a saved choice is either what the player wrote or nothing.
The controls are read whether or not the settings window ran: the window does not offer them, so
saved_choices()now also runs after the window's Play (it skips theDMSettingsrows then, as the window applied those).docs/frontends.md("Saved choices"),docs/env_switches.tsvanddocs/development.mdname the two keys and the different check.Tests
make -C dm/host/tests GAME=010015100B514000: all pass;t_input_map30 checks, 0 failed (22 before, plusinput_map_valid: valid lists, unknown name, key code past 127, text, a sign, empty andNULL, the two maps not interchangeable).dm/tools/tests/test_nsp_mac_app.py: 43 tests OK, including the newtest_saved_controls, which packs a real Mac app with its own bundle ID and starts it with a stand-in host: a valid saved keymap and pad map are applied, a launch override and the player'senv.txtwin,DM_SAVED_CHOICES=0ignores them (and leaves them saved), and invalid values (unknown name,A=128, text, a stick on a button, a key code in a pad map, empty, a non-string) are ignored and logged.test_docs.pyandtest_env_switches.py: 11 tests OK.make -C dm/host GAME=010015100B514000builds the Mac host;launcher.ccompiles with-Wallwithout warnings and links in the packed app.dm/tools/tests(360 tests): 34 do not run on the machine used, for want of the optional Python modulescapstoneandlz4(ModuleNotFoundError); the others pass. Not related to this change.Not verified
scripts/regress.py checkwas not run: it starts games, and the Mac was in use by other runs. The report will follow from a run by the author.regress.py impactwas run: the change reaches every Mac game throughlauncher.candfront_mac.m(it does not touch the host's graphics, services or tables).