[GH-ISSUE #1925] [Bug] Mouse cursor does not center on screen when opening inventory #575

Closed
opened 2026-11-02 15:40:11 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @i-krazy on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/1925

Expected Behavior

When opening the inventory (or any GUI/container screen), the mouse cursor should automatically center on the screen, matching standard Java Edition behavior.

Actual Behavior

The mouse cursor remains in the position where it was last left before opening the interface. This makes inventory navigation slightly clunky.

Steps to Reproduce

  1. Open any world in singleplayer.
  2. Look around and open the inventory (or a chest).
  3. Notice that the cursor spawns at the previous mouse position instead of the center of the viewport.

Environment

  • OS: Arch Linux (Wayland / LabWC)
  • GPU: Intel UHD Graphics (Jasper Lake)
Originally created by @i-krazy on GitHub (Oct 25, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/1925 ### Expected Behavior When opening the inventory (or any GUI/container screen), the mouse cursor should automatically center on the screen, matching standard Java Edition behavior. ### Actual Behavior The mouse cursor remains in the position where it was last left before opening the interface. This makes inventory navigation slightly clunky. ### Steps to Reproduce 1. Open any world in singleplayer. 2. Look around and open the inventory (or a chest). 3. Notice that the cursor spawns at the previous mouse position instead of the center of the viewport. ### Environment - OS: Arch Linux (Wayland / LabWC) - GPU: Intel UHD Graphics (Jasper Lake)
Author
Owner

@kacpherek commented on GitHub (Oct 26, 2026):

Opening a screen from gameplay already centres the cursor on main since #235. If it still stays put on a build that includes that change, please say which build and compositor, since Wayland compositors differ in how they apply the pointer position.

<!-- gh-comment-id:6422493993 --> @kacpherek commented on GitHub (Oct 26, 2026): Opening a screen from gameplay already centres the cursor on main since #235. If it still stays put on a build that includes that change, please say which build and compositor, since Wayland compositors differ in how they apply the pointer position.
Author
Owner

@levzzz5154 commented on GitHub (Oct 27, 2026):

🤖 Agent: fixed in the pull request below: the mouse position is the window's
centre whenever the pointer's grab state changes, as vanilla's
MouseHandler.grabMouse and MouseHandler.releaseMouse do.

What I found on the current main: the centring itself was already there
(the commit "Centre the cursor when a screen opens from gameplay",
f0aa88b0f), but only on the release — Game::capture set the cursor when
the pointer was released, and not when it was grabbed again, so closing a
screen left Horizon's own cursor (the point every screen hit-tests with)
where the closed screen had it, and on a compositor that does 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 the
game applies it on both sides of the grab state change; a screen opened
from another screen keeps the cursor where it is, as in vanilla.

What I verified:

  • cargo test -p horizon-client --lib -- mouse:: -> 8 passed, 0 failed,
    including the new the_mouse_position_is_the_centre_when_the_grab_changes,
    which asserts the vanilla rule: the centre when the grab state changes
    (grab or release), the position unchanged when it does not.
  • cargo build -p horizon-client --bin horizon-client and
    cargo fmt -p horizon-client are clean.

Vanilla followed: net.minecraft.client.MouseHandler.grabMouse and
releaseMouse (both put xpos/ypos at the window's centre, and only
when the grab state changes) and net.minecraft.client.gui.Gui.setScreen
(a screen releases the mouse, the game grabs it again).

<!-- gh-comment-id:6442204061 --> @levzzz5154 commented on GitHub (Oct 27, 2026): 🤖 Agent: fixed in the pull request below: the mouse position is the window's centre whenever the pointer's grab state changes, as vanilla's `MouseHandler.grabMouse` and `MouseHandler.releaseMouse` do. What I found on the current `main`: the centring itself was already there (the commit "Centre the cursor when a screen opens from gameplay", f0aa88b0f), but only on the release — `Game::capture` set the cursor when the pointer was released, and not when it was grabbed again, so closing a screen left Horizon's own cursor (the point every screen hit-tests with) where the closed screen had it, and on a compositor that does 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 the game applies it on both sides of the grab state change; a screen opened from another screen keeps the cursor where it is, as in vanilla. What I verified: - `cargo test -p horizon-client --lib -- mouse::` -> 8 passed, 0 failed, including the new `the_mouse_position_is_the_centre_when_the_grab_changes`, which asserts the vanilla rule: the centre when the grab state changes (grab or release), the position unchanged when it does not. - `cargo build -p horizon-client --bin horizon-client` and `cargo fmt -p horizon-client` are clean. Vanilla followed: `net.minecraft.client.MouseHandler.grabMouse` and `releaseMouse` (both put `xpos`/`ypos` at the window's centre, and only when the grab state changes) and `net.minecraft.client.gui.Gui.setScreen` (a screen releases the mouse, the game grabs it again).
Author
Owner

@levzzz5154 commented on GitHub (Oct 27, 2026):

🤖 Agent: the pull request above now carries the check the issue needs, and
the pr_ready block:

Check Result
python3 -m unittest tests.test_world_input_capture ✅ 2 passed
python3 -m unittest discover -s tests ✅ 336 passed (17 s)
cargo test -p horizon-client --lib -- mouse:: ✅ 8 passed, 0 failed, including the new the_mouse_position_is_the_centre_when_the_grab_changes
cargo build -p horizon-client --bin horizon-client ✅ clean
cargo fmt -p horizon-client ✅ clean
pr_ready --quick Python tests ✅ 336 passed, rustfmt ✅, horizon-client tests ✅ 1330 passed, doc tests ✅, public tree ✅, Cargo.lock unchanged, scope ✅ 3 files +74 −3; clippy ❌ (pre-existing on upstream/main: the errors are in crates/horizon-world, which this branch does not touch, and upstream/main at 1e3a9d53a fails the same way with cargo clippy -p horizon-world --all-targets -- -D warnings)

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

<!-- gh-comment-id:6443063701 --> @levzzz5154 commented on GitHub (Oct 27, 2026): 🤖 Agent: the pull request above now carries the check the issue needs, and the `pr_ready` block: | Check | Result | | --- | --- | | `python3 -m unittest tests.test_world_input_capture` | ✅ 2 passed | | `python3 -m unittest discover -s tests` | ✅ 336 passed (17 s) | | `cargo test -p horizon-client --lib -- mouse::` | ✅ 8 passed, 0 failed, including the new `the_mouse_position_is_the_centre_when_the_grab_changes` | | `cargo build -p horizon-client --bin horizon-client` | ✅ clean | | `cargo fmt -p horizon-client` | ✅ clean | | `pr_ready --quick` | Python tests ✅ 336 passed, rustfmt ✅, horizon-client tests ✅ 1330 passed, doc tests ✅, public tree ✅, Cargo.lock unchanged, scope ✅ 3 files +74 −3; clippy ❌ (pre-existing on `upstream/main`: the errors are in `crates/horizon-world`, which this branch does not touch, and `upstream/main` at 1e3a9d53a fails the same way with `cargo clippy -p horizon-world --all-targets -- -D warnings`) | The Python fixture compiles `Game::capture` on its own, so it takes the helper from the client now, like it takes the methods, and it asserts the grab path as well: grabbing the pointer puts the mouse at the window's centre, as `MouseHandler.grabMouse` does.
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#575
No description provided.