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 2edcd61
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main.rs
Expand Up @@ -75,11 +75,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 2edcd61

Please sign in to comment.