support hiding tray icons
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
class IconManager {
|
class IconManager {
|
||||||
public:
|
public:
|
||||||
@@ -19,7 +20,10 @@ class IconManager {
|
|||||||
std::string app_name = key;
|
std::string app_name = key;
|
||||||
const Json::Value& icon_value = icons_config[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();
|
std::string icon_path = icon_value.asString();
|
||||||
icons_map_[app_name] = icon_path;
|
icons_map_[app_name] = icon_path;
|
||||||
}
|
}
|
||||||
@@ -37,7 +41,12 @@ class IconManager {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isHidden(const std::string& app_name) const {
|
||||||
|
return hidden_apps_.find(app_name) != hidden_apps_.end();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IconManager() = default;
|
IconManager() = default;
|
||||||
std::unordered_map<std::string, std::string> icons_map_;
|
std::unordered_map<std::string, std::string> icons_map_;
|
||||||
|
std::unordered_set<std::string> hidden_apps_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ class Item : public sigc::trackable {
|
|||||||
gdouble distance_scrolled_y_ = 0;
|
gdouble distance_scrolled_y_ = 0;
|
||||||
// visibility of items with Status == Passive
|
// visibility of items with Status == Passive
|
||||||
bool show_passive_ = false;
|
bool show_passive_ = false;
|
||||||
|
// hidden via config
|
||||||
|
bool is_hidden_ = false;
|
||||||
|
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,13 @@ Addressed by *tray*
|
|||||||
default: false ++
|
default: false ++
|
||||||
Enables this module to consume all left over space dynamically.
|
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
|
# EXAMPLES
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -50,7 +57,8 @@ Addressed by *tray*
|
|||||||
"spacing": 10,
|
"spacing": 10,
|
||||||
"icons": {
|
"icons": {
|
||||||
"blueman": "bluetooth",
|
"blueman": "bluetooth",
|
||||||
"TelegramDesktop": "$HOME/.local/share/icons/hicolor/16x16/apps/telegram.png"
|
"TelegramDesktop": "$HOME/.local/share/icons/hicolor/16x16/apps/telegram.png",
|
||||||
|
"spotify": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
* I still haven't found a way for it to pick from theme automatically, although
|
||||||
* it might be my theme.
|
* it might be my theme.
|
||||||
*/
|
*/
|
||||||
|
std::string icon_id = id;
|
||||||
if (id == "chrome_status_icon_1") {
|
if (id == "chrome_status_icon_1") {
|
||||||
Glib::VariantBase value;
|
Glib::VariantBase value;
|
||||||
this->proxy_->get_cached_property(value, "ToolTip");
|
this->proxy_->get_cached_property(value, "ToolTip");
|
||||||
tooltip = get_variant<ToolTip>(value);
|
tooltip = get_variant<ToolTip>(value);
|
||||||
if (!tooltip.text.empty()) {
|
if (!tooltip.text.empty()) {
|
||||||
setCustomIcon(tooltip.text.lowercase());
|
icon_id = tooltip.text.lowercase();
|
||||||
|
setCustomIcon(icon_id);
|
||||||
}
|
}
|
||||||
} else {
|
} 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") {
|
} else if (name == "Title") {
|
||||||
title = get_variant<std::string>(value);
|
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) {
|
void Item::setStatus(const Glib::ustring& value) {
|
||||||
Glib::ustring lower = value.lowercase();
|
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();
|
auto style = event_box.get_style_context();
|
||||||
for (const auto& class_name : style->list_classes()) {
|
for (const auto& class_name : style->list_classes()) {
|
||||||
|
|||||||
@@ -8,11 +8,18 @@
|
|||||||
|
|
||||||
namespace waybar::modules::SNI {
|
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)
|
Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||||
: AModule(config, "tray", id),
|
: AModule(config, "tray", id),
|
||||||
box_(bar.orientation, 0),
|
box_(bar.orientation, 0),
|
||||||
watcher_(SNI::Watcher::getInstance()),
|
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)) {
|
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
||||||
box_.set_name("tray");
|
box_.set_name("tray");
|
||||||
event_box_.add(box_);
|
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();
|
show_passive_ = config["show-passive-items"].asBool();
|
||||||
}
|
}
|
||||||
nb_hosts_ += 1;
|
nb_hosts_ += 1;
|
||||||
if (config_["icons"].isObject()) {
|
|
||||||
IconManager::instance().setIconsConfig(config_["icons"]);
|
|
||||||
}
|
|
||||||
dp.emit();
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user