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
+10 -1
View File
@@ -5,6 +5,7 @@
#include <string>
#include <unordered_map>
#include <unordered_set>
class IconManager {
public:
@@ -19,7 +20,10 @@ class IconManager {
std::string app_name = key;
const Json::Value& icon_value = icons_config[key];
if (icon_value.isString()) {
if (icon_value.isBool() && !icon_value.asBool()) {
// false value means hide this app
hidden_apps_.insert(app_name);
} else if (icon_value.isString()) {
std::string icon_path = icon_value.asString();
icons_map_[app_name] = icon_path;
}
@@ -37,7 +41,12 @@ class IconManager {
return "";
}
bool isHidden(const std::string& app_name) const {
return hidden_apps_.find(app_name) != hidden_apps_.end();
}
private:
IconManager() = default;
std::unordered_map<std::string, std::string> icons_map_;
std::unordered_set<std::string> hidden_apps_;
};
+2
View File
@@ -86,6 +86,8 @@ class Item : public sigc::trackable {
gdouble distance_scrolled_y_ = 0;
// visibility of items with Status == Passive
bool show_passive_ = false;
// hidden via config
bool is_hidden_ = false;
const Bar& bar_;
+12 -4
View File
@@ -42,16 +42,24 @@ Addressed by *tray*
default: false ++
Enables this module to consume all left over space dynamically.
*icons*: ++
typeof: object ++
Per-application icon customization. Keys are application IDs (e.g., "spotify", "blueman"). ++
Values can be: ++
- *string*: Custom icon name or path to icon file ++
- *false*: Hide this application's tray icon completely
# EXAMPLES
```
"tray": {
"icon-size": 21,
"spacing": 10,
"icons": {
"blueman": "bluetooth",
"TelegramDesktop": "$HOME/.local/share/icons/hicolor/16x16/apps/telegram.png"
}
"icons": {
"blueman": "bluetooth",
"TelegramDesktop": "$HOME/.local/share/icons/hicolor/16x16/apps/telegram.png",
"spotify": false
}
}
```
+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();
}