support hiding tray icons

This commit is contained in:
André Silva
2025-11-26 16:29:35 +00:00
parent 161367d961
commit bbb7f37761
5 changed files with 43 additions and 12 deletions
+11 -3
View File
@@ -156,15 +156,23 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
* I still haven't found a way for it to pick from theme automatically, although
* it might be my theme.
*/
std::string icon_id = id;
if (id == "chrome_status_icon_1") {
Glib::VariantBase value;
this->proxy_->get_cached_property(value, "ToolTip");
tooltip = get_variant<ToolTip>(value);
if (!tooltip.text.empty()) {
setCustomIcon(tooltip.text.lowercase());
icon_id = tooltip.text.lowercase();
setCustomIcon(icon_id);
}
} else {
setCustomIcon(id);
setCustomIcon(icon_id);
}
// Check if this item should be hidden
if (IconManager::instance().isHidden(icon_id)) {
spdlog::debug("Hiding tray item with ID: {}", icon_id);
is_hidden_ = true;
}
} else if (name == "Title") {
title = get_variant<std::string>(value);
@@ -214,7 +222,7 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
void Item::setStatus(const Glib::ustring& value) {
Glib::ustring lower = value.lowercase();
event_box.set_visible(show_passive_ || lower.compare("passive") != 0);
event_box.set_visible(!is_hidden_ && (show_passive_ || lower.compare("passive") != 0));
auto style = event_box.get_style_context();
for (const auto& class_name : style->list_classes()) {
+8 -4
View File
@@ -8,11 +8,18 @@
namespace waybar::modules::SNI {
static void initIconsConfig(const Json::Value& config) {
if (config["icons"].isObject()) {
IconManager::instance().setIconsConfig(config["icons"]);
}
}
Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
: AModule(config, "tray", id),
box_(bar.orientation, 0),
watcher_(SNI::Watcher::getInstance()),
host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1),
host_((initIconsConfig(config), nb_hosts_), config, bar,
std::bind(&Tray::onAdd, this, std::placeholders::_1),
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
box_.set_name("tray");
event_box_.add(box_);
@@ -27,9 +34,6 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
show_passive_ = config["show-passive-items"].asBool();
}
nb_hosts_ += 1;
if (config_["icons"].isObject()) {
IconManager::instance().setIconsConfig(config_["icons"]);
}
dp.emit();
}