Skip to content

Commit

Permalink
fix: un-hide tray when new icons are added
Browse files Browse the repository at this point in the history
  • Loading branch information
Bahnschrift committed Dec 19, 2024
1 parent 622f22d commit cf64b2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/modules/sni/tray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Tray : public AModule {
void onRemove(std::unique_ptr<Item>& item);

static inline std::size_t nb_hosts_ = 0;
bool show_passive_ = false;
Gtk::Box box_;
SNI::Watcher::singleton watcher_;
SNI::Host host_;
Expand Down
13 changes: 11 additions & 2 deletions src/modules/sni/tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -42,8 +45,14 @@ void Tray::onRemove(std::unique_ptr<Item>& item) {
auto Tray::update() -> void {
// Show tray only when items are available
std::vector<Gtk::Widget*> 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();
}
Expand Down

0 comments on commit cf64b2c

Please sign in to comment.