fix fullscreen init

This commit is contained in:
Lauri Räsänen 2023-01-24 16:54:26 +02:00
parent 0746a09c45
commit b0a7135120

View file

@ -9,10 +9,19 @@ use winit::{
pub async fn run() { pub async fn run() {
let event_loop = EventLoop::new(); let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap(); let window = WindowBuilder::new()
.with_fullscreen(Some(winit::window::Fullscreen::Borderless(None)))
.with_maximized(true)
.build(&event_loop)
.unwrap();
let mut state = State::new(&window).await; let mut state = State::new(&window).await;
let mut last_render = Instant::now(); let mut last_render = Instant::now();
window
.set_cursor_grab(winit::window::CursorGrabMode::Confined)
.unwrap();
window.set_cursor_visible(false);
// Event loop // Event loop
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
match event { match event {
@ -42,9 +51,14 @@ pub async fn run() {
state.resize(**new_inner_size); state.resize(**new_inner_size);
} }
WindowEvent::Focused(focused) => { WindowEvent::Focused(focused) => {
// window.set_cursor_grab(*focused).unwrap(); window
.set_cursor_grab(if *focused == true {
winit::window::CursorGrabMode::Confined
} else {
winit::window::CursorGrabMode::None
})
.unwrap();
window.set_cursor_visible(!*focused); window.set_cursor_visible(!*focused);
window.set_decorations(!*focused);
} }
_ => {} _ => {}
} }