Keep the pointer locked on macOS when the game captures it
winit's macOS set_cursor_position re-associates the mouse with the pointer (CGAssociateMouseAndMouseCursorPosition(true)), so warping to the window centre right after the Locked grab released it again and the pointer moved freely in first person. Warp before grabbing on macOS; Wayland still warps after, since it moves a pointer only while locked. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0188LkUPntcZdfMF3wAqR2tK
This commit is contained in:
@@ -4485,10 +4485,17 @@ impl Game<'_> {
|
||||
};
|
||||
if capture {
|
||||
self.mouse.set_ignore_first_move();
|
||||
// macOS warps by re-associating the mouse with the pointer,
|
||||
// which undoes a Locked grab and leaves the pointer free: warp
|
||||
// first there. Wayland moves a pointer only while it is locked,
|
||||
// so everywhere else warp after grabbing.
|
||||
#[cfg(target_os = "macos")]
|
||||
warp(window);
|
||||
self.captured = window
|
||||
.set_cursor_grab(CursorGrabMode::Locked)
|
||||
.or_else(|_| window.set_cursor_grab(CursorGrabMode::Confined))
|
||||
.is_ok();
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
if self.captured && self.focused {
|
||||
warp(window);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user