[PR #5208] [MERGED] Release a held sneak or sprint that no key release can reach #6138

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5208
Author: @nathaniel-ramos-dev
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: fix/stuck-sneak-on-focus-loss


📝 Commits (4)

  • 44ba568 Release held sneak and sprint when the window loses focus
  • 5f25673 Heal a held sneak or sprint from the modifier state
  • fe617e8 Heal a stale Shift or Control from the modifier state too
  • fa4017b Merge main into #5208 (main builds again after #5251)

📊 Changes

1 file changed (+63 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+63 -1)

📄 Description

Fixes #5206

Two commits, the first alone fixes the repro in #5206.

1. Release the hold-mode latch on the focus loss. WindowEvent::Focused(false) clears keys and then sync_toggles both mappings back in, so a latch that no release can reach any more survives the alt-tab. This releases each mapping that does not toggle before the re-sync. set_down(false, needs_toggle) is a no-op while the mapping toggles (KeyState::needs_toggle, keymapping.rs:52, also true for a pad latch), so the latched sprint and sneak that #4139 was protecting still cross a short alt-tab, and a controller's toggle-sneak is untouched. Attack and use are included so a stale toggles.is_down(2) or (3) cannot be read back into self.left / self.right by track_toggle_screens.

2. Heal a latch the modifier state contradicts, once per frame. A release is also lost to a screen that reads presses only (#4974), and the focus-loss case is really "the release will never arrive". WindowEvent::ModifiersChanged is stored before any screen or gameplay handler runs, so the keyboard's own assertion is available every frame and answers both. A mapping that toggles, one a pad latched, or one rebound away from its modifier is left alone, so this cannot cancel a deliberate toggle or break a rebinding.

Vanilla

I followed the semantics Horizon already ports in crates/horizon-client-input/src/keymapping.rs: set_down as ToggleKeyMapping.setDown, release as ToggleKeyMapping.release, and the modifier channel as the reason a held key's state is knowable at all. I did not check handleFocus against the pinned bytecode with tools/rea_vanilla.py — the 26.3 class is net.minecraft.client.KeyboardHandler, which has no focus method I could find, and I stopped there rather than guess. If vanilla keeps a held sneak across a focus loss on purpose, commit 1 is wrong and should be dropped; commit 2 stands or falls with it. Commit 2 has no vanilla counterpart that I know of: it is Horizon healing a state vanilla can also reach, so it may belong behind an InputQuirks-style switch, and that is a maintainer call.

Tested

  • cargo fmt -p horizon-client -- --check clean, cargo check -p horizon-client --all-targets with no warnings.
  • cargo clippy -p horizon-client --all-targets -- -D warnings: exit 0.
  • cargo test -p horizon-client --bins: 358 passed, 0 failed, 3 ignored; 18 passed in the second binary target.
  • python3 tools/check_public_tree.py: passed.
  • Built from main at 68ac6f6, ran against prepared 26.3 resources (--test-terrain --frames 45): first frame presented, smoke report error: null.
  • Play-tested the repro from #5206 on Hyprland with commit 1: the player no longer stays crouched after a sub-500 ms alt-tab.

Not tested

  • Commit 2 in game: no player has confirmed the per-frame heal yet, and I have not exercised the #4974 dialog path with it.
  • No harness covers either path and none was added; no test for the focus or heal path either, as in #4139.
  • Windows, macOS, X11/GLFW and controller paths untested.

🔄 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/5208 **Author:** [@nathaniel-ramos-dev](https://github.com/nathaniel-ramos-dev) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/stuck-sneak-on-focus-loss` --- ### 📝 Commits (4) - [`44ba568`](https://github.com/horizon-rust/horizon/commit/44ba5682bebd5f5b51a98c20604933fab01cca26) Release held sneak and sprint when the window loses focus - [`5f25673`](https://github.com/horizon-rust/horizon/commit/5f25673546c429d8193d110a66261a3310cf1a17) Heal a held sneak or sprint from the modifier state - [`fe617e8`](https://github.com/horizon-rust/horizon/commit/fe617e83709069ce991cf338855c0e825a897bd9) Heal a stale Shift or Control from the modifier state too - [`fa4017b`](https://github.com/horizon-rust/horizon/commit/fa4017bdf665840dfb76eb45fa1f079cecf3e117) Merge main into #5208 (main builds again after #5251) ### 📊 Changes **1 file changed** (+63 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+63 -1) </details> ### 📄 Description Fixes #5206 Two commits, the first alone fixes the repro in #5206. **1. Release the hold-mode latch on the focus loss.** `WindowEvent::Focused(false)` clears `keys` and then `sync_toggle`s both mappings back in, so a latch that no release can reach any more survives the alt-tab. This releases each mapping that does not toggle before the re-sync. `set_down(false, needs_toggle)` is a no-op while the mapping toggles (`KeyState::needs_toggle`, keymapping.rs:52, also true for a pad latch), so the latched sprint and sneak that #4139 was protecting still cross a short alt-tab, and a controller's toggle-sneak is untouched. Attack and use are included so a stale `toggles.is_down(2)` or `(3)` cannot be read back into `self.left` / `self.right` by `track_toggle_screens`. **2. Heal a latch the modifier state contradicts, once per frame.** A release is also lost to a screen that reads presses only (#4974), and the focus-loss case is really "the release will never arrive". `WindowEvent::ModifiersChanged` is stored before any screen or gameplay handler runs, so the keyboard's own assertion is available every frame and answers both. A mapping that toggles, one a pad latched, or one rebound away from its modifier is left alone, so this cannot cancel a deliberate toggle or break a rebinding. ## Vanilla I followed the semantics Horizon already ports in `crates/horizon-client-input/src/keymapping.rs`: `set_down` as `ToggleKeyMapping.setDown`, `release` as `ToggleKeyMapping.release`, and the modifier channel as the reason a held key's state is knowable at all. **I did not check `handleFocus` against the pinned bytecode with `tools/rea_vanilla.py`** — the 26.3 class is `net.minecraft.client.KeyboardHandler`, which has no focus method I could find, and I stopped there rather than guess. If vanilla keeps a held sneak across a focus loss on purpose, commit 1 is wrong and should be dropped; commit 2 stands or falls with it. Commit 2 has no vanilla counterpart that I know of: it is Horizon healing a state vanilla can also reach, so it may belong behind an `InputQuirks`-style switch, and that is a maintainer call. ## Tested - `cargo fmt -p horizon-client -- --check` clean, `cargo check -p horizon-client --all-targets` with no warnings. - `cargo clippy -p horizon-client --all-targets -- -D warnings`: exit 0. - `cargo test -p horizon-client --bins`: 358 passed, 0 failed, 3 ignored; 18 passed in the second binary target. - `python3 tools/check_public_tree.py`: passed. - Built from main at 68ac6f6, ran against prepared 26.3 resources (`--test-terrain --frames 45`): first frame presented, smoke report `error: null`. - Play-tested the repro from #5206 on Hyprland with commit 1: the player no longer stays crouched after a sub-500 ms alt-tab. ## Not tested - Commit 2 in game: no player has confirmed the per-frame heal yet, and I have not exercised the #4974 dialog path with it. - No harness covers either path and none was added; no test for the focus or heal path either, as in #4139. - Windows, macOS, X11/GLFW and controller paths untested. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:14:14 +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#6138
No description provided.