[PR #4030] [MERGED] Controller toggle-sneak comes back after a screen closes #5368

Closed
opened 2026-11-03 05:12:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4030
Author: @d3grando
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix-3061-pad


📝 Commits (2)

  • a8b5151 Controller toggle-sneak comes back after a screen closes
  • 3e536cb Merge origin/main into fix-3061-pad

📊 Changes

3 files changed (+102 additions, -11 deletions)

View changed files

📝 crates/horizon-client-input/src/keymapping.rs (+89 -4)
📝 crates/horizon-client/src/game/pad.rs (+10 -5)
📝 docs/controllers.md (+3 -2)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally.

What and why

With a controller, toggling sneak with the stick click and then opening the inventory (or any screen) left you standing after the screen closed. Toggle crouch on the keyboard brings sneaking back.

Cause. The pad's toggle-sneak (game/pad.rs) faked a toggle on top of the hold-mode sneak mapping. It sent a Shift press when you weren't sneaking and a Shift release when you were. The sneak ToggleKeyMapping therefore treated it as a held key. Gui.setScreen → KeyMapping.releaseAll released it like a held key and didn't remember it, so restoreToggleStatesOnScreenClosed had nothing to restore.

Fix. ToggleKeys::pad_toggle (horizon-client-input/src/keymapping.rs) flips the sneak mapping the way ToggleKeyMapping.setDown(true) does with its option on, and marks the mapping as toggled by the pad. While that mark is set, the mapping acts as a toggle mapping with needsToggle true:

  • opening a screen releases it and remembers it (release);
  • closing the screen restores it (shouldRestoreStateOnScreenClosed);
  • a keyboard Shift release behind the screen (a shift-click in the inventory) doesn't drop it.

The mark clears when sneaking is toggled back up. A respawn keeps it only while a restore is pending: vanilla's LocalPlayer.respawn → resetToggleKeys runs before the death screen closes, so the option's toggle comes back after death too. Keyboard hold-to-sneak is unchanged: a held Shift is still released by a screen and not restored. Every stick click now reaches the key handlers as a press, as a toggle-crouch key press does, so the click that toggles sneaking off also wakes you from a bed (before, only the click that toggled it on did). docs/controllers.md now says how pad toggle-sneak behaves around screens.

Part of #3061 (the controller item; the elytra sound and shield banners are already fixed, and the tab-list heads match vanilla).

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Controllers are Horizon-only. The pad's toggle now follows vanilla's toggle crouch (checked with javap on the 26.3 client.jar):

  • ToggleKeyMapping.setDown, release, shouldRestoreStateOnScreenClosed and reset;
  • KeyMapping.releaseAll, restoreToggleStatesOnScreenClosed and resetToggleKeys;
  • Gui.setScreen, which calls releaseAll when a screen opens and restoreToggleStatesOnScreenClosed when it closes in a level;
  • DeathScreen: LocalPlayer.respawn runs before setScreen(null).

No parity harness covers controller input. The new unit tests in keymapping.rs check this.

Self-check

tools/pr_ready.py doesn't run on Windows, so I ran its steps by hand:

  • cargo fmt --all -- --check: clean
  • cargo clippy -p horizon-client-input --all-targets -- -D warnings: clean
  • cargo clippy -p horizon-client --all-targets -- -D warnings: clean
  • cargo test -p horizon-client-input --lib keymapping: 5 passed, including the new pad_toggle_is_restored_after_a_screen and pad_toggle_ends_with_its_release.
  • Before the fix: I put back the old pad logic (a hold-mode press or release of the opposite state, as pad.rs did) and kept the new tests. Both new tests fail:
    • pad_toggle_is_restored_after_a_screen panics with the pad's toggle is restored;
    • pad_toggle_ends_with_its_release panics on assertion failed: keys.is_down(SNEAK) (the toggle doesn't come back after the death screen);
    • result: 3 passed; 2 failed.
  • cargo build --profile fast -p horizon-client --bins: OK
  • Rebased on current main and re-ran fmt, clippy and the tests above: same results.

In game (single player, server thread, survival, virtual pad through horizon-ctl pad rs tap, controller toggle-sneak on, toggle crouch off). The values are state's player.sneaking:

Step Before After
R3 true true
E (inventory open) false false
Esc (inventory closed) false (stays standing) true (crouched again)
R3 again true (toggles back on) false (toggles off)

After the fix, a keyboard shift press and release while the inventory is open (a shift-click) doesn't drop the restore. Once sneaking is toggled off, opening and closing the inventory leaves you standing. Holding Shift on the keyboard still holds sneak, and releasing Shift stops it. The pad_toggle_* tests check the same steps, along with the gamepad tests (15 passed).

Screenshots

before: toggle-sneak on, open and close the inventory: the player stands up

after: still crouching after the screen closes

Third-person front view after closing the inventory. Before: the player stands. After: the player is crouched again, as with keyboard toggle crouch.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/4030 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix-3061-pad` --- ### 📝 Commits (2) - [`a8b5151`](https://github.com/horizon-rust/horizon/commit/a8b5151ce5032477dbd285098244c478bd9370c4) Controller toggle-sneak comes back after a screen closes - [`3e536cb`](https://github.com/horizon-rust/horizon/commit/3e536cb541787a4640f50dad2b387ee7125a1a14) Merge origin/main into fix-3061-pad ### 📊 Changes **3 files changed** (+102 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-input/src/keymapping.rs` (+89 -4) 📝 `crates/horizon-client/src/game/pad.rs` (+10 -5) 📝 `docs/controllers.md` (+3 -2) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why With a controller, toggling sneak with the stick click and then opening the inventory (or any screen) left you standing after the screen closed. Toggle crouch on the keyboard brings sneaking back. **Cause.** The pad's toggle-sneak (`game/pad.rs`) faked a toggle on top of the hold-mode sneak mapping. It sent a Shift press when you weren't sneaking and a Shift release when you were. The sneak `ToggleKeyMapping` therefore treated it as a held key. `Gui.setScreen` → `KeyMapping.releaseAll` released it like a held key and didn't remember it, so `restoreToggleStatesOnScreenClosed` had nothing to restore. **Fix.** `ToggleKeys::pad_toggle` (`horizon-client-input/src/keymapping.rs`) flips the sneak mapping the way `ToggleKeyMapping.setDown(true)` does with its option on, and marks the mapping as toggled by the pad. While that mark is set, the mapping acts as a toggle mapping with `needsToggle` true: - opening a screen releases it and remembers it (`release`); - closing the screen restores it (`shouldRestoreStateOnScreenClosed`); - a keyboard Shift release behind the screen (a shift-click in the inventory) doesn't drop it. The mark clears when sneaking is toggled back up. A respawn keeps it only while a restore is pending: vanilla's `LocalPlayer.respawn` → `resetToggleKeys` runs before the death screen closes, so the option's toggle comes back after death too. Keyboard hold-to-sneak is unchanged: a held Shift is still released by a screen and not restored. Every stick click now reaches the key handlers as a press, as a toggle-crouch key press does, so the click that toggles sneaking off also wakes you from a bed (before, only the click that toggled it on did). `docs/controllers.md` now says how pad toggle-sneak behaves around screens. Part of #3061 (the controller item; the elytra sound and shield banners are already fixed, and the tab-list heads match vanilla). ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Controllers are Horizon-only. The pad's toggle now follows vanilla's toggle crouch (checked with javap on the 26.3 client.jar): - `ToggleKeyMapping.setDown`, `release`, `shouldRestoreStateOnScreenClosed` and `reset`; - `KeyMapping.releaseAll`, `restoreToggleStatesOnScreenClosed` and `resetToggleKeys`; - `Gui.setScreen`, which calls `releaseAll` when a screen opens and `restoreToggleStatesOnScreenClosed` when it closes in a level; - `DeathScreen`: `LocalPlayer.respawn` runs before `setScreen(null)`. No parity harness covers controller input. The new unit tests in `keymapping.rs` check this. ## Self-check `tools/pr_ready.py` doesn't run on Windows, so I ran its steps by hand: - `cargo fmt --all -- --check`: clean - `cargo clippy -p horizon-client-input --all-targets -- -D warnings`: clean - `cargo clippy -p horizon-client --all-targets -- -D warnings`: clean - `cargo test -p horizon-client-input --lib keymapping`: 5 passed, including the new `pad_toggle_is_restored_after_a_screen` and `pad_toggle_ends_with_its_release`. - **Before the fix:** I put back the old pad logic (a hold-mode press or release of the opposite state, as `pad.rs` did) and kept the new tests. Both new tests fail: - `pad_toggle_is_restored_after_a_screen` panics with `the pad's toggle is restored`; - `pad_toggle_ends_with_its_release` panics on `assertion failed: keys.is_down(SNEAK)` (the toggle doesn't come back after the death screen); - result: `3 passed; 2 failed`. - `cargo build --profile fast -p horizon-client --bins`: OK - Rebased on current `main` and re-ran fmt, clippy and the tests above: same results. **In game** (single player, server thread, survival, virtual pad through `horizon-ctl pad rs tap`, controller toggle-sneak on, toggle crouch off). The values are `state`'s `player.sneaking`: | Step | Before | After | |---|---|---| | R3 | true | true | | E (inventory open) | false | false | | Esc (inventory closed) | **false** (stays standing) | **true** (crouched again) | | R3 again | true (toggles back on) | false (toggles off) | After the fix, a keyboard shift press and release while the inventory is open (a shift-click) doesn't drop the restore. Once sneaking is toggled off, opening and closing the inventory leaves you standing. Holding Shift on the keyboard still holds sneak, and releasing Shift stops it. The `pad_toggle_*` tests check the same steps, along with the gamepad tests (15 passed). ## Screenshots ![before: toggle-sneak on, open and close the inventory: the player stands up](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/3061-pad-1.png) ![after: still crouching after the screen closes](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/3061-pad-2.png) Third-person front view after closing the inventory. Before: the player stands. After: the player is crouched again, as with keyboard toggle crouch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:12:05 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5368
No description provided.