Skip to content

host/input: the player's controls file (button map, keyboard map, mouse as a stick) - #3141

Open
Eriksrevenge1 wants to merge 3 commits into
seedds:mainfrom
Eriksrevenge1:pr/controls-file
Open

Eriksrevenge1 wants to merge 3 commits into
seedds:mainfrom
Eriksrevenge1:pr/controls-file

Conversation

@Eriksrevenge1

Copy link
Copy Markdown
Contributor

What and why

The Mac keyboard's map was a fixed table in front_mac.m, a controller's buttons could not be sent as others, and the mouse was only the touch screen. The host now reads the player's controls (dm/host/controls.h): DM_CONTROLS, files separated by : read in order with later lines winning, else <DM_ROOT>/controls.txt. A file can send a controller's buttons as others on every controller path, swap the sticks, change or clear the keyboard map (by macOS key code), and make the mouse a stick (a click in the picture captures the pointer; Escape, losing focus or the controller prompt give it back). Without a file nothing changes. A line the host does not understand is a [RED] controls: line and is skipped. The Mac app's launcher passes the global file and then the game's; the iPhone app reads Documents/controls.txt. Described in docs/frontends.md, Controls and docs/playing.md.

Checked

  • Tests: t_controls (31 checks), t_hid (561), the host tests (make -C dm/host/tests run), the host build, launcher.c compiled with -Wall -Werror, test_docs, test_settings, test_launcher_settings, test_env_switches
  • Games run: Nintendo Switch 2 Welcome Tour (040057C02159A000, v262144), a Mac app built from this branch, fullscreen on a DELL S2725QC, about 90 s per run from launch: with a controls file of pad a=b, key 38=b and mouse=right the log shows controls: read … and controls: controller buttons mapped, no [RED] controls: line, no crash. (One [RED] stage 0 cb7 has no uniform buffer bound at frame 6, the game's own, as without the change.)
  • Devices and OS: Apple M6 Mac mini, macOS 27.0.1, Xcode 27.2
  • Not run: lint_c (no LLVM release installed here; CI's lint-c job runs it).

Front ends

Front-ends: new: the controls file (docs/frontends.md, Controls). A front end writes it; the host never does.

Docs

  • The change is described where players and front ends read it (see the commit), and python3 dm/tools/docs_symptoms.py was run where docs/reference changed
  • No game files, keys or data extracted from a game in the change or the attachments

@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 21, 2026
Eriksrevenge1 added a commit to Eriksrevenge1/cartridge that referenced this pull request Nov 21, 2026
…dds#3158)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Fixed the clang-tidy ratchet failure: t_controls closes the first temporary file when the second cannot open.

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main; test_docs and test_patches pass (the host builds where the change touches it). The Tool tests failure came from a stale merge base.

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main (it was 50+ commits behind); the clang-tidy ratchet failure was only the baseline file out of step with the tree it ran on (0 findings above it, entries below it). The host builds, test_docs and test_env_switches pass, and the host tests pass here. Not run: GPU and game checks (no Metal 4 here).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main: main.m and launcher.c conflicted only beside the new DM_ALBUM_DIR lines (both kept). The host builds; t_controls, test_docs and test_env_switches pass; launcher.c compiles with -Wall -Werror.

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main (39 commits behind; #3142 on the rebased #3141). The CI failures were from the old merge base. The host builds; test_docs, test_env_switches and test_patches pass, and the host tests show no failure. Not run: GPU and game checks (no Metal 4 here).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main (23 commits behind). The host builds; test_docs, test_env_switches and test_patches pass. Not run: GPU and game checks (no Metal 4 here).

@Eriksrevenge1
Eriksrevenge1 force-pushed the pr/controls-file branch 2 times, most recently from d28971f to e2f7b3f Compare November 24, 2026 18:29
@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main: the clang-tidy ratchet finding was in dm/gfx/tests/t_cpu_tex.m, which this change does not touch (old merge base). The host builds; test_docs and test_env_switches pass. Not run: GPU and game checks (no Metal 4 here).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main: docs/playing.md conflicted beside main's HID paragraph (both kept). The host builds; test_docs, test_env_switches and test_patches pass. Not run: GPU and game checks (no Metal 4 here).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main: front_mac.m conflicted beside the new right-stick motion menu (both kept). The host builds; test_docs, test_env_switches and test_patches pass. Not run: GPU and game checks (no Metal 4 here).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main (53 commits behind): the Sanitizers failure was t_audio_device's watchdog test, which main has since made deterministic (2d0773f). The host builds; test_docs, test_env_switches and test_patches pass. Not run: GPU and game checks (no Metal 4 here).

Eriksrevenge1 and others added 3 commits November 27, 2026 18:26
…se as a stick)

The Mac keyboard's map was a fixed table in front_mac.m, a controller's
buttons could not be sent as others, and the mouse was only the touch screen.

The host now reads the player's controls (dm/host/controls.h): DM_CONTROLS,
files separated by ':' read in order with later lines winning, else
<DM_ROOT>/controls.txt. A file can send a controller's buttons as others on
every controller path (hle_hid.c dm_pad_set_player, dm_joy_set), swap the
sticks, change or clear the keyboard map (by macOS key code), and make the
mouse a stick: a click in the picture captures the pointer, its movement is
summed into a tilt 120 times a second, its buttons do the file's actions, and
Escape, losing focus or the controller prompt give it back. The built-in
keyboard map is unchanged without a file; Shift with an arrow is still the
right stick while that arrow keeps its built-in action. A line the host does
not understand is a [RED] controls: line and is skipped. The Mac app's
launcher passes the global file and then the game's; the iPhone app reads
Documents/controls.txt.

Front-ends: new: the controls file (docs/frontends.md, Controls). A front end
writes it; the host never does.

Checked: t_controls (31 checks), t_hid (561), the host tests (make run),
the host build, launcher.c compiled, test_docs, test_settings,
test_launcher_settings, test_env_switches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clang-tidy's analyzer (lint-c) flagged the test's fdopen of an unchecked
mkstemp result and the stream that could be NULL (unix.StdCLibraryFunctions,
unix.Stream, two each). The test now stops with a message when either
temporary file cannot be made or opened.

Checked: t_controls (31 checks, 0 failed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d cannot open

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main (83 commits behind); the clang-tidy ratchet finding was in dm/gfx/tests/t_perf_order.m, which this change does not touch and main has since fixed (9fd5bbe). The host builds; test_docs and test_env_switches pass. Not run: GPU and game checks (no Metal 4 here).

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.

2 participants