close all windows if the main window is destroyed
This commit is contained in:
parent
c4bb321ed1
commit
373c9365e8
1 changed files with 15 additions and 3 deletions
|
@ -13,6 +13,12 @@ pub mod ctx;
|
|||
struct WindowContext<'window> {
|
||||
window: Arc<Window>,
|
||||
ctx: WgpuCtx<'window>,
|
||||
main_window: bool
|
||||
}
|
||||
impl WindowContext<'_> {
|
||||
pub fn is_main_window(&self) -> bool {
|
||||
self.main_window
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -36,6 +42,7 @@ impl ApplicationHandler for App<'_> {
|
|||
WindowContext {
|
||||
window,
|
||||
ctx: wgpu_ctx,
|
||||
main_window: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -50,12 +57,10 @@ impl ApplicationHandler for App<'_> {
|
|||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
if let Some(window_context) = self.windows.remove(&window_id) {
|
||||
|
||||
drop(window_context);
|
||||
debug!("Window: {:?} closed, exiting", window_id);
|
||||
}
|
||||
if self.windows.is_empty() {
|
||||
event_loop.exit();
|
||||
}
|
||||
}
|
||||
WindowEvent::KeyboardInput {
|
||||
device_id,
|
||||
|
@ -97,6 +102,7 @@ impl ApplicationHandler for App<'_> {
|
|||
WindowContext {
|
||||
window: new_window,
|
||||
ctx: wgpu_ctx,
|
||||
main_window: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -119,6 +125,12 @@ impl ApplicationHandler for App<'_> {
|
|||
debug!("Window resized to {:?}", size_str);
|
||||
}
|
||||
}
|
||||
WindowEvent::Destroyed => {
|
||||
if !self.windows.iter().any(|(_,ctx)| ctx.is_main_window()) || self.windows.is_empty() {
|
||||
self.windows.clear();
|
||||
event_loop.exit();
|
||||
}
|
||||
}
|
||||
_ => trace!("Unhandled window event"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue