Merge pull request #5028 from JeremieRodon/fix/tray-hide-when-empty

fix(tray): hide module when no items are visible
This commit is contained in:
Alexis Rouillard
2026-07-03 20:58:33 +02:00
committed by GitHub
2 changed files with 4 additions and 14 deletions
-1
View File
@@ -22,7 +22,6 @@ class Tray : public AModule {
void queueUpdate(); void queueUpdate();
static inline std::size_t nb_hosts_ = 0; static inline std::size_t nb_hosts_ = 0;
bool show_passive_ = false;
Gtk::Box box_; Gtk::Box box_;
SNI::Watcher::singleton watcher_; SNI::Watcher::singleton watcher_;
SNI::Host host_; SNI::Host host_;
+4 -13
View File
@@ -24,9 +24,6 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
if (config_["spacing"].isUInt()) { if (config_["spacing"].isUInt()) {
box_.set_spacing(config_["spacing"].asUInt()); box_.set_spacing(config_["spacing"].asUInt());
} }
if (config["show-passive-items"].isBool()) {
show_passive_ = config["show-passive-items"].asBool();
}
nb_hosts_ += 1; nb_hosts_ += 1;
if (config_["icons"].isObject()) { if (config_["icons"].isObject()) {
IconManager::instance().setIconsConfig(config_["icons"]); IconManager::instance().setIconsConfig(config_["icons"]);
@@ -42,6 +39,8 @@ void Tray::onAdd(std::unique_ptr<Item>& item) {
} else { } else {
box_.pack_start(item->event_box); box_.pack_start(item->event_box);
} }
item->event_box.signal_show().connect([this] { dp.emit(); });
item->event_box.signal_hide().connect([this] { dp.emit(); });
dp.emit(); dp.emit();
} }
@@ -51,17 +50,9 @@ void Tray::onRemove(std::unique_ptr<Item>& item) {
} }
auto Tray::update() -> void { auto Tray::update() -> void {
// Show tray only when items are available
std::vector<Gtk::Widget*> children = box_.get_children(); std::vector<Gtk::Widget*> children = box_.get_children();
if (show_passive_) { event_box_.set_visible(std::any_of(children.begin(), children.end(),
event_box_.set_visible(!children.empty()); [](Gtk::Widget* child) { return child->get_visible(); }));
} 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(); AModule::update();
} }