diff --git a/CHANGELOG.md b/CHANGELOG.md index 60ab815..2a8e36a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- When multiple windows are open, windows now properly close fully without + requiring that all windows are closed. + ## v0.3.0 (2024-07-15) ### Added diff --git a/src/lib.rs b/src/lib.rs index 3b2ac27..63d8731 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -474,7 +474,9 @@ impl Windows { fn close(&self, window: WindowId) -> bool { let mut data = self.data.lock().unwrap_or_else(PoisonError::into_inner); - data.remove(&window); + if let Some(closed) = data.remove(&window) { + closed.winit.close(); + } data.is_empty() } } diff --git a/src/private.rs b/src/private.rs index 47fe587..7018d23 100644 --- a/src/private.rs +++ b/src/private.rs @@ -38,6 +38,10 @@ impl OpenedWindow { .unwrap_or_else(PoisonError::into_inner) .clone() } + + pub(crate) fn close(&self) { + *self.0.lock().unwrap_or_else(PoisonError::into_inner) = None; + } } pub enum EventLoopMessage diff --git a/src/window.rs b/src/window.rs index c5c7d53..e0647be 100644 --- a/src/window.rs +++ b/src/window.rs @@ -221,7 +221,8 @@ where let (sender, receiver) = mpsc::sync_channel(65536); let sender = Arc::new(sender); let app = self.owner.as_application().app(); - let show_after_init = self.attributes.delay_visible && std::mem::replace(&mut self.attributes.visible, false); + let show_after_init = + self.attributes.delay_visible && std::mem::replace(&mut self.attributes.visible, false); let Some(winit) = self.owner.as_application_mut().open( self.attributes, sender.clone(), @@ -464,7 +465,7 @@ where behavior.redraw(&mut self); self.window.set_visible(true); } - + while !self.close { match self.process_messages_until_redraw(&mut behavior) { Ok(guard) => {