Fixing multiwindow close behavior

This commit is contained in:
Jonathan Johnson 2024-08-28 08:42:39 -07:00
parent d0af8bb4e0
commit ea1c0975dc
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
4 changed files with 17 additions and 3 deletions

View file

@ -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

View file

@ -474,7 +474,9 @@ impl<Message> Windows<Message> {
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()
}
}

View file

@ -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<AppMessage>

View file

@ -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) => {