[PR #235] [MERGED] Centre the cursor when a screen opens from gameplay #2424

Closed
opened 2026-11-02 15:55:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/235
Author: @ludovic111
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @ludovic111

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


📝 Commits (1)

  • f0aa88b Centre the cursor when a screen opens from gameplay

📊 Changes

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

View changed files

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

📄 Description

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

What

When a screen opens from gameplay (inventory, chest, pause, chat, sign, book, death), the cursor now appears at the window centre. Before, it appeared wherever the OS had left it.

Why

Ludovic: "sometimes when we open the inventory or other stuff it goes idk where". Game::capture(false) only released the grab. Vanilla's MouseHandler.releaseMouse()/grabMouse() set the cursor position to the window centre (glfwSetCursorPos).

How

  • capture(false) when the pointer was grabbed: on Wayland, winit's set_cursor_position is only a hint for the locked pointer's position, so it is set before ungrabbing. It is set again after ungrabbing for X11/Windows/macOS, where a warp works. self.cursor (what every screen hit-tests and uses for hover) is set to the centre in GUI pixels.
  • capture(true) also recentres, as grabMouse does.
  • Releasing a pointer that is already released does nothing, so moving from one screen to another keeps the cursor where it is, as vanilla does. Nothing warps while the window is unfocused, so losing focus never pulls the pointer back.
  • I read every call site: they all release through capture(false). The controller virtual cursor (#129) seeds its position from self.cursor, so it starts at the centre too.

How tested

Draft: no in-game test yet. It compiles: the Linux build on the ThinkPad and workspace clippy on the Mac mini are clean. Still to do: on the vscreen, check sway (Wayland) and its Xwayland :6 (X11, WINIT_UNIX_BACKEND/unset WAYLAND_DISPLAY) with grim -c to show the real pointer. Turn the camera, then press E, open a chest, press Esc, T and /, and check that the cursor is centred and hover matches. Also check that a screen→screen change keeps the cursor. I could not check Hyprland: whether it applies the lock position hint needs a real Hyprland session.

🤖 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/235 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/cursor-centre-on-screen-open` --- ### 📝 Commits (1) - [`f0aa88b`](https://github.com/horizon-rust/horizon/commit/f0aa88b0f6624b2b77420aedcd9e5c4330ef7bda) Centre the cursor when a screen opens from gameplay ### 📊 Changes **1 file changed** (+37 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+37 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What When a screen opens from gameplay (inventory, chest, pause, chat, sign, book, death), the cursor now appears at the window centre. Before, it appeared wherever the OS had left it. ## Why Ludovic: "sometimes when we open the inventory or other stuff it goes idk where". `Game::capture(false)` only released the grab. Vanilla's `MouseHandler.releaseMouse()`/`grabMouse()` set the cursor position to the window centre (`glfwSetCursorPos`). ## How - `capture(false)` when the pointer was grabbed: on Wayland, winit's `set_cursor_position` is only a hint for the locked pointer's position, so it is set **before** ungrabbing. It is set again after ungrabbing for X11/Windows/macOS, where a warp works. `self.cursor` (what every screen hit-tests and uses for hover) is set to the centre in GUI pixels. - `capture(true)` also recentres, as `grabMouse` does. - Releasing a pointer that is already released does nothing, so moving from one screen to another keeps the cursor where it is, as vanilla does. Nothing warps while the window is unfocused, so losing focus never pulls the pointer back. - I read every call site: they all release through `capture(false)`. The controller virtual cursor (#129) seeds its position from `self.cursor`, so it starts at the centre too. ## How tested **Draft: no in-game test yet.** It compiles: the Linux build on the ThinkPad and workspace clippy on the Mac mini are clean. Still to do: on the vscreen, check sway (Wayland) and its Xwayland `:6` (X11, `WINIT_UNIX_BACKEND`/unset WAYLAND_DISPLAY) with `grim -c` to show the real pointer. Turn the camera, then press E, open a chest, press Esc, T and /, and check that the cursor is centred and hover matches. Also check that a screen→screen change keeps the cursor. I could not check Hyprland: whether it applies the lock position hint needs a real Hyprland session. 🤖 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-02 15:55:58 +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#2424
No description provided.