diff --git a/src/app/common.rs b/src/app/common.rs index a5ec14f..396acb2 100644 --- a/src/app/common.rs +++ b/src/app/common.rs @@ -58,6 +58,7 @@ pub struct WindowState { pub surface_desc: wgpu::SurfaceConfiguration, pub surface: wgpu::Surface<'static>, pub hidpi_factor: f64, + pub minimized: bool, } impl WindowState { @@ -105,6 +106,7 @@ impl WindowState { surface_desc, surface, hidpi_factor, + minimized: false, } } @@ -114,9 +116,14 @@ impl WindowState { } pub fn handle_resize(&mut self, size: &PhysicalSize) { - self.surface_desc.width = size.width; - self.surface_desc.height = size.height; - self.surface.configure(&self.device, &self.surface_desc); + if size.width > 0 && size.height > 0 { + self.minimized = false; + self.surface_desc.width = size.width; + self.surface_desc.height = size.height; + self.surface.configure(&self.device, &self.surface_desc); + } else { + self.minimized = true; + } } } diff --git a/src/app/game.rs b/src/app/game.rs index 5b00c51..efbeae0 100644 --- a/src/app/game.rs +++ b/src/app/game.rs @@ -30,6 +30,7 @@ pub struct GameWindow { client: EmulatorClient, input_mapper: Arc>, proxy: EventLoopProxy, + paused_due_to_minimize: bool, } impl GameWindow { @@ -165,6 +166,7 @@ impl GameWindow { client, input_mapper, proxy, + paused_due_to_minimize: false, } } @@ -181,7 +183,9 @@ impl GameWindow { let frame = match window.surface.get_current_texture() { Ok(frame) => frame, Err(e) => { - eprintln!("dropped frame: {e:?}"); + if !self.window.minimized { + eprintln!("dropped frame: {e:?}"); + } return; } }; @@ -325,7 +329,18 @@ impl AppWindow for GameWindow { fn handle_event(&mut self, event_loop: &ActiveEventLoop, event: &Event) { match event { Event::WindowEvent { event, .. } => match event { - WindowEvent::Resized(size) => self.window.handle_resize(size), + WindowEvent::Resized(size) => { + self.window.handle_resize(size); + if self.window.minimized { + if self.client.is_running() { + self.client.send_command(EmulatorCommand::Pause); + self.paused_due_to_minimize = true; + } + } else if self.paused_due_to_minimize { + self.client.send_command(EmulatorCommand::Resume); + self.paused_due_to_minimize = false; + } + } WindowEvent::CloseRequested => event_loop.exit(), WindowEvent::RedrawRequested => self.draw(event_loop), _ => (), diff --git a/src/app/input.rs b/src/app/input.rs index bf56196..d5ffe7e 100644 --- a/src/app/input.rs +++ b/src/app/input.rs @@ -73,7 +73,9 @@ impl InputWindow { let frame = match window.surface.get_current_texture() { Ok(frame) => frame, Err(e) => { - eprintln!("dropped frame: {e:?}"); + if !self.window.minimized { + eprintln!("dropped frame: {e:?}"); + } return; } };