Repository navigation
Add Steam Controller (2026) support on macOS - #221
thehobbit85 wants to merge 3 commits into
Conversation
421e920 to
f7c2f2f
Compare
|
I tested this PR with a real 2026 Steam Controller. Rumble works. Gyro data reaches the game, but TotK's gyro aiming does not respond to it. Details below. Setup
Results
Axes and signsA read-only IOKit probe (sends nothing to the controller) guided four moves and integrated the raw gyro at offset 40, using the PR's scale. The accelerometer is at offset 34.
So the controller's axes are the Switch's, and the PR's mapping ( What TotK receivesI added a temporary trace, TotK 1.4.3 imports only
A Side finding: six-axis handle encoding
Not done
|
Follow-up: gyro aiming works with a stick deadzoneI found why TotK's bow aiming ignored the gyro. The motion data was correct throughout. The Steam Controller's sticks have no deadzone in this PR.
With a radial deadzone in --- a/dm/host/steam_input.h
+++ b/dm/host/steam_input.h
@@ #pragma once
+#include <math.h>
#include <stddef.h>
+#include <stdlib.h>
#include <string.h>
@@
+// The raw HID sticks rest a few counts off centre; the console's input service reports a centred stick as exactly 0 (a radial deadzone), and games rely on it:
+// Tears of the Kingdom treats any non-zero stick as stick input and stops gyro aiming. Radial deadzone of DM_STEAM_DEADZONE (fraction of full scale, default 0.10),
+// rescaled so the edge still reaches full scale
+static inline void steam_deadzone(int32_t *x, int32_t *y) {
+ static float dz = -1; if (dz < 0) { const char *e = getenv("DM_STEAM_DEADZONE"); dz = e ? (float)atof(e) : 0.10f; if (!(dz >= 0 && dz < 0.9f)) dz = 0.10f; }
+ float fx = *x / 32767.0f, fy = *y / 32767.0f, m = sqrtf(fx * fx + fy * fy);
+ if (m <= dz) { *x = *y = 0; return; }
+ float k = (m - dz) / (1 - dz) / m; // each axis clamped on its own, so a full diagonal stays at full scale on both axes
+ *x = (int32_t)lrintf(fmaxf(-1, fminf(1, fx * k)) * 32767); *y = (int32_t)lrintf(fmaxf(-1, fminf(1, fy * k)) * 32767);
+}
@@ steam_decode
s->rx = steam_axis(p + 14); s->ry = steam_axis(p + 16);
+ steam_deadzone(&s->lx, &s->ly); steam_deadzone(&s->rx, &s->ry);
How it was traced (TotK 1.4.3,
Corrections to my comment above:
Still not tested: trackpads, rear buttons, the mapping window, Bluetooth and the Puck. |
a9d9941 to
eb44c9b
Compare
|
Heads-up: #388 proposes treating controls as data that every UI writes (#388 (comment)): the key and button maps (#386's |
e2bdbaf to
f115432
Compare
|
The fixes for the USB-C findings and gyro-aiming follow-up are included in the cleaned three-commit series:
Implementation and regressions: motion/rumble foundations and controller input. The full host suite, ASan/UBSan and thread checks passed locally, as did the Mac host build. Both code commits also build and pass the host suite independently. The remaining hardware limits are documented: gyro scale calibration is still unconfirmed, and this final revision needs physical trackpad/rear-button/transport retesting. Recenter keeps a truthful identity pose; we have not added a fabricated rotation to avoid TotK's identity check. No game was launched during this update. |
|
The shared-controls coordination comment is now implemented in 075ce81. The launcher and host use #386's Launch environment and Synthetic integration tests cover launcher/host domain agreement, precedence, malformed choices, session-only edits, model isolation and panel actions. They passed, along with the packaging/docs tests and lint ratchet. The store contract and player guide describe the behavior. This incorporates #386 at |
64410df to
26b6fcb
Compare
a1e0012 to
506259d
Compare
c2b75bc to
8dfa9c6
Compare
|
Hi @seedds — I've refreshed the branches that had conflicts with current main. Could you help me prioritize review of these PRs?
Validation and remaining limitations are recorded in each PR. CI on the refreshed heads is being verified separately. Which of these best fits the project's current priorities, and are there scope changes or specific validation you would like before review? I'm happy to focus on a smaller subset first. Thanks for your time. |
6adc104 to
54d923a
Compare
892b350 to
5bd183c
Compare
0115 and 0117 extend fork-only parts upstream declined (#492, #488). 0118, 0120 and 0121 build on the touch patches 0065 to 0070 and 0090, 0122 on seedds/nxnative#221. They are forwarded once those land.
|
return NSBundle.mainBundle.bundleIdentifier ?: [[@"org.nxnative." stringByAppendingString:@(DM_GAME_ID)] lowercaseString]; |
5bd183c to
1766226
Compare
1766226 to
6a585be
Compare
) Patch 0017 builds the Mac preferences domain by joining @"org.nxnative." and DM_GAME_ID as string literals. A multi-program profile such as Super Mario 3D All-Stars defines DM_GAME_ID at run time, so its Mac host did not compile. The new patch boxes the ID at run time, as seedds/nxnative#221's branch already does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s_mac.h) Patch 0017's input_preferences_mac.h joined "org.nxnative." with DM_GAME_ID at compile time, which does not compile when DM_GAME_ID is read at run time, as in a game of several programs (LUNAR Remastered Collection). The new patch 0054 joins them at run time; the string is the same for a one-program game. Belongs in seedds/nxnative#221 with 0017. The other two engine bugs of #1224 (cpk.py offsets, provisional program profiles) are upstream as 8e7b9bf and 5b086b7 and came with the sync to 5a4e23a2e952. Part of #1224. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JhC6PmqAEWZuUNEEEgBm91
Adapt seedds/nxnative PR seedds#221 by thehobbit85 ([email protected]) at source commit 5e2b1c7276e0745825f17d7875ec0e56b6913f7b to the NX2Apple pinned engine and existing input mapping carrier. Preserve fork window, screen, aspect and cursor behavior while integrating controller ownership, motion, haptics and shared preferences. Retain the pin refresh's split Joy-Con input, per-half motion and haptic localities in the shared controller registry. Preserve the newer pointer, embedded-section and iOS game-framework behavior. Advertise DMControllerMappings=1 in Mac app metadata so launchers can gate the shared mapping contract independently of DMSettings. Front-ends: Gate shared DM_KEYMAP, DM_PAD_MAP and controller.<model> preferences on the DMControllerMappings capability marker. See docs/frontends.md for the exact storage contract. Upstream-Status: forwarded seedds#221 Reason: Provide Steam Controller support and shared Mac controller mappings on the pinned engine while the upstream pull request is pending Issue: seedds#221
Upstream-Status: pending [builds on controllers_mac from seedds#221] Reason: Open an in-game Home menu on short Home press, pause in background, and guard hide timers across resume Issue: LNPANDY/NX2Apple#1120
…d test Upstream-Status: pending [builds on seedds#1322 and seedds#221] Reason: Honor DM_PAD_PRESS_TO_JOIN on Bluetooth Joy-Cons and verify one Pro Controller registers one pad Issue: LNPANDY/NX2Apple#1150
…program games Symptom: the Mac host of LUNAR Remastered Collection (a launcher and two game programs, packed as one app with the profile key programs) does not compile: front_mac.m and controllers_mac.m stop in input_preferences_mac.h with "called object type 'NSString *' is not a function or function pointer". Cause: input_preferences_mac.h built the fallback preferences domain by joining two literals at compile time, [@"org.nxnative." DM_GAME_ID lowercaseString]. That works when DM_GAME_ID is a string literal, as in a one-program game's game_profile.h. For a game of several programs, game.py header_multi defines it as (dm_game_cur()->id), a C string read at run time, and the juxtaposition no longer parses. Fix: join the strings at run time, [[@"org.nxnative." stringByAppendingString:@(DM_GAME_ID)] lowercaseString], as front_mac.m already boxes DM_GAME_ID with @(...). The domain is the same string for a one-program game. Checked: with this change Lunar's Mac app builds and runs the launcher and both game programs (M3 Max); the domain string of a one-program game is unchanged (the same characters, joined at run time). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JhC6PmqAEWZuUNEEEgBm91 Upstream-Status: pending (a fix to patch 0017's input_preferences_mac.h, forwarded as seedds#221: it belongs in that pull request) Reason: patch 0017's input_preferences_mac.h does not compile for a game of several programs (LUNAR Remastered Collection), where DM_GAME_ID is read at run time Issue: LNPANDY/NX2Apple#1224
…mple motion_apple.h now takes a controller as a motion source once its rotation rate changes from its first report. test_native_motion_integration sent one report and expected it published; it now sends a priming report first. Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream-Status: fork-only (t_controllers_mac.m comes with patch 0017, forwarded seedds#221) Reason: test_native_motion_integration in the fork's t_controllers_mac.m needs a priming report since patch 0100 Issue: LNPANDY/NX2Apple#971
|
Hi @seedds, First of all, thank you so much for all the time you put into maintaining this project, and for the time you spend reviewing my many PRs. I know there have been a lot of them, and I really appreciate the patience and care you give each one. If and when you have a moment, would you be willing to take a second look at this Steam Controller (2026) PR (#221), and see whether it could be merged? It has been rebased onto current main and is mergeable. If anything about it isn't the way you'd like it, whether the approach, its scope, or how it is split up, I'm very happy to change it, split it, or rework it however suits you best. To be honest about why I'm asking: out of all my PRs, the LOLLIPOP CHAINSAW RePOP ones (#684 and #3075) and the Steam Controller one (#221) are the only ones I've personally been interested in. All the others are just me trying to be useful to the project. No pressure at all, and thanks again for everything you do here. |
Each player keeps its own six-axis history (dm_pad_motion), so a controller's gyro reaches its own npad and is cleared on disconnect or recenter. Rumble can go straight to a controller's own actuators (haptics_apple) instead of only through GameController. Six-axis handles use the SDK's style indices and device bytes. Covered by t_hid and t_haptics_apple.
Read the Steam Controller (2026) over USB-C, its Puck and Bluetooth straight from its HID reports (steam_input.h): buttons, both sticks with a radial deadzone (DM_STEAM_DEADZONE), trackpads, rear buttons, gyro and rumble, each controller as its own player. The Mac controller code moves out of front_mac.m into controllers_mac.m, which routes every controller model through one registry. Key and button maps (input_map.h) are shared with the launcher in the game's preference domain, so the mapping panel and the host agree; model-specific extras sit beside them. Covered by t_controllers_mac, t_input_map, t_pad_map, t_pad_motion and test_nsp_mac_app.py. Front-ends: Mac launchers share DM_KEYMAP and DM_PAD_MAP in the per-game preference domain; use the controller-specific choice contract in docs/frontends.md for extra inputs and model settings.
dm_switch2_front.attach now passes split: a Joy-Con that leaves its pair takes its player at once, or goes back into the pair. The Mac front end does this; the iOS one still had the one-argument callback, so DmGamepad.m no longer compiled. With DM_PAD_PRESS_TO_JOIN, iOS now waits for a button only for a new pad, not a split one, as on the Mac.
Adds Steam Controller (2026) support to the Mac host, and shares controller mappings between the launcher and the host.
Commits
host/hid: keep motion and rumble per player: each player keeps its own six-axis history (dm_pad_motion), rumble can go straight to a controller's own actuators (haptics_apple), and six-axis handles use the SDK's style indices and device bytes. Builds and passes the host suite on its own.host/input: support the Steam Controller (2026) on macOS:steam_input.h) for USB-C, the Puck and Bluetooth: buttons, both sticks with a 10% radial deadzone (DM_STEAM_DEADZONE), trackpads, rear buttons, gyro and rumble, each controller as its own player.front_mac.mintocontrollers_mac.m, one registry for every model. Main's wired Xbox One (GIP) and Xbox 360 (XUSB) pads, Switch Pro stick fallback, 8BitDo routes and GameController player lights are carried over; main's right-stick motion and its Controls menu stay as they are.pad_hid_mac.h) builds on main's per-device opening: a device the Steam adapter holds waits until it is free, pads are matched by their I/O Registry entry, and a model whose pad cannot be opened stays with GameController.input_map.h,DM_KEYMAP/DM_PAD_MAP) are shared with the launcher in the game's preference domain, so the mapping panel and the host agree (docs/frontends.md, docs/mac-controllers.md). The launcher applies the saved maps after main's Swift launcher has resolvedlauncher.json.ios/input: take the Switch 2 front's split flag on attach: the iOS front end takes thesplitargument commit 2 adds todm_switch2_front.attach, with the Mac's rule.Testing
Hardware (by the author, on a Steam Controller 2026): USB-C, Puck and Bluetooth all work; trackpads and rear buttons work; saved mappings persist. Earlier, @hrdkbhatnagar confirmed rumble and gyro in Tears of the Kingdom over USB-C, which led to the stick deadzone (report).
Gameplay (by the author, with the Steam Controller): LOLLIPOP CHAINSAW RePOP and The Legend of Zelda: Link's Awakening both appeared to work with the controller.
Both of these were on an earlier revision (head
3cf085260or before); the refreshes since have not been retested on hardware.Local, on this head (
dfec25504, main7d398f7a9; macOS, Apple Silicon):GAME=010015100B514000) on each commit.make -C dm/host/tests run, 90 commands, each run on its own): 88 pass, includingt_hid,t_haptics_apple,t_controllers_mac,t_pad_hid_mac,t_pad_gip,t_pad_xusb,t_pad_gip_mac,t_motion_pro,t_motion_pro_mac,t_input_map,t_pad_mapandt_pad_motion. The other two are main's:t_memstatalternates between pass and fail (its sources are main's), andt_cheatsdoes not link on main either (main'shle_os.cnow callsdm_thread_native_wait).t_controllers_mac,t_haptics_appleandt_pad_hid_macunder ASan/UBSan: pass, no reports.test_docs.py,test_game_profile.py,test_nsp_chain.py,test_nsp_mac_app.py,test_nsp_mac.py,test_launcher_settings.py,test_nsp_multi_program.py,test_bug_report.pyanddm/ios/tests/test_launcher_storage.pypass.test_env_switches.pyfails the same way on main (switches quoted in the docs but read nowhere). The symptom and patch indexes are current.dm/ios/tools/compile_check.py(270 files) andswiftc -typecheckof the iOS Swift sources pass. This is a source check, not an IPA or device run.Not run here: clang-tidy (no LLVM locally; CI runs it),
regress.py check --games(no Mac game builds on this machine), a physical iPhone.Known limits
Changes in this revision
Rebased on main
7d398f7a9, keeping the three commits. Main changed code this PR builds on, so its changes are carried over:pad_hid_mac.h): main now opens each raw HID pad on its own (1947c0df1), as this PR did. This PR uses main's version (opening, scheduling, closing and the Input Monitoring messages) and keeps only its own additions: matching by registry entry, the deferred list for devices the Steam Controller adapter holds (hidpad_available,hidpad_retry), and handing a model back to GameController when one of its pads cannot be opened. The fixtures follow main: a pad handed back to GameController stays open but unread, andt_pad_hid_macis main's plus thehidpad_availablestub.launcher.c): main moved saved choices into the Swift launcher (7cf637e1f), which resolveslauncher.json's rows only.DM_KEYMAPandDM_PAD_MAPstay in C: they are applied after it (saved_controls, with the same checks and order;DM_SAVED_CHOICES=0skips them and says so), and a value from the launch environment is added toDM_ENV_LAUNCH_KEYS, so the host keeps it fixed.docs/frontends.mdno longer mentionsDMSettings.cfdae4aa4) are set from the registry: a pad's player when it joins, and off when it leaves or waits to join. Original Joy-Cons keep their own HID-driven lights. The controller fixture checks this.Earlier revisions: on
ab44edaba, main's lazy Pro stick probe, XUSB pads and right-stick motion were carried over. On168e9e780, the PR was split into its commits, and the lint workflow change and the HMMA tests (already in #870) were removed.Front-ends: Mac launchers share
DM_KEYMAPandDM_PAD_MAPin the per-game preference domain; use the controller-specific choice contract indocs/frontends.mdfor extra inputs and model settings.