diff --git a/examples/applet/src/window.rs b/examples/applet/src/window.rs index eb372f15..ca023729 100644 --- a/examples/applet/src/window.rs +++ b/examples/applet/src/window.rs @@ -210,7 +210,10 @@ impl cosmic::Application for Window { }, ); - self.core.applet.applet_tooltip(btn, "test").into() + self.core + .applet + .applet_tooltip(btn, "test", self.popup.is_some()) + .into() } fn view_window(&self, _id: Id) -> Element { diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index 713cda7d..7f48326e 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -132,11 +132,11 @@ where match surface_message { SurfaceMessage::AppSubsurface(settings, view) => { let Some(settings) = std::sync::Arc::try_unwrap(settings) - .ok() - .and_then(|s| s.downcast:: iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync>>().ok()) else { - tracing::error!("Invalid settings for subsurface"); - return Task::none(); - }; + .ok() + .and_then(|s| s.downcast:: iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync>>().ok()) else { + tracing::error!("Invalid settings for subsurface"); + return Task::none(); + }; if let Some(view) = view.and_then(|view| { match std::sync::Arc::try_unwrap(view).ok()?.downcast:: { let Some(settings) = std::sync::Arc::try_unwrap(settings) - .ok() - .and_then(|s| s.downcast:: iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync>>().ok()) else { - tracing::error!("Invalid settings for subsurface"); - return Task::none(); - }; + .ok() + .and_then(|s| s.downcast:: iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync>>().ok()) else { + tracing::error!("Invalid settings for subsurface"); + return Task::none(); + }; if let Some(view) = view.and_then(|view| { match std::sync::Arc::try_unwrap(view).ok()?.downcast:: { let Some(settings) = std::sync::Arc::try_unwrap(settings) - .ok() - .and_then(|s| s.downcast:: iced_runtime::platform_specific::wayland::popup::SctkPopupSettings + Send + Sync>>().ok()) else { - tracing::error!("Invalid settings for popup"); - return Task::none(); - }; + .ok() + .and_then(|s| s.downcast:: iced_runtime::platform_specific::wayland::popup::SctkPopupSettings + Send + Sync>>().ok()) else { + tracing::error!("Invalid settings for popup"); + return Task::none(); + }; if let Some(view) = view.and_then(|view| { match std::sync::Arc::try_unwrap(view).ok()?.downcast:: { let Some(settings) = std::sync::Arc::try_unwrap(settings) - .ok() - .and_then(|s| s.downcast:: iced_runtime::platform_specific::wayland::popup::SctkPopupSettings + Send + Sync>>().ok()) else { - tracing::error!("Invalid settings for popup"); - return Task::none(); - }; + .ok() + .and_then(|s| s.downcast:: iced_runtime::platform_specific::wayland::popup::SctkPopupSettings + Send + Sync>>().ok()) else { + tracing::error!("Invalid settings for popup"); + return Task::none(); + }; if let Some(view) = view.and_then(|view| { match std::sync::Arc::try_unwrap(view).ok()?.downcast:: iced::Task::none(), } #[cfg(not(feature = "wayland"))] iced::Task::none() diff --git a/src/applet/mod.rs b/src/applet/mod.rs index 3f5168df..d267ec53 100644 --- a/src/applet/mod.rs +++ b/src/applet/mod.rs @@ -238,8 +238,9 @@ impl Context { &self, content: impl Into>, tooltip: impl Into>, + has_popup: bool, ) -> crate::widget::wayland::tooltip::widget::Tooltip<'a, Message> { - let window_id = TOOLTIP_WINDOW_ID.clone(); + let window_id = *TOOLTIP_WINDOW_ID; let subsurface_id = TOOLTIP_ID.clone(); let anchor = self.anchor; let tooltip = tooltip.into(); @@ -254,50 +255,53 @@ impl Context { PanelAnchor::Top => (Anchor::Bottom, Gravity::Bottom), PanelAnchor::Bottom => (Anchor::Top, Gravity::Top), }; - - crate::app::message::simple_popup::< - Message, - Option< - Box< - dyn Fn() -> crate::Element<'static, crate::app::Message> - + Send - + Sync - + 'static, + if has_popup { + SurfaceMessage::Ignore.into() + } else { + crate::app::message::simple_popup::< + Message, + Option< + Box< + dyn Fn() -> crate::Element<'static, crate::app::Message> + + Send + + Sync + + 'static, + >, >, - >, - >( - move || SctkPopupSettings { - parent: window::Id::RESERVED, - id: window_id, - grab: false, - input_zone: Some(Rectangle::default()), - positioner: SctkPositioner { - size: None, - size_limits: Limits::NONE.min_width(1.).min_height(1.), - anchor_rect: Rectangle { - x: bounds.x.round() as i32, - y: bounds.y.round() as i32, - width: bounds.width.round() as i32, - height: bounds.height.round() as i32, + >( + move || SctkPopupSettings { + parent: window::Id::RESERVED, + id: window_id, + grab: false, + input_zone: Some(Rectangle::default()), + positioner: SctkPositioner { + size: None, + size_limits: Limits::NONE.min_width(1.).min_height(1.), + anchor_rect: Rectangle { + x: bounds.x.round() as i32, + y: bounds.y.round() as i32, + width: bounds.width.round() as i32, + height: bounds.height.round() as i32, + }, + anchor: popup_anchor, + gravity, + constraint_adjustment: 15, + offset: (0, 0), + reactive: true, }, - anchor: popup_anchor, - gravity, - constraint_adjustment: 15, - offset: (0, 0), - reactive: true, + parent_size: None, + close_with_children: true, }, - parent_size: None, - close_with_children: true, - }, - Some(Box::new(move || { - Element::<'static, crate::app::Message>::from(autosize::autosize( - layer_container(crate::widget::text(tooltip.clone())) - .layer(crate::cosmic_theme::Layer::Background) - .padding(4.), - subsurface_id.clone(), - )) - })), - ) + Some(Box::new(move || { + Element::<'static, crate::app::Message>::from(autosize::autosize( + layer_container(crate::widget::text(tooltip.clone())) + .layer(crate::cosmic_theme::Layer::Background) + .padding(4.), + subsurface_id.clone(), + )) + })), + ) + } }; crate::widget::wayland::tooltip::widget::Tooltip::new( content, diff --git a/src/surface_message.rs b/src/surface_message.rs index a54b81df..754d4cf9 100644 --- a/src/surface_message.rs +++ b/src/surface_message.rs @@ -50,14 +50,17 @@ pub enum SurfaceMessage { /// Requested Full Size for expanded menu bar size: Size, }, + Ignore, } impl std::fmt::Debug for SurfaceMessage { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::AppSubsurface(arg0, arg1) => { - f.debug_tuple("Subsurface").field(arg0).field(arg1).finish() - } + Self::AppSubsurface(arg0, arg1) => f + .debug_tuple("AppSubsurface") + .field(arg0) + .field(arg1) + .finish(), Self::Subsurface(arg0, arg1) => { f.debug_tuple("Subsurface").field(arg0).field(arg1).finish() } @@ -79,6 +82,7 @@ impl std::fmt::Debug for SurfaceMessage { .field("limits", limits) .field("size", size) .finish(), + Self::Ignore => write!(f, "Ignore"), } } }