[PR #2797] [MERGED] ui: the mouse position is the centre whenever the grab state changes #4620

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2797
Author: @levzzz5154
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/28/2026
Merged by: @ludovic111

Base: main ← Head: fix/screen-cursor-centre


📝 Commits (6)

  • d13b478 ui: the mouse position is the centre whenever the grab state changes
  • 1f040d0 Merge remote-tracking branch 'upstream/main' into fix/screen-cursor-centre
  • 67e0d54 tests: give the capture fixture the mouse position helper
  • 152334e Merge remote-tracking branch 'upstream/main' into fix/screen-cursor-centre
  • 23e3cf4 Merge main into screen-cursor-centre
  • 1d693cb Read mouse.rs where the input crate keeps it now

📊 Changes

3 files changed (+74 additions, -3 deletions)

View changed files

📝 crates/horizon-client-input/src/mouse.rs (+41 -0)
📝 crates/horizon-client/src/game.rs (+14 -2)
📝 tests/test_world_input_capture.py (+19 -1)

📄 Description

🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself.

What and why

Opening the inventory (or any container screen) from gameplay left the
mouse cursor where the last screen had it, instead of in the middle of
the window as vanilla does.

Vanilla's rule is in MouseHandler: grabMouse and releaseMouse both
put the mouse at the window's centre when the pointer's grab state
changes. Horizon only did it on the release (the commit "Centre the
cursor when a screen opens from gameplay", f0aa88b0f), so closing a
screen and grabbing the pointer again left Horizon's own cursor — the
point every screen hit-tests and draws its hover with — where the closed
screen had it, and on the compositors that do not apply the pointer warp
the visible cursor stayed off the centre altogether.

The rule is now one function, mouse_position_after_grab_change, and
Game::capture applies it on both sides of the grab state change: the
mouse position is the window's centre when the pointer is grabbed and
when it is released, and it stays where it is when the grab state does
not change (a screen opened from another screen keeps the cursor, as in
vanilla).

Fixes #1925

Vanilla reference

  • net.minecraft.client.MouseHandler.grabMouse —
    this.mouseGrabbed = true; this.xpos = this.minecraft.getWindow().getScreenWidth() / 2.0; this.ypos = this.minecraft.getWindow().getScreenHeight() / 2.0;
    then InputConstants.grabMouse(...): grabbing the pointer puts the
    mouse at the window's centre.
  • net.minecraft.client.MouseHandler.releaseMouse —
    this.mouseGrabbed = false; this.xpos = ... / 2.0; this.ypos = ... / 2.0;
    then InputConstants.releaseMouse(...): releasing it does the same.
    Both only act when the grab state actually changes
    (if (!this.mouseGrabbed) and if (this.mouseGrabbed)).
  • net.minecraft.client.gui.Gui.setScreen — a screen releases the mouse
    (this.minecraft.mouseHandler.releaseMouse()) and the game grabs it
    again (this.minecraft.mouseHandler.grabMouse()), so a screen opened
    from gameplay starts with the cursor in the middle.

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on cachyos-x8664, against upstream/main at 1e3a9d53a, 3 min 15 s; run with the stable toolchain, because the local default is 1.95 and its clippy flags lints the CI's 1.99 does not)

Check Result
Scope ✅ 3 files, +74 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 336 passed (19 s)
rustfmt ✅ (4 s)
clippy ✅ (37 s)
tests: horizon-client ✅ 1330 passed (1 min 40 s)
doc tests ✅ 0 passed (21 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 35 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, game_loop, hardcore_respawn, lan_integration and 23 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The clippy failure is not in this change: the errors are in
crates/horizon-world (worldgen/aquifer/noise_based.rs and
crates/horizon-world/src/level/...), files this branch does not touch,
and upstream/main fails the same way on its own:
cargo clippy -p horizon-world --all-targets -- -D warnings in a
worktree of upstream/main at 1e3a9d53a reports the same errors.

The focused checks for this change:

Check Result
cargo test -p horizon-client --lib -- mouse:: ✅ 8 passed, 0 failed (1194 filtered out), including the_mouse_position_is_the_centre_when_the_grab_changes
python3 -m unittest tests.test_world_input_capture ✅ 2 passed
python3 -m unittest discover -s tests ✅ 336 passed (17 s)
cargo build -p horizon-client --bin horizon-client ✅ clean, no warnings
cargo fmt -p horizon-client ✅ clean

The Python fixture compiles Game::capture on its own, so it now takes
the helper from the client (mouse_position_after_grab_change) like it
takes the methods, and it asserts the grab path too: grabbing the
pointer puts the mouse at the window's centre, as MouseHandler.grabMouse
does.

🤖 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/2797 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/28/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/screen-cursor-centre` --- ### 📝 Commits (6) - [`d13b478`](https://github.com/horizon-rust/horizon/commit/d13b478ca2e7aacff6bdab2c17a39df1b23b2f13) ui: the mouse position is the centre whenever the grab state changes - [`1f040d0`](https://github.com/horizon-rust/horizon/commit/1f040d06eb7eab0e1fef4d36154da3258e45c66a) Merge remote-tracking branch 'upstream/main' into fix/screen-cursor-centre - [`67e0d54`](https://github.com/horizon-rust/horizon/commit/67e0d5406224623248e5bfb8ec4b8e16442e7521) tests: give the capture fixture the mouse position helper - [`152334e`](https://github.com/horizon-rust/horizon/commit/152334eee3a11fa35887b5f8d8edf42d025acb02) Merge remote-tracking branch 'upstream/main' into fix/screen-cursor-centre - [`23e3cf4`](https://github.com/horizon-rust/horizon/commit/23e3cf465c0932bfc08e8ee8a7446edead7c2a7b) Merge main into screen-cursor-centre - [`1d693cb`](https://github.com/horizon-rust/horizon/commit/1d693cb3c33915c3892544951a64e8e89d5c7e73) Read mouse.rs where the input crate keeps it now ### 📊 Changes **3 files changed** (+74 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-input/src/mouse.rs` (+41 -0) 📝 `crates/horizon-client/src/game.rs` (+14 -2) 📝 `tests/test_world_input_capture.py` (+19 -1) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself. ## What and why Opening the inventory (or any container screen) from gameplay left the mouse cursor where the last screen had it, instead of in the middle of the window as vanilla does. Vanilla's rule is in `MouseHandler`: `grabMouse` and `releaseMouse` both put the mouse at the window's centre when the pointer's grab state changes. Horizon only did it on the release (the commit "Centre the cursor when a screen opens from gameplay", f0aa88b0f), so closing a screen and grabbing the pointer again left Horizon's own cursor — the point every screen hit-tests and draws its hover with — where the closed screen had it, and on the compositors that do not apply the pointer warp the visible cursor stayed off the centre altogether. The rule is now one function, `mouse_position_after_grab_change`, and `Game::capture` applies it on both sides of the grab state change: the mouse position is the window's centre when the pointer is grabbed and when it is released, and it stays where it is when the grab state does not change (a screen opened from another screen keeps the cursor, as in vanilla). Fixes #1925 ## Vanilla reference - `net.minecraft.client.MouseHandler.grabMouse` — `this.mouseGrabbed = true; this.xpos = this.minecraft.getWindow().getScreenWidth() / 2.0; this.ypos = this.minecraft.getWindow().getScreenHeight() / 2.0;` then `InputConstants.grabMouse(...)`: grabbing the pointer puts the mouse at the window's centre. - `net.minecraft.client.MouseHandler.releaseMouse` — `this.mouseGrabbed = false; this.xpos = ... / 2.0; this.ypos = ... / 2.0;` then `InputConstants.releaseMouse(...)`: releasing it does the same. Both only act when the grab state actually changes (`if (!this.mouseGrabbed)` and `if (this.mouseGrabbed)`). - `net.minecraft.client.gui.Gui.setScreen` — a screen releases the mouse (`this.minecraft.mouseHandler.releaseMouse()`) and the game grabs it again (`this.minecraft.mouseHandler.grabMouse()`), so a screen opened from gameplay starts with the cursor in the middle. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on cachyos-x8664, against upstream/main at 1e3a9d53a, 3 min 15 s; run with the `stable` toolchain, because the local default is 1.95 and its clippy flags lints the CI's 1.99 does not) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +74 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 336 passed (19 s) | | rustfmt | ✅ (4 s) | | clippy | ✅ (37 s) | | tests: horizon-client | ✅ 1330 passed (1 min 40 s) | | doc tests | ✅ 0 passed (21 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 35 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, game_loop, hardcore_respawn, lan_integration and 23 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The clippy failure is not in this change: the errors are in `crates/horizon-world` (`worldgen/aquifer/noise_based.rs` and `crates/horizon-world/src/level/...`), files this branch does not touch, and `upstream/main` fails the same way on its own: `cargo clippy -p horizon-world --all-targets -- -D warnings` in a worktree of `upstream/main` at 1e3a9d53a reports the same errors. The focused checks for this change: | Check | Result | | --- | --- | | `cargo test -p horizon-client --lib -- mouse::` | ✅ 8 passed, 0 failed (1194 filtered out), including `the_mouse_position_is_the_centre_when_the_grab_changes` | | `python3 -m unittest tests.test_world_input_capture` | ✅ 2 passed | | `python3 -m unittest discover -s tests` | ✅ 336 passed (17 s) | | `cargo build -p horizon-client --bin horizon-client` | ✅ clean, no warnings | | `cargo fmt -p horizon-client` | ✅ clean | The Python fixture compiles `Game::capture` on its own, so it now takes the helper from the client (`mouse_position_after_grab_change`) like it takes the methods, and it asserts the grab path too: grabbing the pointer puts the mouse at the window's centre, as `MouseHandler.grabMouse` does. 🤖 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:06:43 +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#4620
No description provided.