From e9b7bdad20d5663755b697a89cfa373be1030e2c Mon Sep 17 00:00:00 2001 From: Vyacheslav Ananev Date: Sun, 5 May 2024 22:16:41 +0700 Subject: [PATCH 1/3] systray: add property --- crates/eww/src/widgets/systray.rs | 17 +++++++++++++++-- crates/eww/src/widgets/widget_definitions.rs | 7 ++++++- 2 files changed, 21 insertions(+), 3 deletions(-) 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..5cf1034a 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 @@ -1218,7 +1219,11 @@ fn build_systray(bargs: &mut BuilderArgs) -> Result { }, // @prop prepend-new - prepend new icons. prop(prepend_new: as_bool = true) { - *props_clone2.prepend_new.borrow_mut() = prepend_new; + *props_clone2.clone().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.clone().visible_empty.borrow_mut() = visible_empty; }, }); From 4a529de019685853ec476743e7a2c51c68ace5e3 Mon Sep 17 00:00:00 2001 From: Vyacheslav Ananev Date: Sun, 5 May 2024 22:25:22 +0700 Subject: [PATCH 2/3] systray: refactor --- crates/eww/src/widgets/widget_definitions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index 5cf1034a..3ecb8165 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -1219,11 +1219,11 @@ fn build_systray(bargs: &mut BuilderArgs) -> Result { }, // @prop prepend-new - prepend new icons. prop(prepend_new: as_bool = true) { - *props_clone2.clone().prepend_new.borrow_mut() = prepend_new; + *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.clone().visible_empty.borrow_mut() = visible_empty; + *props_clone3.visible_empty.borrow_mut() = visible_empty; }, }); From 8ee7e3ecbc6b35d94038d2ac74f002c6af05bca5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Ananev Date: Sun, 5 May 2024 22:28:55 +0700 Subject: [PATCH 3/3] add info to CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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)