Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion include/modules/sni/icon_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <string>
#include <unordered_map>
#include <unordered_set>

class IconManager {
public:
Expand All @@ -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;
}
Expand All @@ -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 changes: 2 additions & 0 deletions include/modules/sni/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down
16 changes: 12 additions & 4 deletions man/waybar-tray.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

```
Expand Down
14 changes: 11 additions & 3 deletions src/modules/sni/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down
12 changes: 8 additions & 4 deletions src/modules/sni/tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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();
}

Expand Down