diff --git a/src/main.rs b/src/main.rs index 4124cd5..c3533d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -630,6 +630,11 @@ fn handle_window_event( event: winit::event::Event, ) -> bool { use winit::event::*; + let cursor_grab_mode = if cfg!(target_os = "macos") { + winit::window::CursorGrabMode::Locked + } else { + winit::window::CursorGrabMode::Confined + }; match event { Event::MainEventsCleared => return true, Event::DeviceEvent { @@ -659,9 +664,7 @@ fn handle_window_event( use std::f64::consts::PI; if game.focused { - window - .set_cursor_grab(winit::window::CursorGrabMode::Locked) - .unwrap(); + window.set_cursor_grab(cursor_grab_mode).unwrap(); window.set_cursor_visible(false); if let Some(player) = game.server.player { let rotation = game @@ -719,9 +722,7 @@ fn handle_window_event( && !game.screen_sys.is_current_closable() { game.focused = true; - window - .set_cursor_grab(winit::window::CursorGrabMode::Locked) - .unwrap(); + window.set_cursor_grab(cursor_grab_mode).unwrap(); window.set_cursor_visible(false); } else if !game.focused { #[cfg(not(target_arch = "wasm32"))] @@ -783,9 +784,7 @@ fn handle_window_event( screen::SettingsMenu::new(game.vars.clone(), true), )); } else if game.screen_sys.is_current_closable() { - window - .set_cursor_grab(winit::window::CursorGrabMode::Locked) - .unwrap(); + window.set_cursor_grab(cursor_grab_mode).unwrap(); window.set_cursor_visible(false); game.focused = true; game.screen_sys.pop_screen();