Skip to content

Commit

Permalink
Do not grab cursor on MacOS
Browse files Browse the repository at this point in the history
Mouse grabbing does not work correctly on MacOS: the mouse is locked to
the initial position instead of being confined to the primary window.

Relates to DigitalExtinction#354.
Relates to rust-windowing/winit#1093.
  • Loading branch information
Indy2222 committed Jan 27, 2023
1 parent af84fa2 commit 2073ae1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main.rs
@@ -1,7 +1,9 @@
#[cfg(not(target_os = "macos"))]
use bevy::window::CursorGrabMode;
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
window::{CursorGrabMode, WindowMode},
window::WindowMode,
};
use de_behaviour::BehaviourPluginGroup;
use de_camera::CameraPluginGroup;
Expand Down Expand Up @@ -75,11 +77,16 @@ impl Plugin for GamePlugin {
fn build(&self, app: &mut App) {
app.add_loopless_state(AppState::InMenu)
.add_loopless_state(MenuState::MLoading)
.add_loopless_state(GameState::None)
.add_enter_system(MenuState::MLoading, cursor_grab_system);
.add_loopless_state(GameState::None);

#[cfg(not(target_os = "macos"))]
{
app.add_enter_system(MenuState::MLoading, cursor_grab_system);
}
}
}

#[cfg(not(target_os = "macos"))]
fn cursor_grab_system(mut windows: ResMut<Windows>) {
let window = windows.get_primary_mut().unwrap();
window.set_cursor_grab_mode(CursorGrabMode::Confined);
Expand Down

0 comments on commit 2073ae1

Please sign in to comment.