The glutin/winit update in #700 changed set_cursor_grab from a bool to an enum, but always used CursorGrabMode::Locked, which is only available on macOS. Conditionally compile to use CursorGrabMode::Confined otherwise. Fixes #714 and fixes #713 * set_cursor_grab failed with NotSupported(NotSupportedError) on Linux Patch from https://github.com/iceiix/stevenarella/issues/714 * cargo fmt Co-authored-by: inferno <inferrna@gmail.com>
This commit is contained in:
parent
bbbe58a112
commit
fe8d8ece9c
17
src/main.rs
17
src/main.rs
|
@ -630,6 +630,11 @@ fn handle_window_event<T>(
|
||||||
event: winit::event::Event<T>,
|
event: winit::event::Event<T>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
use winit::event::*;
|
use winit::event::*;
|
||||||
|
let cursor_grab_mode = if cfg!(target_os = "macos") {
|
||||||
|
winit::window::CursorGrabMode::Locked
|
||||||
|
} else {
|
||||||
|
winit::window::CursorGrabMode::Confined
|
||||||
|
};
|
||||||
match event {
|
match event {
|
||||||
Event::MainEventsCleared => return true,
|
Event::MainEventsCleared => return true,
|
||||||
Event::DeviceEvent {
|
Event::DeviceEvent {
|
||||||
|
@ -659,9 +664,7 @@ fn handle_window_event<T>(
|
||||||
use std::f64::consts::PI;
|
use std::f64::consts::PI;
|
||||||
|
|
||||||
if game.focused {
|
if game.focused {
|
||||||
window
|
window.set_cursor_grab(cursor_grab_mode).unwrap();
|
||||||
.set_cursor_grab(winit::window::CursorGrabMode::Locked)
|
|
||||||
.unwrap();
|
|
||||||
window.set_cursor_visible(false);
|
window.set_cursor_visible(false);
|
||||||
if let Some(player) = game.server.player {
|
if let Some(player) = game.server.player {
|
||||||
let rotation = game
|
let rotation = game
|
||||||
|
@ -719,9 +722,7 @@ fn handle_window_event<T>(
|
||||||
&& !game.screen_sys.is_current_closable()
|
&& !game.screen_sys.is_current_closable()
|
||||||
{
|
{
|
||||||
game.focused = true;
|
game.focused = true;
|
||||||
window
|
window.set_cursor_grab(cursor_grab_mode).unwrap();
|
||||||
.set_cursor_grab(winit::window::CursorGrabMode::Locked)
|
|
||||||
.unwrap();
|
|
||||||
window.set_cursor_visible(false);
|
window.set_cursor_visible(false);
|
||||||
} else if !game.focused {
|
} else if !game.focused {
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
@ -783,9 +784,7 @@ fn handle_window_event<T>(
|
||||||
screen::SettingsMenu::new(game.vars.clone(), true),
|
screen::SettingsMenu::new(game.vars.clone(), true),
|
||||||
));
|
));
|
||||||
} else if game.screen_sys.is_current_closable() {
|
} else if game.screen_sys.is_current_closable() {
|
||||||
window
|
window.set_cursor_grab(cursor_grab_mode).unwrap();
|
||||||
.set_cursor_grab(winit::window::CursorGrabMode::Locked)
|
|
||||||
.unwrap();
|
|
||||||
window.set_cursor_visible(false);
|
window.set_cursor_visible(false);
|
||||||
game.focused = true;
|
game.focused = true;
|
||||||
game.screen_sys.pop_screen();
|
game.screen_sys.pop_screen();
|
||||||
|
|
Loading…
Reference in New Issue