From 622f22d6b59da9bfbfabb9e9f70fa2c520ffad86 Mon Sep 17 00:00:00 2001 From: Bahnschrift Date: Thu, 19 Dec 2024 12:09:31 +1100 Subject: [PATCH 1/2] fix: hide tray when there are no non-passive icons --- src/modules/sni/tray.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/sni/tray.cpp b/src/modules/sni/tray.cpp index a2c56808..f194c1d9 100644 --- a/src/modules/sni/tray.cpp +++ b/src/modules/sni/tray.cpp @@ -2,6 +2,8 @@ #include +#include + namespace waybar::modules::SNI { Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config) @@ -39,7 +41,9 @@ void Tray::onRemove(std::unique_ptr& item) { auto Tray::update() -> void { // Show tray only when items are available - event_box_.set_visible(!box_.get_children().empty()); + std::vector children = box_.get_children(); + event_box_.set_visible(std::any_of(children.begin(), children.end(), + [](Gtk::Widget* child) { return child->get_visible(); })); // Call parent update AModule::update(); } From cf64b2c88c2c2184cb3690668bd678a9f0853c15 Mon Sep 17 00:00:00 2001 From: Bahnschrift Date: Thu, 19 Dec 2024 12:29:58 +1100 Subject: [PATCH 2/2] fix: un-hide tray when new icons are added --- include/modules/sni/tray.hpp | 1 + src/modules/sni/tray.cpp | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/modules/sni/tray.hpp b/include/modules/sni/tray.hpp index 6cda35d7..5f12d7f2 100644 --- a/include/modules/sni/tray.hpp +++ b/include/modules/sni/tray.hpp @@ -21,6 +21,7 @@ class Tray : public AModule { void onRemove(std::unique_ptr& item); static inline std::size_t nb_hosts_ = 0; + bool show_passive_ = false; Gtk::Box box_; SNI::Watcher::singleton watcher_; SNI::Host host_; diff --git a/src/modules/sni/tray.cpp b/src/modules/sni/tray.cpp index f194c1d9..33827145 100644 --- a/src/modules/sni/tray.cpp +++ b/src/modules/sni/tray.cpp @@ -21,6 +21,9 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config) if (config_["spacing"].isUInt()) { box_.set_spacing(config_["spacing"].asUInt()); } + if (config["show-passive-items"].isBool()) { + show_passive_ = config["show-passive-items"].asBool(); + } nb_hosts_ += 1; dp.emit(); } @@ -42,8 +45,14 @@ void Tray::onRemove(std::unique_ptr& item) { auto Tray::update() -> void { // Show tray only when items are available std::vector children = box_.get_children(); - event_box_.set_visible(std::any_of(children.begin(), children.end(), - [](Gtk::Widget* child) { return child->get_visible(); })); + if (show_passive_) { + event_box_.set_visible(!children.empty()); + } else { + event_box_.set_visible(!std::all_of(children.begin(), children.end(), [](Gtk::Widget* child) { + return child->get_style_context()->has_class("passive"); + })); + } + // Call parent update AModule::update(); }