diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index 42ae122b..c53bb6a6 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -93,6 +93,7 @@ pub struct Cosmic { ), >, pub tracked_windows: HashSet, + pub opened_surfaces: HashMap, } impl Cosmic @@ -161,6 +162,7 @@ where } }) { let settings = settings(&mut self.app); + self.get_subsurface(settings, *view) } else { iced_winit::commands::subsurface::get_subsurface(settings(&mut self.app)) @@ -188,6 +190,7 @@ where } }) { let settings = settings(); + self.get_subsurface(settings, Box::new(move |_| view())) } else { iced_winit::commands::subsurface::get_subsurface(settings()) @@ -292,6 +295,8 @@ where } }) { let settings = settings(&mut self.app); + self.tracked_windows.insert(id); + self.get_window(id, settings, *view) } else { let settings = settings(&mut self.app); @@ -327,6 +332,8 @@ where } }) { let settings = settings(); + self.tracked_windows.insert(id); + self.get_window(id, settings, Box::new(move |_| view())) } else { let settings = settings(); @@ -1035,9 +1042,15 @@ impl Cosmic { Action::Surface(action) => return self.surface_update(action), Action::SurfaceClosed(id) => { - #[cfg(feature = "wayland")] - self.surface_views.remove(&id); - self.tracked_windows.remove(&id); + if self.opened_surfaces.get_mut(&id).is_some_and(|v| { + *v = v.saturating_sub(1); + *v == 0 + }) { + self.opened_surfaces.remove(&id); + #[cfg(feature = "wayland")] + self.surface_views.remove(&id); + self.tracked_windows.remove(&id); + } let mut ret = if let Some(msg) = self.app.on_close_requested(id) { self.app.update(msg) @@ -1201,7 +1214,6 @@ impl Cosmic { core.applet.suggested_bounds = b; } Action::Opened(id) => { - self.tracked_windows.insert(id); #[cfg(feature = "wayland")] if self.app.core().sync_window_border_radii_to_theme() { use iced_runtime::platform_specific::wayland::CornerRadius; @@ -1254,6 +1266,7 @@ impl Cosmic { #[cfg(feature = "wayland")] surface_views: HashMap::new(), tracked_windows: HashSet::new(), + opened_surfaces: HashMap::new(), } } @@ -1268,6 +1281,7 @@ impl Cosmic { ) -> Task> { use iced_winit::commands::subsurface::get_subsurface; + *self.opened_surfaces.entry(settings.id).or_insert_with(|| 0) += 1; self.surface_views.insert( settings.id, ( @@ -1289,7 +1303,7 @@ impl Cosmic { >, ) -> Task> { use iced_winit::commands::popup::get_popup; - + *self.opened_surfaces.entry(settings.id).or_insert_with(|| 0) += 1; self.surface_views.insert( settings.id, ( @@ -1312,7 +1326,7 @@ impl Cosmic { >, ) -> Task> { use iced_winit::SurfaceIdWrapper; - + *self.opened_surfaces.entry(id.clone()).or_insert_with(|| 0) += 1; self.surface_views.insert( id.clone(), (