diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f5a6f1b..87634b6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,12 @@ All notable changes to eww will be listed here, starting at changes since versio ### Fixes - Fix and refactor nix flake (By: w-lfchen) +- Fix deleting items from tray (By: vnva) ### Features - Add `:truncate` property to labels, disabled by default (except in cases where truncation would be enabled in version `0.5.0` and before) (By: Rayzeq). - Add support for `:hover` css selectors for tray items (By: zeapoz) +- Add `:visible-empty` property for `systray` widget (By: vnva) ## [0.6.0] (21.04.2024) diff --git a/crates/eww/src/widgets/systray.rs b/crates/eww/src/widgets/systray.rs index cf06907e..801b1d0e 100644 --- a/crates/eww/src/widgets/systray.rs +++ b/crates/eww/src/widgets/systray.rs @@ -34,12 +34,13 @@ fn run_async_task(f: F) -> F::Output { pub struct Props { icon_size_tx: tokio::sync::watch::Sender, pub prepend_new: Rc>, + pub visible_empty: Rc>, } impl Props { pub fn new() -> Self { let (icon_size_tx, _) = tokio::sync::watch::channel(24); - Self { icon_size_tx, prepend_new: Rc::new(RefCell::new(false)) } + Self { icon_size_tx, prepend_new: Rc::new(RefCell::new(false)), visible_empty: Rc::new(RefCell::new(true)) } } pub fn icon_size(&self, value: i32) { @@ -60,6 +61,7 @@ struct Tray { icon_size: tokio::sync::watch::Receiver, prepend_new: Rc>, + visible_empty: Rc>, } pub fn spawn_systray(container: >k::Box, props: &Props) { @@ -68,6 +70,7 @@ pub fn spawn_systray(container: >k::Box, props: &Props) { items: Default::default(), icon_size: props.icon_size_tx.subscribe(), prepend_new: props.prepend_new.clone(), + visible_empty: props.visible_empty.clone(), }; let task = glib::MainContext::default().spawn_local(async move { @@ -79,7 +82,10 @@ pub fn spawn_systray(container: >k::Box, props: &Props) { } }; - systray.container.show(); + if !*systray.visible_empty.borrow() { + systray.container.hide(); + } + let e = notifier_host::run_host(&mut systray, &s.snw).await; log::error!("notifier host error: {}", e); }); @@ -101,14 +107,21 @@ impl notifier_host::Host for Tray { if let Some(old_item) = self.items.insert(id.to_string(), item) { self.container.remove(&old_item.widget); } + if !*self.visible_empty.borrow() && !self.container.is_visible() && self.items.len() > 0 { + self.container.show(); + } } fn remove_item(&mut self, id: &str) { if let Some(item) = self.items.get(id) { self.container.remove(&item.widget); + self.items.remove(id); } else { log::warn!("Tried to remove nonexistent item {:?} from systray", id); } + if !*self.visible_empty.borrow() && self.container.is_visible() && self.items.len() == 0 { + self.container.hide(); + } } } diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index d5d97fb4..3ecb8165 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -1200,6 +1200,7 @@ fn build_systray(bargs: &mut BuilderArgs) -> Result { let props = Rc::new(systray::Props::new()); let props_clone = props.clone(); // copies for def_widget let props_clone2 = props.clone(); // copies for def_widget + let props_clone3 = props.clone(); // copies for def_widget def_widget!(bargs, _g, gtk_widget, { // @prop spacing - spacing between elements @@ -1220,6 +1221,10 @@ fn build_systray(bargs: &mut BuilderArgs) -> Result { prop(prepend_new: as_bool = true) { *props_clone2.prepend_new.borrow_mut() = prepend_new; }, + // @prop visible-empty - visibility of the widget when the systray is empty + prop(visible_empty: as_bool = true) { + *props_clone3.visible_empty.borrow_mut() = visible_empty; + }, }); systray::spawn_systray(>k_widget, &props_clone);