mirror of
https://github.com/lisk77/comet.git
synced 2025-12-12 09:08:49 +00:00
fix(app): winit doesnt induce 'not responding' on minimization anymore
This commit is contained in:
parent
bf7f0bebe9
commit
d37351fbc5
1 changed files with 49 additions and 27 deletions
|
|
@ -9,7 +9,7 @@ use std::sync::Arc;
|
|||
use winit::dpi::LogicalSize;
|
||||
use winit::{
|
||||
event::*,
|
||||
event_loop::EventLoop,
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
window::{Icon, Window},
|
||||
};
|
||||
use winit_input_helper::WinitInputHelper as InputManager;
|
||||
|
|
@ -349,27 +349,18 @@ impl App {
|
|||
setup(&mut self, &mut renderer);
|
||||
|
||||
let mut time_stack = 0.0;
|
||||
let mut window_focused = true;
|
||||
let mut window_occluded = false;
|
||||
|
||||
info!("Starting event loop!");
|
||||
event_loop
|
||||
.run(|event, elwt| {
|
||||
self.delta_time = renderer.update();
|
||||
|
||||
if self.should_quit {
|
||||
elwt.exit()
|
||||
}
|
||||
|
||||
self.input_manager.update(&event);
|
||||
|
||||
if self.dt() != f32::INFINITY {
|
||||
time_stack += self.delta_time;
|
||||
while time_stack > self.update_timer {
|
||||
let time = self.dt();
|
||||
update(&mut self, &mut renderer, time);
|
||||
time_stack -= self.update_timer;
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
|
|
@ -377,6 +368,18 @@ impl App {
|
|||
window_id,
|
||||
} => match event {
|
||||
WindowEvent::CloseRequested {} => elwt.exit(),
|
||||
WindowEvent::Focused(focused) => {
|
||||
window_focused = *focused;
|
||||
if window_focused && !window_occluded {
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
WindowEvent::Occluded(occluded) => {
|
||||
window_occluded = *occluded;
|
||||
if window_focused && !window_occluded {
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
WindowEvent::Resized(physical_size) => {
|
||||
renderer.resize(*physical_size);
|
||||
}
|
||||
|
|
@ -384,11 +387,12 @@ impl App {
|
|||
renderer.set_scale_factor(*scale_factor);
|
||||
}
|
||||
WindowEvent::RedrawRequested => {
|
||||
window.request_redraw();
|
||||
if window_focused && !window_occluded {
|
||||
match renderer.render() {
|
||||
Ok(_) => {}
|
||||
Err(
|
||||
wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated,
|
||||
wgpu::SurfaceError::Lost
|
||||
| wgpu::SurfaceError::Outdated,
|
||||
) => {
|
||||
let size = renderer.size();
|
||||
renderer.resize(size);
|
||||
|
|
@ -402,8 +406,26 @@ impl App {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Event::AboutToWait => {
|
||||
elwt.set_control_flow(ControlFlow::Poll);
|
||||
self.delta_time = renderer.update();
|
||||
|
||||
if self.dt() != f32::INFINITY {
|
||||
time_stack += self.delta_time;
|
||||
while time_stack > self.update_timer {
|
||||
let time = self.dt();
|
||||
update(&mut self, &mut renderer, time);
|
||||
time_stack -= self.update_timer;
|
||||
}
|
||||
}
|
||||
|
||||
if window_focused && !window_occluded {
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue