fix: surface cleanup

Clean up surfaces before processing the dialog result message
This commit is contained in:
Ashley Wulber 2025-11-17 20:17:30 -05:00
parent 2c7d06c980
commit b571f11b92
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820

View file

@ -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<M: Send + 'static> Dialog<M> {
.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::<M>(id).discard());
}
SurfaceIdWrapper::LayerSurface(id) => {
tasks.push(iced_winit::wayland::commands::layer_surface::destroy_layer_surface::<M>(id).discard());
}
SurfaceIdWrapper::Popup(id) => {
tasks.push(
iced_winit::wayland::commands::popup::destroy_popup::<M>(id)
.discard(),
);
}
SurfaceIdWrapper::Subsurface(id) => {
tasks.push(
iced_winit::wayland::commands::subsurface::destroy_subsurface::<M>(
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) }),