diff --git a/src/dialog.rs b/src/dialog.rs index 053d8d5..8ed71cc 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -14,6 +14,7 @@ use cosmic::{ stream, window, }, iced_core::widget::operation, + iced_winit::{self, SurfaceIdWrapper}, theme, widget::{ self, Operation, @@ -368,7 +369,43 @@ impl Dialog { .map(DialogMessage) .map(move |message| cosmic::action::app(mapper(message))); if let Some(result) = self.cosmic.app.result_opt.take() { + if !self.cosmic.surface_views.is_empty() { + log::debug!("waiting for surfaces to close..."); + let mut tasks = Vec::new(); + for id in self.cosmic.surface_views.drain() { + match id.1.1 { + SurfaceIdWrapper::Window(id) => { + tasks.push(window::close::(id).discard()); + } + SurfaceIdWrapper::LayerSurface(id) => { + tasks.push(iced_winit::wayland::commands::layer_surface::destroy_layer_surface::(id).discard()); + } + SurfaceIdWrapper::Popup(id) => { + tasks.push( + iced_winit::wayland::commands::popup::destroy_popup::(id) + .discard(), + ); + } + SurfaceIdWrapper::Subsurface(id) => { + tasks.push( + iced_winit::wayland::commands::subsurface::destroy_subsurface::( + id, + ) + .discard(), + ); + } + _ => {} + } + } + let on_result_message = (self.on_result)(result); + + tasks.push(Task::future(async move { + cosmic::action::app(on_result_message) + })); + return Task::batch(tasks); + } let on_result_message = (self.on_result)(result); + Task::batch([ command, Task::future(async move { cosmic::action::app(on_result_message) }), @@ -388,6 +425,10 @@ impl Dialog { pub const fn window_id(&self) -> window::Id { self.cosmic.app.flags.window_id } + + pub fn contains_surface(&self, id: &window::Id) -> bool { + self.cosmic.surface_views.contains_key(id) + } } #[derive(Clone, Debug)]