feat(input): controller gyro under Steam Input (Steam Controller, DualSense, Deck; Linux and Windows) #3045
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
6 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3045
Loading…
Reference in a new issue
No description provided.
Delete branch "sandymac/Longshot:feat/steam-controller-gyro"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
With Steam Input on, a game started from Steam gets
SDL_GAMECONTROLLER_IGNORE_DEVICES, so SDL opens only Steam'sstand-in pads, which have no sensors. Longshot's Motion controls then had no gyro, except the Steam Deck's own controls
(#2660, #2802). Each real controller still streams its state reports, motion included, to every reader of its HID
device. This PR turns the builder's Deck reader (
build_core::deck_imu) into one reader of controller familiesthat runs on Linux and Windows, and adds the Steam Controller (2026) and the DualSense / DualSense Edge.
Steam keeps the buttons, sticks, trackpads and the player's layout, and Longshot's own Motion page (sensitivity, invert,
deadzone) gets the gyro. Refs #2974.
Since #2822 the builder reads every pad for the game, so the reader lives there and its reading reaches the game in
the pads snapshot's trailer, as the Deck's did. The game opens no HID device, confined or not.
Read first:
builder/crates/build-core/src/hid_imu.rs(the families, the parsers and each family's input signature,then
Reader::poll, thenBackground), then the wire inbuild_core::pads(Request,snapshot) and its client ingame/crates/longshot-game/src/builder_link/pads.rs, thenmotion_pollinhost/pad_sdl.c.build_core::deck_imu→build_core::hid_imu. The reader holds thedevice choice, probing, live/stale motion and turning sensors on, and reaches the system only through its
Hidtrait: Linux's
Sysis the old hidraw code (uevent'sHID_IDnow gives the vendor and product), Windows'Sysuses cfgmgr32's device interface list and the HID class driver's ioctls on an overlapped handle, not SetupDi/HidD_*,
which Steam's overlay hooks in the processes it starts to hide the controllers Steam Input drives (PrimeRecomp's
approach, MIT, written here from it). No new crate. The reader runs on a thread of its own (
Background), startedat the first request that wants motion: a pads request only stores what the game wants and copies the newest
reading, so no device listing, feature report or slow controller can hold back a snapshot's buttons and sticks.
28de:1205): as onmain, its sensors turned on and its setting put back where thebuilder still owns it.
28de:1302–1305: cable, Bluetooth, both receivers): reports0x42/0x45/0x47atSDL 3.4's offsets and axes, with its own sensor clock (a stalled one is no reading, as SDL).
054c:0ce6,0df2):0x01on a cable,0x31over Bluetooth with its CRC-32 checked; SDL'sscale without the factory calibration (the filter learns the resting bias). Read only.
a Deck's setting put back), options (bit 0: the Steam Controller's sensors may be turned on) and the Steam Input pad
used last (
vendor << 16 | product, a hint). The snapshot's trailer (28 → 48 bytes) says which family was read, aserial that changes with the device read (a fresh filter), how long ago that controller's own buttons or sticks
moved, the device's id (its node's FNV-1a and the count of devices that node has had: the same while it stays
plugged in), and the wire id of the pad SDL opened on the same node (0 none).
game_builder_deck_imu→game_builder_hid_imu.drains them all each poll, and reads the one whose input signature (buttons, and each stick axis past 40%) changed
last. Steam's stand-in pads were not reliable for this: after controllers reconnect, SDL's ids for them drift out of
step (the pad named "DualSense Wireless Controller" reported
28de:1302), and a stand-in connected mid-game can comeunnamed (
28de:11ff). The stand-in pad used last is only a hint before anything has moved.IMU streams only while Steam's layout (or Steam's menus) use the gyro. When the controller being read has a frozen
sensor clock for 150 ms, the reader sends the one setting SDL's Triton driver sends for it,
SETTING_IMU_MODE= rawaccel | raw gyro (feature report 1, 64 bytes), at most every 3 s, never while motion arrives. Lizard mode and the rest
stay Steam's. Its receiver answers no settings request (
EPIPE), so who owns the setting later can't be read: thereader never writes it off (Steam sets it with each layout it applies).
HOS_STEAM_CONTROLLER_IMU_ON=0keeps thereader to reading.
(
steam_pads_without_valve), so a Steam Controller's gyro often comes through SDL. The reader keeps running then, andits controller is read over SDL's pad when its own buttons or sticks moved after the pad was last used
(
hid_imu_over_padinhost/hid_imu.h). The builder names the pad SDL opened on the reader's node (each open pad'spath hashed as the reader's node is, case blind on Windows), and a controller SDL reads the sensors of stays SDL's:
the reader's signature counts buttons SDL's pad doesn't (grips, trackpad clicks), so deciding by time would hand one
controller back and forth. A second controller of the same kind on another node is another controller.
host/steam_pads.h): a pad with Valve's virtual id28de:11ffwas taken for a real Valve pad and made motion only, so a Steam Controller connected mid-game lost itsbuttons.
setting down, and a second controller of the same kind, or one Linux gives a node another left (
/dev/hidrawN),starts unlearned.
pads::TARGET(#3249), so they reach the game'slongshot_log.txt.tests/test_deck_imu.py→tests/test_hid_imu.py(the game's side, andhost/hid_imu.h's device table against thebuilder's); the reader's own tests are build-core's unit tests on a fake
Hid: the parsers on real reports capturedfrom these controllers, the 14 scenarios of the C reader this started as,
main's Deck tests, a device that takes200 ms a feature report never holding a request back, and Steam taking a Steam Controller over before the end.
Testing
Tested: this PR's builder and game built with
from-sourceon each machine, started from Steam:aiming with all three, switching between them, the Steam Controller's grips and trackpad clicks while aiming (no
hand-over), a controller off and on again. With Steam Input off for the game (Properties → Controller), the
DualSense's gyro through SDL as on
main.game, the DualSense through SDL.
main's default (no sandbox): a Steam Controller and two DualSenses overBluetooth: each one's buttons and gyro aiming, switching between all three, reconnects, a second start with no
pipelines prepared again. With PlayStation controller support off in Steam's settings, the DualSense through SDL, switching
with the Steam Controller.
40aa3ab1(this PR onmain@f577a1ae); rebased ontomain@ca830e89since (#3044's pads changes: one wireversion up, the state's new fields kept), the tests below again, and at
77afed87each controller's gyro andswitching in game on all three machines again, beside #3044's new DualSense features.
main@67fda193as4444cedd: one conflict, ingpu/vk/switches.def(main'sHOS_STEP_SHOWNbesidethe new
HOS_STEAM_CONTROLLER_IMU*lines, all kept in order); the PR's own diff is unchanged (18 files, +3672−884). Then on Linux again: rustfmt,
ffi-gen --check,schema-gen --check, clippy-D warnings --no-depsonbuild-coreandlongshot-game(with dependencies,host-sysandbuild-assetsfail clippy onmain@67fda193too),
cargo test -p build-core -p longshot-game, and the Python checks below;mise run test-changed's 8 failedPython checks are 8 of the 15 that fail on
maintoo.HOS_SANDBOX=1, started from Steam, PlayStation controller support off (this PR's code, built at77afed87): the game confined in its AppContainer (the log'ssandbox:lines); a DualSense through the builder'sSDL: buttons and sticks as a gamepad (PS5 prompts), gyro aiming with the slingshot, the PS button opens Longshot's
menu.
0d352eb4(onmain@7bc53f84), Steam Input on: Steam DeckLCD with its own controls, the Steam Controller and a DualSense, and the Steam Machine with the Steam Controller and a
DualSense: gyro aiming with each, the Steam Controller's grips and trackpad clicks while aiming (no hand-over),
switching between them. Rebased since onto
main@b6330a5bas83dfa98b:deck_imu.rs(#3249's log target,carried into
hid_imu.rs),lib.rs(#3245's modules kept),input.md's tables and the session's fields (#3249'ssaidkept).ffi-gencan't run on thatmain(host/game_host.h's new declarations have no doc comments,#3164, #3208); the PR's
game.hlines are the ones it generated at0d352eb4. Rebased again ontomain@a0e0c720as
7c417748:input.md's table (main's new keyboard and mouse row kept); the PR's code unchanged. rustfmt and onelongshot-gametest (settings_now) fail onmain@a0e0c720too, in files this PR doesn't touch. Rebased since ontomain@5aa5989eas3afc328d(no conflict; BeanBot's@fixrebase in between,19907f20): the PR's diff unchanged,the same checks again with the same results.
cargo test -p build-core(hid_imu,pads: 48) on Windows and Linux,cargo test -p longshot-game(
builder_link: 43) on Linux; clippy-D warningson both crates, rustfmt,ffi-gen --check;tests/test_hid_imu.py,test_steam_pads.py,test_pad_motion_policy.py,test_builder_pads_route.py,test_pads_after_menu.py,test_gyro_rearm.py,test_switch_table.py.Still to test:
3afc328d(the same code as83dfa98b), Steam Input on: a Steam Controller's gyro aiming with its grips and trackpad clicks pressed(no hand-over), a DualSense picked up and back (by hand; asked on the PR and in the team room)
main(Test Farm: @Beanstalk steamdeck, Motion controls aiming with the built-ingyro)
HOS_SANDBOX=1and a DualSense under Steam Input (PlayStation controller support on): the confinedgame's controllers may come under Steam's Desktop Layout there (the builder is the process Steam started, the game's
window is not), on
mainas here; the gyro path itself is the builder's either way (by hand)Measurements
Verdict: the reader costs a pads request nothing measurable: its device work runs on its own thread. The kill
switches ship on:
HOS_DECK_IMU(as before),HOS_STEAM_CONTROLLER_IMU,HOS_STEAM_CONTROLLER_IMU_ON,HOS_DUALSENSE_IMU.What a pads request waits on for motion (
Background::motion), and the reader's own poll on its thread, every 4 ms for20 s, all three families wanted (a scratch program over
build_core::hid_imu, release build;hid_imu.rsis the sameat 40aa3ab1 and
77afed87). On the Steam Deck LCD its own controls were read (99% of polls with a reading) with the gamerunning; on Windows 11 no controller was connected.
main's Deck reader polled on the request itself (not measuredthere). Times in ms: median / p99 / p99.9 / max.
ca830e8977afed87Risks
for its gyro features, Steam sets it again with each layout, and the reader never writes it off.
HOS_STEAM_CONTROLLER_IMU_ON=0avoids any write.each controller and in the game on the Deck, the Steam Machine and Windows.
main's behaviour. Saves,longshot_options.iniand the caches areuntouched.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (mise run test --container, CI'simage, under Docker on the Windows PC's WSL, on this PR @
77afed87and onmain@ca830e89: 870 passed, 15 failedor timed out, 13 skipped on both, the same 15 checks on both, none of them reading a file this PR changes: renderer
and shader fixtures,
test_builder_files_linux,test_crash_record,test_utf8_paths,test_run_all_junit, andtest_lifter/test_lifter_semanticstiming out on a laptop. Every check that reads this PR's files passes:test_hid_imu,test_steam_pads,test_pad_motion_policy,test_builder_pads_route,test_pads_after_menu,test_gyro_rearm,test_switch_table. clippy and rustfmt, whichtest_lifterruns, were run on build-core andlongshot-game by hand.)
main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.(Report layouts from SDL's zlib-licensed drivers, the Windows transport after PrimeRecomp's MIT approach, both
written here in our own code;
game/game.hregenerated by ffi-gen.)When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.Ready to merge
main, measured again or a comment says why the numbers still hold.Assisted-by: Claude Opus 5.5 (Claude Code)
Tested in game: SteamOS on a Steam Machine (RADV NAVI33, Mesa 26.2), Steam Controller (2026) through its receiver, started from Steam with Steam Input on and a layout without gyro: the reader found the controller, turned its sensors on (Steam had them off), and gyro aiming of the slingshot, bow and hookshot works well (directions and sensitivity right); buttons and sticks still through Steam's layout.
WIP: feat(input): Steam Controller (2026) gyro under Steam Inputto WIP: feat(input): controller gyro under Steam Input (Steam Controller, DualSense, Deck; Linux and Windows)Grew from Linux + Steam Controller to one shared reader over a small transport (Linux and Windows), with the DualSense as a third family. The controller read is now the one whose own buttons or sticks moved last (Steam's stand-in pad ids drift after reconnects). Tested in the game on a Steam Deck with its own controls, a Steam Controller and a DualSense, switching between all three; Windows tested outside the game so far.
Tested in the game on Windows 11: Steam Controller and DualSense over Bluetooth under Steam Input, both aim, switching between them works, the DualSense survives reconnects. Two fixes on the way (
dd297c59,9669237d): the reader runs beside a pad SDL reads the gyro of (Windows' SDL opens a Bluetooth Steam Controller itself), chosen by recency of input, and one controller read by both stays SDL's.Rechecked on the Steam Deck LCD with
9669237d: its own controls, a Steam Controller and a DualSense (both Bluetooth), motion with each and switching between all three as before.Full suite in CI's container (mise run test --container) on this branch and on main: the same 123 checks fail or time out on both, none from this PR; every check reading its files passes.
Heads-up: #2822 moved controller reading into the builder (the game is sandboxed and opens no hidraw), so this PR's C reader in host/ no longer fits. I'm porting it onto build_core: the Deck reader in build_core::deck_imu generalized to the Steam Controller (2026) and DualSense, a Windows backend for its Hid trait, and the pads request and snapshot trailer extended for the families wanted and the one read. The game-side choice in pad_sdl.c stays. It stays WIP until the port is retested on a Steam Machine, a Steam Deck and Windows.
9669237ddfa6b24b7148Ported onto the builder-side pads of #2822 and rebased onto main @
7c3c16f0(heada6b24b71): the C reader in host/ is gone; build_core::deck_imu became build_core::hid_imu (Deck, Steam Controller 2026, DualSense; Linux hidraw and a Windows cfgmgr32/ioctl transport), the pads wire goes to version 3 (families wanted, options, the stand-in hint; a 40-byte trailer with the family, a serial and the input's age), and pad_sdl.c keeps its choice between SDL's gyro and the reader's. Retested in game on a Steam Deck LCD, a Steam Machine and Windows 11 with all three controllers, and the full container suite matches main's (the same 20 failures on both). Description rewritten for the new design.WIP: feat(input): controller gyro under Steam Input (Steam Controller, DualSense, Deck; Linux and Windows)to feat(input): controller gyro under Steam Input (Steam Controller, DualSense, Deck; Linux and Windows)@review
Recommendation: Request changes. The new reader can select the wrong controller, reuse another controller’s gyro bias, and stall the shared pad poll while waiting for a device. Its cleanup can also turn off sensors that Steam has since started using.
The change adds gyro support behind Steam Input for DualSense and Steam Controller devices and preserves the Deck reader. The reported game runs show the feature working, but controller identity, device ownership and input latency need correction.
Blocking (2): must change before merging.
builder/crates/build-core/src/hid_imu.rs:1158: A feature report waits on the pads request thread, delaying the entire input snapshot when a controller does not answer promptly. (more on the line) Do: Move feature-report operations off the pads request path and publish their results asynchronously, keeping the request and cancellation buffers alive until completion.builder/crates/build-core/src/hid_imu.rs:695: Cleanup unconditionally disables a Steam Controller after this reader has enabled it, even if Steam subsequently began using its gyro. (more on the line) Do: Coordinate ownership with Steam or avoid writing a destructive off value when the current owner cannot be determined; add a test for Steam taking over before cleanup.Should fix (2): not blocking, but worth doing before merging.
host/pad_sdl.c:352: Matching only the family treats two different controllers as the same device and prevents the newer HID controller from taking over. (more on the line) Do: Match actual device identity across SDL and HID, or use a selection scheme that distinguishes two controllers of the same family; cover that case with a behavioral test.host/pad_sdl.c:409: The saved gyro bias is keyed by family rather than controller, so switching between devices applies one device's calibration to another. (more on the line) Do: Keep bias by stable controller identity, or start with an unlearned bias when the actual device changes.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
@fixdoes its part first: Move device discovery and feature operations off the request path and bound the work performed per poll.)@fixcan do L1, L2, L3, L4 and L6.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes: the author reports DualSense gyro aiming working under Steam Input on SteamOS and Windows, where main had no gyro. The runs do not quantify the added polling cost or input latency.
Other systems: The reader also runs alongside SDL-owned controllers and affects the shared pads snapshot on Windows and Linux. Direct SDL motion, Deck OLED, Windows sandbox mode and polling latency remain unverified in the reported runs.
Switches: HOS_DECK_IMU remains on but now runs beside SDL motion pads. HOS_STEAM_CONTROLLER_IMU, HOS_STEAM_CONTROLLER_IMU_ON and HOS_DUALSENSE_IMU are added on by default, with switch-table entries. The defaults enable the tested feature, but the sensor-write and polling issues need fixing.
Reviewed:
a6b24b7148against7c3c16f0a7: Read the repository rules, PR template, standards, commit and diff, HID reader and host selection paths; inspected the pads wire changes, tests, documentation and generated header. The large test and pads files were skimmed in part. docs/review-checklist.md and the adjacent Tooling checkout were unavailable.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no project code, tests or builds were run. CI was still running in the supplied status.
Overlaps and merge order: Not checked; network access was unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
@ -0,0 +692,4 @@&& read_setting(&self.hid, &mut w.dev) == Some(set){send_setting(&self.hid, &mut w.dev, ID_SET_SETTINGS_VALUES, saved);}L4 (blocking): Cleanup unconditionally disables a Steam Controller after this reader has enabled it, even if Steam subsequently began using its gyro.
When: Start with a layout that leaves the gyro off, so the reader enables it; then switch to a Steam layout that uses gyro and turn Longshot Motion off or exit. The cleanup sends mode zero and interrupts Steam's now-active gyro stream.
Do: Coordinate ownership with Steam or avoid writing a destructive off value when the current owner cannot be determined; add a test for Steam taking over before cleanup.
@ -0,0 +1155,4 @@if GetLastError() != ERROR_IO_PENDING {return None;}if WaitForSingleObject(ov.hEvent, FEATURE_MS) != WAIT_OBJECT_0 {L3 (blocking): A feature report waits on the pads request thread, delaying the entire input snapshot when a controller does not answer promptly.
When: On Windows, a Steam Controller with stalled sensor reports causes triton_enable to issue this request; an unanswered feature request waits 50 ms before cancellation, and retries occur every three seconds. During each wait the shared pad snapshot, including buttons and sticks, cannot be returned.
Do: Move feature-report operations off the pads request path and publish their results asynchronously, keeping the request and cancellation buffers alive until completion.
@ -296,0 +349,4 @@int64_t hid_input_ns = 0;const int hid_ok = hid_poll(want, prefer, now, hid_a, hid_g, &hid_family, &hid_serial, &hid_input_ns);/* (the reader's controller over SDL's pad only when its own input is the newer: host/hid_imu.h) */const int hid_same = pick >= 0 && hid_family >= 0 &&L1 (should fix): Matching only the family treats two different controllers as the same device and prevents the newer HID controller from taking over.
When: With one Steam Controller opened by SDL and a second Steam Controller read through HID, moving the second makes it the reader's choice, but both have the Triton family. hid_same remains true and the game continues aiming with the first controller.
Do: Match actual device identity across SDL and HID, or use a selection scheme that distinguishes two controllers of the same family; cover that case with a behavioral test.
@ -346,2 +406,4 @@if (src >= 0 && pads[src].has_bias)memcpy(motion.bias, pads[src].bias, sizeof motion.bias), motion.learned_t = pads[src].bias_t;motion_hid_family = src == MOTION_SRC_HID ? hid_family : -1;if (motion_hid_family >= 0 && motion_hid_family < HID_IMU_FAMILIES && motion_hid_has_bias[motion_hid_family])L2 (should fix): The saved gyro bias is keyed by family rather than controller, so switching between devices applies one device's calibration to another.
When: After a DualSense has learned its resting bias, switching to a second DualSense restores the first controller's bias even though the reader supplies a new serial. A different sensor offset then produces aim drift until the filter relearns it.
Do: Keep bias by stable controller identity, or start with an unlearned bias when the actual device changes.
a6b24b714877afed87bdThanks for the review. Pushed
77afed87(rebased ontomain@ca830e89, squashed to one commit). Per finding:L3 (blocking), a feature report on the pads request: fixed. The reader runs on a thread of its own
(
hid_imu::Background, started at the first request that wants motion, alive for the builder's life). A pads requeststores what the game wants and copies the newest reading; the input's age is worked out from the absolute time the
reader saw it, at the reply. Device listing, probing, the Deck's settings and the Steam Controller's IMU-on all happen
on that thread. Test:
a_slow_device_never_holds_a_request_back(a fake Deck whose feature reports take 200 ms each:every request returns under 100 ms, the reading still arrives, the end puts the setting back). The session's end waits
up to 500 ms for the reader to stop, so a Deck's setting goes back before the builder may exit.
L4 (blocking), the off-write at cleanup: fixed by never writing it. The receiver answers no settings request
(
EPIPE), so who owns the IMU mode later can't be told; the reader now never writes a Steam Controller's IMU off, at theend or when its family stops being wanted. Steam sets that setting with each layout it applies. Test:
a_steam_controller_steam_took_over_is_not_turned_off. The Deck is unchanged: its setting is read first and put backonly where the builder still owns it.
L1 (should fix), the same family as SDL's pad: kept, with the reason in the code and a test. I tried the time-based
rule (the reader's controller of the pad's own kind wins when its input is newer than the pad's last use by more than
250 ms). On Windows with one Steam Controller, the log showed motion handed back and forth between SDL's pad and the
reader: the reader's signature counts the grips and trackpad clicks, SDL's pad doesn't, so a grip press read as another
controller picked up, and the next face button handed it back. The case it was for doesn't come up: the builder's SDL
opens every Valve pad beside Steam's stand-ins (
steam_pads_without_valve), so a second Steam Controller is an SDL padtoo, and SDL's own last use picks between them. The DualSense, which SDL doesn't open under Steam Input, has no SDL pad
to compete with.
hid_imu_over_pad's comment says this, andtests/test_hid_imu.pypins it (a grip pressed 2 s laterstays SDL's). Tested in game with one Steam Controller and two DualSenses on Windows, and grips and trackpad clicks
while aiming on the Deck and Windows: no hand-over.
L2 (should fix), the bias by family: fixed. The trailer carries the physical device's stable id (FNV-1a of its
path, never 0);
pad_sdl.ckeeps the learned bias by device id (8 entries, the oldest replaced), and an unknown devicestarts unlearned. The serial still decides a fresh filter.
L5 (testing): run. Steam Input off for the game on the Steam Deck and the Steam Machine, and PlayStation controller
support off on Windows: the DualSense's gyro through SDL as on
main, switching with the Steam Controller. The DeckOLED stays with the Test Farm (Still to test).
L6 (measure): measured. A request's wait for motion and the reader's own poll, every 4 ms for 20 s (Measurements):
on the Deck with its controls read and the game running, the request's median 0.001 ms, p99.9 0.003 ms, max 0.099 ms;
the reader's thread median 0.014 ms, max 5.3 ms, none of it on the request. On Windows (no controller connected) the
request's max is 0.088 ms; the 2 ms device list every 2 s is on the reader's thread. No frame-time comparison: the
request path no longer touches a device, so there is nothing for frame pacing to see.
Thanks for this, reading the real controller next to Steam Input is exactly what was missing for the gyro.
Would you consider carrying haptics over the same path, in this PR or a follow-up?
With Steam Input on, the game's rumble goes to Steam's stand-in pad, so a Steam Controller (2026) only gets what Steam makes of it. Its grips can play HD haptics (Longshot already does this through RenHDrum), but only by writing to the real device, which is the same device your reader already finds and opens on Linux (hidraw) and Windows (cfgmgr32 + HID ioctls, avoiding the SetupDi/HidD calls Steam's overlay hooks).
What I have in mind:
HOS_STEAM_CONTROLLER_HAPTICS).If it's out of scope here, a note on where the device handle could be exposed would already help someone pick it up. Happy to test on a Steam Controller (2026) over cable and the puck on Windows and Linux
One more thing if haptics ever go through this path: Steam's rumble intensity setting only applies to what goes through its stand-in pad. Anything written straight to the controller (RenHDrum's grip stream, for one) ignores it, so the grips stay at full strength even when the player turned vibration down in Steam.
Steam keeps that setting in plain text files, so it can be followed without touching Steam:
<Steam>/steamapps/common/Steam Controller Configs/<account id>/config/preferences_<serial>.vdf, key"rumble_intensity"inside"ControllerPersonalization".<Steam>/userdata/<account id>/config/localconfig.vdf, key"SteamControllerRumbleIntensityV2"under"UserLocalConfigStore" > "apps" > "<app id>". Missing or 0 means the game follows the general setting.Values (smaller is stronger): very high 60, high 100, medium-high 200, medium 0 (default; 320 when set in a game's own settings), medium-low 1000, low 8000, very low 16000.
Finding the Steam folder:
HKCU\Software\Valve\SteamSteamPath; the account isHKCU\Software\Valve\Steam\ActiveProcessActiveUser.~/.local/share/Steam(or~/.steam/steam).STEAM_COMPAT_CLIENT_INSTALL_PATH. When no account is named, the one whoselocalconfig.vdfchanged last works.Re-reading the files every couple of seconds (only when their write time changes) lets the player change it with the game open. I'm doing exactly this in a small DLL for another game and it behaves well on Windows; the Proton path is new.
@iafx Thanks for the detailed write-up, and for the notes on Steam's rumble strength setting.
Haptics would widen this PR beyond reading motion. It has already been reworked heavily several times to keep up with how fast
mainmoves, so I'd like to get it merged as it is before working on the next improvements.Could you open an issue with the idea, both the grip haptics and following Steam's rumble strength? Please mention me (@sandymac) in it, so I can track it more easily later. The device discovery a haptics path would share is in
build_core::hid_imu(builder/crates/build-core/src/hid_imu.rs): theHidtrait with its Linux (hidraw) and Windows (cfgmgr32 plus HID ioctls) implementations, and the reader's own thread,Background.77afed87bd4444ceddbaRebased onto
main@67fda193as4444cedd; it no longer merged. One conflict, ingpu/vk/switches.def: main's newHOS_STEP_SHOWNline sits beside this PR'sHOS_STEAM_CONTROLLER_IMU*lines, and all three are kept in order. The PR's own diff is otherwise unchanged (18 files, +3672 −884).Run again on Linux:
ffi-gen --check,schema-gen --check, clippy-D warnings --no-depsonbuild-coreandlongshot-game,cargo test -p build-core -p longshot-game, and the pad checks (test_hid_imu,test_steam_pads,test_builder_pads_route,test_pads_after_menu,test_switch_table,test_switches_removed);maintoo: clippy with dependencies, inhost-sys'ssettings_abi.rsand inbuild-assets.Ready for a re-review.
@Beanstalk steamdeck: Motion controls on, aim the slingshot with the Steam Deck OLED's built-in gyro; it should follow the Deck's tilt as on main.
@sandymac only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for4444ced, and the PR has changed since (83dfa98), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.@review
Recommendation: Approve. The feature works in the reported Steam Input tests, but controller identity still has gaps: same-family HID controllers cannot take over from an SDL pad, and Linux can reuse a device node for a different controller’s saved bias. The Deck OLED run and CI are also outstanding. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
Adds gyro input behind Steam Input for Steam Controller and DualSense devices on Linux and Windows, while moving HID work to a background thread. It improves controller support at the cost of additional device-selection and calibration state.
Should fix (2): not blocking, but worth doing before merging.
host/pad_sdl.c:352: Matching only the family treats two different controllers as the same device and prevents the newer HID controller from taking over. When: With one Steam Controller opened by SDL and a second Steam Controller read through HID, moving the second makes it the reader's choice, but both have the Triton family. hid_same remains true and the game continues aiming with the first controller. Do: Match actual device identity across SDL and HID, or use a selection scheme that distinguishes two controllers of the same family; cover that case with a behavioral test.host/pad_sdl.c:409: The device key hashes a reusable Linux hidraw node rather than identifying the physical controller. When: After one controller’s bias is saved, it disconnects and another controller is assigned the same /dev/hidrawN node. The new controller receives the old controller’s bias. Do: Use a physical-device identity where available, and avoid restoring a saved bias when the identity cannot distinguish devices.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1 and L2.Since the last review (on
a6b24b7148)Resolved: L3 (A feature report waits on the pads request thread, delaying the entire input snapshot when…); L4 (Cleanup unconditionally disables a Steam Controller after this reader has enabled it, even…); L6 (The added work on the pads polling path has no measured input or frame-time cost.)
Still open: L1 (Matching only the family treats two different controllers as the same device and prevents…); L2 (The device key hashes a reusable Linux hidraw node rather than identifying the physical co…); L5 (The Steam Deck OLED built-in gyro path still needs its in-game run.)
Checks: Still running: 10 checks.
Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes: the author reports gyro aiming and controller switching in game on Steam Deck LCD, Steam Machine and Windows. The request-side motion call measured a 0.003 ms p99.9 and 0.099 ms maximum on Deck; these are not before-and-after frame-time measurements.
Other systems: The reported runs cover Linux, Windows, Steam Input and direct SDL motion. Deck OLED and Windows sandbox with DualSense under Steam Input remain untested; CI is still running.
Switches: HOS_STEAM_CONTROLLER_IMU, HOS_STEAM_CONTROLLER_IMU_ON and HOS_DUALSENSE_IMU are added, default on; HOS_DECK_IMU remains on by default. The defaults enable the feature, with IMU_ON allowing the Steam Controller write to be disabled.
Reviewed:
4444ceddbaagainst67fda193c3: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the supplied range diff and the relevant controller selection, bias and background-reader code. The full changed files, remaining project standards and generated files were not read in full; the review checklist file was absent.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run project code were executed. The author reports in-game tests on Deck LCD, Steam Machine and Windows, plus game-free checks; CI is still running.
Overlaps and merge order: Not checked.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
4444ceddba83dfa98b92Thanks for the re-review. Pushed
83dfa98b, rebased ontomain@b6330a5b: the earlier commit, then one for L1 and L2.L1 (should fix), the same family as SDL's pad: fixed, by node. The builder now names the pad SDL opened on the HID node the reader reads: it hashes each open pad's path (
SDL_GetGamepadPath) as it hashes the reader's node (hid_imu::node_id; case blind on Windows, where cfgmgr32 and SDL's hidapi spell one path in different cases), and puts that pad's wire id in the motion trailer (48 bytes now; 0 none). The game treats the reader's controller as SDL's only when that pad is one whose sensors SDL reads (pad_sdl.c:hid_sdl); the family no longer decides. So a second Steam Controller on another node is another controller, picked up by its own input like a DualSense, while one controller that SDL and the reader both read still doesn't take turns with itself (its grips and trackpad clicks, which SDL's pad doesn't count). The builder logs which it is when that changes (pads: motion: ... is a pad SDL reads too/... is no pad SDL opened), and since #3249 those lines are in the game's log. Tests:the_hid_motion_names_the_pad_sdl_opened_on_its_node(a pad on another node: none; the pad on its node: its id), the trailer's tests on both sides (a pad not among the pads is refused), andtests/test_hid_imu.py(no match by family left).L2 (should fix), a reused hidraw node: fixed. The device id is now the node's id hashed with the count of devices that node has had (
hid_imu::device_id(path, plugged)). The reader keeps the count while the node is there and drops it when the device is gone (a read that says so, or a look that no longer finds the node), so the next controller on that node gets another id and starts unlearned, while one controller keeps its id across Motion controls off and on. Test:another_controller_on_a_node_reused_is_another_device(unplugged and replaced on the same node, with and without a read that says so).Tested in game at
0d352eb4(the same code onmain@7bc53f84), Steam Input on: the Steam Deck LCD with its own controls, the Steam Controller and a DualSense, and the Steam Machine with the Steam Controller and a DualSense: gyro aiming with each, the Steam Controller's grips and trackpad clicks while aiming (no hand-over), switching between them.Checks on Linux: rustfmt, clippy
-D warnings --no-deps,cargo test -p build-core -p longshot-game(262, 232), the pad checks (test_hid_imu,test_steam_pads,test_builder_pads_route,test_pads_after_menu,test_pad_motion_policy,test_gyro_rearm,test_switch_table,test_sdl_pad_diagnostics);build-core's on Windows too.ffi-gen --checkfails onmain@b6330a5bitself (host/game_host.h:rx_menu_openandrx_display_refresh_mhzhave no doc comment, from #3208 and #3164), so it can't run here; this PR'sgame.hlines are the ones it generated at0d352eb4, unchanged by the rebase.Wanted: a Windows run. I can't test Windows for about 12 hours. Could someone with a Steam Controller (2026) and/or a DualSense on Windows build this PR and play with Steam Input on (started from Steam, Motion controls on)?
longshot_log.txthas forpads: motion:(which controller, and whether it "is a pad SDL reads too").@review
Recommendation: Request changes. It conflicts with its base branch: bring it up to date (
@fixor@rebasetry first). (L7) The node-based pad matching addresses the controller handover issue, but a replacement controller can still inherit a previous controller’s gyro bias when the swap happens while Motion controls are off. The Steam Deck OLED run also remains outstanding.This adds gyro input behind Steam Input for supported controllers on Linux and Windows, with device work moved off the pads request thread. It improves controller coverage at the cost of a platform-specific HID reader and device-selection logic.
Blocking (1): must change before merging.
@fixor@rebasetry first). (for the author)Should fix (1): not blocking, but worth doing before merging.
host/pad_sdl.c:409: A replacement on a reused node can still receive the previous controller’s device ID when the swap occurs while the reader is stopped. When: Turn Motion controls off, unplug a controller, connect another that receives the same /dev/hidrawN, then turn Motion back on. The retained plugged entry supplies the old count, so the game restores the first controller’s learned bias. Do: Track device removal while motion is stopped, or use a physical-device identity that distinguishes the replacement while preserving the ID for a controller that remains connected.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L2.Since the last review (on
4444ceddba)Resolved: L1 (Matching only the family treats two different controllers as the same device and prevents…)
Still open: L2 (A replacement on a reused node can still receive the previous controller’s device ID when…); L5 (The Steam Deck OLED built-in gyro path still needs its in-game run.)
New: L7 (It conflicts with its base branch: bring it up to date (
@fixor@rebasetry first).)Checks: Still running: 11 checks.
Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes. The author reports gyro aiming and controller switching in game on Steam Deck LCD, Steam Machine and Windows. The reported request motion-call time on Deck was 0.001 ms median and 0.003 ms p99.9; those numbers are not a before-and-after frame-time comparison.
Other systems: The reader affects Linux and Windows HID devices, SDL sensor selection and the builder-game pads wire. Linux switching was retested after the node-matching fix; the corresponding Windows run and the Deck OLED built-in gyro run remain outstanding. CI is still running.
Switches: HOS_DECK_IMU remains on by default. HOS_STEAM_CONTROLLER_IMU, HOS_STEAM_CONTROLLER_IMU_ON and HOS_DUALSENSE_IMU default on; the IMU_ON switch permits the Steam Controller sensor setting write. The defaults enable the feature tested by the author, with opt-outs documented.
Reviewed:
83dfa98b92againstb6330a5b0b: Read AGENTS.md, CONTRIBUTING.md and the pull request template in full. Read the fix diff and the relevant reader, background polling, snapshot matching and motion-selection code; the remaining changed files and tests were skimmed, not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run project code were executed. Author-reported Linux and Windows runs and checks are described in the pull request; the OLED run and current CI remain outstanding.
Overlaps and merge order: No overlapping pull request identified from the supplied material.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
83dfa98b927c4177481eRebased onto
main@a0e0c720as7c417748; it no longer merged. One conflict, indocs/dev/reference/input.md's table: main's rewritten keyboard and mouse row kept beside this PR's two rows. The PR's code is unchanged (the same diff as83dfa98b).Run again on Linux: clippy
-D warnings --no-depsonbuild-coreandlongshot-game,cargo test -p build-core(all pass), and the pad checks (test_hid_imu,test_steam_pads,test_builder_pads_route,test_pads_after_menu,test_pad_motion_policy,test_gyro_rearm,test_switch_table,test_sdl_pad_diagnostics: pass). Failing onmain@a0e0c720too, in files this PR doesn't touch: rustfmt (gamecube.rs,devices/tests.rsand others),longshot-game'ssettings_now::tests::a_file_of_every_frozen_key_is_read_and_written_back_byte_identical, andffi-gen(host/game_host.h'srx_menu_openhas no doc comment).The Windows run asked for above is still wanted, on this head.
@review
Recommendation: Approve. The controller gyro feature has been demonstrated in game, but the Steam Deck OLED built-in gyro run is still outstanding. A controller swapped while motion reading is stopped can also inherit the previous controller’s learned bias. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
Adds builder-side gyro reading behind Steam Input on Linux and Windows, with device selection and per-device bias. It moves device work off the pads request thread, at the cost of a more complex reader and controller selection path.
Should fix (1): not blocking, but worth doing before merging.
host/pad_sdl.c:409: A replacement on a reused node can still receive the previous controller’s device ID when the swap occurs while the reader is stopped. When: Turn Motion controls off, unplug a controller, connect another that receives the same /dev/hidrawN, then turn Motion back on. The retained plugged entry supplies the old count, so the game restores the first controller’s learned bias. Do: Track device removal while motion is stopped, or use a physical-device identity that distinguishes the replacement while preserving the ID for a controller that remains connected.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L2.Since the last review (on
83dfa98b92)Resolved: L7 (It conflicts with its base branch: bring it up to date (
@fixor@rebasetry first).)Still open: L2 (A replacement on a reused node can still receive the previous controller’s device ID when…); L5 (The Steam Deck OLED built-in gyro path still needs its in-game run.)
Checks: Still running: 11 checks.
Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes: the author reports gyro aiming and controller switching in game on Steam Deck LCD, Steam Machine and Windows. Request motion-call measurements on Deck were 0.001 ms median and 0.099 ms maximum; they do not compare frame times against main.
Other systems: The reader affects Linux and Windows controller discovery, Steam Input, SDL sensor selection and the Deck’s built-in controls. Linux in-game testing covers the revised node matching; the revised Windows path and Deck OLED run remain outstanding.
Switches: HOS_DECK_IMU remains enabled by default. HOS_STEAM_CONTROLLER_IMU, HOS_STEAM_CONTROLLER_IMU_ON and HOS_DUALSENSE_IMU default to enabled; the reported controller runs support those defaults, with the remaining hardware checks noted.
Reviewed:
7c4177481eagainsta0e0c72073: Read the repository rules and PR template, ledger-related reader and bias code, and the input documentation diffs. Skimmed the remaining change and recorded runs; the full changed code and tests were not reread.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run project code were executed. The author reports passing relevant checks on the head; CI is still running.
Overlaps and merge order: none found
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@fix
7c4177481e19907f20c7Recommendation: Approve. The gyro feature works in the reported Linux and Windows runs, but the Steam Deck OLED built-in gyro run remains outstanding. A controller replaced while motion reading is stopped can also inherit the previous controller’s learned bias. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
19907f20c7. I rebased it ontomain(14f452f810).Not done
Nothing was built or run: the checks run again on the new head.
The builder reads gyro data from supported controllers alongside Steam Input and passes it to the game without doing device work on the pads request thread. It adds controller selection, device identity and platform transport complexity.
Should fix (1): not blocking, but worth doing before merging.
host/pad_sdl.c:409: A replacement on a reused node can still receive the previous controller’s device ID when the swap occurs while the reader is stopped. When: Turn Motion controls off, unplug a controller, connect another that receives the same /dev/hidrawN, then turn Motion back on. The retained plugged entry supplies the old count, so the game restores the first controller’s learned bias. Do: Track device removal while motion is stopped, or use a physical-device identity that distinguishes the replacement while preserving the ID for a controller that remains connected.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L2.Checks: they run again on this head; a failure shows on the pull request.
Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes. The author reports successful in-game gyro aiming and controller switching on Steam Deck LCD, Steam Machine and Windows. Request-side motion calls measured 0.002 ms p99 on the Deck and Windows; there is no comparable baseline timing.
Other systems: The reader affects Linux and Windows controller discovery, Steam Input, SDL sensor selection and the Deck’s sensor setting. Reported runs cover several combinations; the OLED built-in gyro and the latest Windows controller-selection changes remain untested in game.
Switches: HOS_DECK_IMU remains on by default and now uses the shared reader. HOS_STEAM_CONTROLLER_IMU, HOS_STEAM_CONTROLLER_IMU_ON and HOS_DUALSENSE_IMU are added, all on by default; the IMU_ON switch permits the Steam Controller sensor write. These defaults support the feature and have kill switches.
Reviewed:
19907f20c7against14f452f810: Read the repository rules, the reader’s stop, device identity and background paths, the game’s bias handling, and the switch diff. Skimmed the changed-file summary and reported runs; the full changed code and tests were not reread in this check.; nothing run (a code review).Checked and fine:
Testing: No tests were run. The author reports in-game testing on Steam Deck LCD, Steam Machine and Windows, plus build-core and pad checks; CI has not yet run on the head.
Overlaps and merge order: None found in the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
19907f20c73afc328d09Rebased onto
main@5aa5989eas3afc328d: the forge said it no longer merged after BeanBot's@fixrebase (19907f20, on14f452f8). No conflict, and the PR's diff is unchanged.Run again:
cargo test -p build-core(hid_imu,pads: 48) on Windows; on Linux clippy-D warnings --no-deps,cargo test -p build-core(262) and the pad checks pass. Failing onmain@5aa5989etoo, in files this PR doesn't touch: rustfmt,longshot-game'ssettings_now::…byte_identical, andffi-gen(host/game_host.h'srx_menu_openhas no doc comment).L2's remaining case (a controller swapped onto the same hidraw node while Motion controls is off) is still open; I'll follow up on it after the Windows run.