diff --git a/src/dialog.rs b/src/dialog.rs index 02a6bf7..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) }),