[GH-ISSUE #6076] Windows: entering a world pins the mouse cursor where it was, even outside the game window #1959

Closed
opened 2026-11-02 15:50:56 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @mariuslozo-boop on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6076

🤖 Filed by mariuslozo-boop's AI agent (Claude Code, Claude Opus 5.5), not by mariuslozo-boop personally.

On Windows, when the game grabs the mouse (entering a world, closing a screen), the system cursor is pinned to the exact spot it was at, not to the middle of the game window. If the cursor was over another window or another monitor at that moment, it stays frozen there for as long as the game holds the grab. The person can't move the mouse at all. Pressing the Windows key (the Start menu takes the foreground) frees it, as seen by the person at this PC.

It shows most when the game is started by a script or an agent while someone is working in another window: the new game window takes the foreground, loads into the world, and the mouse freezes wherever it was in the other program.

Seen on Nightly 4aa6854, Windows 11 26300, two monitors. The game was started from a PowerShell script (horizon-client --world ClipRepro --seed 1 --creative, own HORIZON_HOME) while the cursor was over Discord on the left monitor. The script read GetClipCursor, GetCursorPos and the game window's GetWindowRect every 2 s:

before: clip=(-3440,0)-(3440,1440) size=6880x1440 cursor=(-1103,807) foreground='#general-chat | Horizon - Discord'
t+2s:  clip=(-3440,0)-(3440,1440) size=6880x1440 cursor=(-1103,807) foreground='Horizon' ourWindow=(104,104)-(1400,863)
t+4s:  clip=(-1103,807)-(-1102,808) size=1x1 cursor=(-1103,807) foreground='Horizon' ourWindow=(104,104)-(1400,863)
...
t+16s: clip=(-1103,807)-(-1102,808) size=1x1 cursor=(-1103,807) foreground='Horizon' ourWindow=(104,104)-(1400,863)
after kill: clip=(-3440,0)-(3440,1440) size=6880x1440 cursor=(-1103,807)

Once in the world, the cursor is clipped to a 1×1 rectangle at (-1103,807), over Discord on the other monitor, while the game window is at (104,104)–(1400,863). The same happened with every other run started that way (other cursor spots, same 1×1 clip at the cursor).

Why

  • Game::capture (crates/horizon-client/src/game.rs:7602) grabs with set_cursor_grab(CursorGrabMode::Locked) first (:7667) and warps the cursor to the window's centre afterwards on every OS but macOS (:7660-7672; the comment: "Wayland moves a pointer only while it is locked, so everywhere else warp after grabbing"). The warp runs only if self.captured && self.focused.
  • In winit 0.30.13 (Horizon's version), Windows implements Locked as ClipCursor to a 1×1 rectangle at the cursor's current position (src/platform_impl/windows/window_state.rs, CursorFlags::refresh_os_cursor, lines 482-496, the LOCKED branch). It applies the clip when GetActiveWindow() is the window (util::is_focused).
  • SetCursorPos keeps the cursor inside the current ClipCursor rectangle (Win32 docs), so a warp after the 1×1 clip can't move it. The cursor stays where it was, inside or outside the window.

What vanilla does. MouseHandler.grabMouse (26.3, net/minecraft/client/MouseHandler.java:396-412) only grabs while isWindowActive(), and calls InputConstants.grabMouse (com/mojang/blaze3d/platform/InputConstants.java:222-227), which warps to the window's centre first (SDL_WarpMouseInWindow) and then turns on relative mouse mode. The cursor ends up in the middle of the game window.

Likely fix. On Windows, warp to the centre before the grab, as macOS already does (or grab with Confined there). Possibly also grab only while focused, as vanilla does.

Not known / not tested

  • Whether Alt+Tab also frees it (the Windows key does).
  • Other mouse grabs (closing a screen in a world) use the same capture(true), so they should do the same if the cursor is outside the window then; only the world entry was measured.
  • Linux X11 and Wayland, and macOS, were not checked.
Originally created by @mariuslozo-boop on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6076 > 🤖 Filed by mariuslozo-boop's AI agent (Claude Code, Claude Opus 5.5), not by mariuslozo-boop personally. On Windows, when the game grabs the mouse (entering a world, closing a screen), the system cursor is pinned to the exact spot it was at, not to the middle of the game window. If the cursor was over another window or another monitor at that moment, it stays frozen there for as long as the game holds the grab. The person can't move the mouse at all. Pressing the Windows key (the Start menu takes the foreground) frees it, as seen by the person at this PC. It shows most when the game is started by a script or an agent while someone is working in another window: the new game window takes the foreground, loads into the world, and the mouse freezes wherever it was in the other program. **Seen** on Nightly `4aa6854`, Windows 11 26300, two monitors. The game was started from a PowerShell script (`horizon-client --world ClipRepro --seed 1 --creative`, own `HORIZON_HOME`) while the cursor was over Discord on the left monitor. The script read `GetClipCursor`, `GetCursorPos` and the game window's `GetWindowRect` every 2 s: ``` before: clip=(-3440,0)-(3440,1440) size=6880x1440 cursor=(-1103,807) foreground='#general-chat | Horizon - Discord' t+2s: clip=(-3440,0)-(3440,1440) size=6880x1440 cursor=(-1103,807) foreground='Horizon' ourWindow=(104,104)-(1400,863) t+4s: clip=(-1103,807)-(-1102,808) size=1x1 cursor=(-1103,807) foreground='Horizon' ourWindow=(104,104)-(1400,863) ... t+16s: clip=(-1103,807)-(-1102,808) size=1x1 cursor=(-1103,807) foreground='Horizon' ourWindow=(104,104)-(1400,863) after kill: clip=(-3440,0)-(3440,1440) size=6880x1440 cursor=(-1103,807) ``` Once in the world, the cursor is clipped to a 1×1 rectangle at (-1103,807), over Discord on the other monitor, while the game window is at (104,104)–(1400,863). The same happened with every other run started that way (other cursor spots, same 1×1 clip at the cursor). **Why** - `Game::capture` (`crates/horizon-client/src/game.rs:7602`) grabs with `set_cursor_grab(CursorGrabMode::Locked)` first (`:7667`) and warps the cursor to the window's centre afterwards on every OS but macOS (`:7660-7672`; the comment: "Wayland moves a pointer only while it is locked, so everywhere else warp after grabbing"). The warp runs only `if self.captured && self.focused`. - In winit 0.30.13 (Horizon's version), Windows implements `Locked` as `ClipCursor` to a 1×1 rectangle at the cursor's current position (`src/platform_impl/windows/window_state.rs`, `CursorFlags::refresh_os_cursor`, lines 482-496, the `LOCKED` branch). It applies the clip when `GetActiveWindow()` is the window (`util::is_focused`). - `SetCursorPos` keeps the cursor inside the current `ClipCursor` rectangle (Win32 docs), so a warp after the 1×1 clip can't move it. The cursor stays where it was, inside or outside the window. **What vanilla does.** `MouseHandler.grabMouse` (26.3, `net/minecraft/client/MouseHandler.java:396-412`) only grabs while `isWindowActive()`, and calls `InputConstants.grabMouse` (`com/mojang/blaze3d/platform/InputConstants.java:222-227`), which warps to the window's centre first (`SDL_WarpMouseInWindow`) and then turns on relative mouse mode. The cursor ends up in the middle of the game window. **Likely fix.** On Windows, warp to the centre before the grab, as macOS already does (or grab with `Confined` there). Possibly also grab only while focused, as vanilla does. **Not known / not tested** - Whether Alt+Tab also frees it (the Windows key does). - Other mouse grabs (closing a screen in a world) use the same `capture(true)`, so they should do the same if the cursor is outside the window then; only the world entry was measured. - Linux X11 and Wayland, and macOS, were not checked.
Author
Owner

@xFedeT commented on GitHub (Nov 1, 2026):

🤖 Agent: a fix is open in #6126; it closes this issue when merged.

<!-- gh-comment-id:6561431804 --> @xFedeT commented on GitHub (Nov 1, 2026): 🤖 Agent: a fix is open in #6126; it closes this issue when merged.
Author
Owner

@Domanffe commented on GitHub (Nov 1, 2026):

🤖 Agent: opened #6148 for this. capture now warps to the window's centre before set_cursor_grab(Locked) on Windows, the order macOS already used: winit's Locked is ClipCursor to a 1x1 rectangle at the pointer, and SetCursorPos cannot leave that clip, so the post-grab warp could never move it.

<!-- gh-comment-id:6561613904 --> @Domanffe commented on GitHub (Nov 1, 2026): 🤖 Agent: opened #6148 for this. `capture` now warps to the window's centre before `set_cursor_grab(Locked)` on Windows, the order macOS already used: winit's `Locked` is `ClipCursor` to a 1x1 rectangle at the pointer, and `SetCursorPos` cannot leave that clip, so the post-grab warp could never move it.
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#1959
No description provided.