feat: avoid tooltip creation if there is an existing popup
This commit is contained in:
parent
40748c3037
commit
8b5d5ee45c
4 changed files with 78 additions and 66 deletions
|
|
@ -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::<Box<dyn Fn(&mut T) -> 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::<Box<dyn Fn(&mut T) -> 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::<Box<
|
||||
|
|
@ -165,11 +165,11 @@ where
|
|||
}
|
||||
SurfaceMessage::Subsurface(settings, view) => {
|
||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||
.ok()
|
||||
.and_then(|s| s.downcast::<Box<dyn Fn() -> 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::<Box<dyn Fn() -> 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::<Box<
|
||||
|
|
@ -197,11 +197,11 @@ where
|
|||
}
|
||||
SurfaceMessage::AppPopup(settings, view) => {
|
||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||
.ok()
|
||||
.and_then(|s| s.downcast::<Box<dyn Fn(&mut T) -> 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::<Box<dyn Fn(&mut T) -> 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::<Box<
|
||||
|
|
@ -245,11 +245,11 @@ where
|
|||
}
|
||||
SurfaceMessage::Popup(settings, view) => {
|
||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||
.ok()
|
||||
.and_then(|s| s.downcast::<Box<dyn Fn() -> 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::<Box<dyn Fn() -> 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::<Box<
|
||||
|
|
@ -274,6 +274,7 @@ where
|
|||
iced_winit::commands::popup::get_popup(settings())
|
||||
}
|
||||
}
|
||||
SurfaceMessage::Ignore => iced::Task::none(),
|
||||
}
|
||||
#[cfg(not(feature = "wayland"))]
|
||||
iced::Task::none()
|
||||
|
|
|
|||
|
|
@ -238,8 +238,9 @@ impl Context {
|
|||
&self,
|
||||
content: impl Into<Element<'a, Message>>,
|
||||
tooltip: impl Into<Cow<'static, str>>,
|
||||
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<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<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<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<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,
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue