From 66322b1e90a2b584dc8b3a23dd2af20fd552b0ae Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 27 Feb 2025 01:09:16 -0500 Subject: [PATCH] refactor: popup for tooltip this conflicts with autopopup switching. Either I need to drop autopopup switching, disable tooltips if autopopup switching is enabled, or I need to change how autohopopup switching is implemented to use dbus or wayland protocols instead of simulating a click. --- src/applet/mod.rs | 67 ++++++++++++++--------------------- src/widget/dropdown/widget.rs | 3 +- 2 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/applet/mod.rs b/src/applet/mod.rs index 0e017bd1..0b7a6fbb 100644 --- a/src/applet/mod.rs +++ b/src/applet/mod.rs @@ -20,11 +20,9 @@ use crate::{ }, Application, Element, Renderer, }; -use cctk::sctk::shell::xdg::window::WindowConfigure; pub use cosmic_panel_config; use cosmic_panel_config::{CosmicPanelBackground, PanelAnchor, PanelSize}; use cosmic_theme::Theme; -use iced::platform_specific::runtime::wayland::subsurface; use iced::Pixels; use iced_core::{Layout, Padding, Shadow}; use iced_widget::runtime::platform_specific::wayland::popup::{SctkPopupSettings, SctkPositioner}; @@ -250,38 +248,14 @@ impl Context { let subsurface_id = subsurface_id.clone(); let tooltip = tooltip.clone(); let window_id = window_id; - let (loc, gravity) = match anchor { - PanelAnchor::Left => ( - iced::Point { - x: bounds.width, - y: bounds.height / 2., - }, - Gravity::Right, - ), - PanelAnchor::Right => ( - iced::Point { - x: 0., - y: bounds.height / 2., - }, - Gravity::Left, - ), - PanelAnchor::Top => ( - iced::Point { - x: bounds.width / 2., - y: bounds.height, - }, - Gravity::Bottom, - ), - PanelAnchor::Bottom => ( - iced::Point { - x: bounds.width / 2., - y: 0., - }, - Gravity::Top, - ), + let (popup_anchor, gravity) = match anchor { + PanelAnchor::Left => (Anchor::Right, Gravity::Right), + PanelAnchor::Right => (Anchor::Left, Gravity::Left), + PanelAnchor::Top => (Anchor::Bottom, Gravity::Bottom), + PanelAnchor::Bottom => (Anchor::Top, Gravity::Top), }; - crate::app::message::simple_subsurface::< + crate::app::message::simple_popup::< Message, Option< Box< @@ -292,16 +266,28 @@ impl Context { >, >, >( - move || subsurface::SctkSubsurfaceSettings { + move || SctkPopupSettings { parent: window::Id::RESERVED, id: window_id, - loc, - size: None, - z: 1, - steal_keyboard_focus: false, - offset: (0, 0), - gravity, - input_region: Rectangle::default(), + 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, + }, + parent_size: None, + close_with_children: true, }, Some(Box::new(move || { Element::<'static, crate::app::Message>::from(autosize::autosize( @@ -405,6 +391,7 @@ impl Context { parent_size: None, grab: true, close_with_children: false, + input_zone: None, } } diff --git a/src/widget/dropdown/widget.rs b/src/widget/dropdown/widget.rs index eb62150d..7a0130cc 100644 --- a/src/widget/dropdown/widget.rs +++ b/src/widget/dropdown/widget.rs @@ -524,6 +524,7 @@ pub fn update< SctkPopupSettings { parent, id, + input_zone: None, positioner: SctkPositioner { size: Some((selections_width as u32 + gap as u32 + pad_width as u32 + icon_width as u32, 10)), anchor_rect, @@ -534,7 +535,7 @@ pub fn update< }, parent_size: None, grab: true, - close_with_children: true + close_with_children: true, }, Arc::new(move || { Element::from(