mirror of
https://github.com/lisk77/comet.git
synced 2025-12-12 17:18:50 +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::dpi::LogicalSize;
|
||||||
use winit::{
|
use winit::{
|
||||||
event::*,
|
event::*,
|
||||||
event_loop::EventLoop,
|
event_loop::{ControlFlow, EventLoop},
|
||||||
window::{Icon, Window},
|
window::{Icon, Window},
|
||||||
};
|
};
|
||||||
use winit_input_helper::WinitInputHelper as InputManager;
|
use winit_input_helper::WinitInputHelper as InputManager;
|
||||||
|
|
@ -349,27 +349,18 @@ impl App {
|
||||||
setup(&mut self, &mut renderer);
|
setup(&mut self, &mut renderer);
|
||||||
|
|
||||||
let mut time_stack = 0.0;
|
let mut time_stack = 0.0;
|
||||||
|
let mut window_focused = true;
|
||||||
|
let mut window_occluded = false;
|
||||||
|
|
||||||
info!("Starting event loop!");
|
info!("Starting event loop!");
|
||||||
event_loop
|
event_loop
|
||||||
.run(|event, elwt| {
|
.run(|event, elwt| {
|
||||||
self.delta_time = renderer.update();
|
|
||||||
|
|
||||||
if self.should_quit {
|
if self.should_quit {
|
||||||
elwt.exit()
|
elwt.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.input_manager.update(&event);
|
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)]
|
#[allow(unused_variables)]
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
|
|
@ -377,6 +368,18 @@ impl App {
|
||||||
window_id,
|
window_id,
|
||||||
} => match event {
|
} => match event {
|
||||||
WindowEvent::CloseRequested {} => elwt.exit(),
|
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) => {
|
WindowEvent::Resized(physical_size) => {
|
||||||
renderer.resize(*physical_size);
|
renderer.resize(*physical_size);
|
||||||
}
|
}
|
||||||
|
|
@ -384,11 +387,12 @@ impl App {
|
||||||
renderer.set_scale_factor(*scale_factor);
|
renderer.set_scale_factor(*scale_factor);
|
||||||
}
|
}
|
||||||
WindowEvent::RedrawRequested => {
|
WindowEvent::RedrawRequested => {
|
||||||
window.request_redraw();
|
if window_focused && !window_occluded {
|
||||||
match renderer.render() {
|
match renderer.render() {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(
|
Err(
|
||||||
wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated,
|
wgpu::SurfaceError::Lost
|
||||||
|
| wgpu::SurfaceError::Outdated,
|
||||||
) => {
|
) => {
|
||||||
let size = renderer.size();
|
let size = renderer.size();
|
||||||
renderer.resize(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