Skip to content

Commit

Permalink
Fix grab mode
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Nov 25, 2022
1 parent 3827316 commit bab52f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 5 additions & 5 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,12 +834,12 @@ impl Window {
.push(WindowCommand::SetAlwaysOnTop { always_on_top });
}
/// Close the operating system window corresponding to this [`Window`].
///
///
/// This will also lead to this [`Window`] being removed from the
/// [`Windows`] resource.
///
/// If the default [`WindowPlugin`] is used, when no windows are
/// open, the [app will exit](bevy_app::AppExit).
/// open, the [app will exit](bevy_app::AppExit).
/// To disable this behaviour, set `exit_on_all_closed` on the [`WindowPlugin`]
/// to `false`
///
Expand Down Expand Up @@ -869,7 +869,7 @@ impl Window {
/// The "html canvas" element selector.
///
/// If set, this selector will be used to find a matching html canvas element,
/// rather than creating a new one.
/// rather than creating a new one.
/// Uses the [CSS selector format](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector).
///
/// This value has no effect on non-web platforms.
Expand Down Expand Up @@ -978,7 +978,7 @@ pub struct WindowDescriptor {
pub decorations: bool,
/// Sets whether the cursor is visible when the window has focus.
pub cursor_visible: bool,
/// Sets whether and how the window grabs the cursor.
/// Sets whether or how the window grabs the cursor.
pub cursor_grab_mode: CursorGrabMode,
/// Sets whether or not the window listens for 'hits' of mouse activity over _this_ window.
pub hittest: bool,
Expand All @@ -996,7 +996,7 @@ pub struct WindowDescriptor {
/// The "html canvas" element selector.
///
/// If set, this selector will be used to find a matching html canvas element,
/// rather than creating a new one.
/// rather than creating a new one.
/// Uses the [CSS selector format](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector).
///
/// This value has no effect on non-web platforms.
Expand Down
17 changes: 13 additions & 4 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod web_resize;
mod winit_config;
mod winit_windows;

use converters::convert_cursor_grab_mode;
use winit::window::CursorGrabMode;
pub use winit_config::*;
pub use winit_windows::*;

Expand Down Expand Up @@ -136,9 +136,18 @@ fn change_window(
}
bevy_window::WindowCommand::SetCursorGrabMode { grab_mode } => {
let window = winit_windows.get_window(id).unwrap();
window
.set_cursor_grab(convert_cursor_grab_mode(grab_mode))
.unwrap_or_else(|e| error!("Unable to un/grab cursor: {}", e));
match grab_mode {
bevy_window::CursorGrabMode::None => {
window.set_cursor_grab(CursorGrabMode::None)
}
bevy_window::CursorGrabMode::Confined => window
.set_cursor_grab(CursorGrabMode::Confined)
.or_else(|_e| window.set_cursor_grab(CursorGrabMode::Locked)),
bevy_window::CursorGrabMode::Locked => window
.set_cursor_grab(CursorGrabMode::Locked)
.or_else(|_e| window.set_cursor_grab(CursorGrabMode::Confined)),
}
.unwrap_or_else(|e| error!("Unable to un/grab cursor: {}", e));
}
bevy_window::WindowCommand::SetCursorVisibility { visible } => {
let window = winit_windows.get_window(id).unwrap();
Expand Down

0 comments on commit bab52f2

Please sign in to comment.