Merge pull request #4624 from andresilva/tray-hide-icons
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_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -101,6 +101,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;
|
||||||
bool ready_ = false;
|
bool ready_ = false;
|
||||||
Glib::ustring status_ = "active";
|
Glib::ustring status_ = "active";
|
||||||
|
|
||||||
|
|||||||
+12
-4
@@ -42,16 +42,24 @@ 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
|
||||||
|
|
||||||
```
|
```
|
||||||
"tray": {
|
"tray": {
|
||||||
"icon-size": 21,
|
"icon-size": 21,
|
||||||
"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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -172,15 +172,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);
|
||||||
@@ -238,7 +246,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) {
|
||||||
status_ = value.lowercase();
|
status_ = value.lowercase();
|
||||||
event_box.set_visible(show_passive_ || status_.compare("passive") != 0);
|
event_box.set_visible(!is_hidden_ && (show_passive_ || status_.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,6 +8,12 @@
|
|||||||
|
|
||||||
namespace waybar::modules::SNI {
|
namespace waybar::modules::SNI {
|
||||||
|
|
||||||
|
static void initIconsConfig(const Json::Value& config) {
|
||||||
|
if (config["icons"].isObject()) {
|
||||||
|
IconManager::instance().setIconsConfig(config["icons"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> Tray::parseIgnoreList(const Json::Value& config) {
|
std::vector<std::string> Tray::parseIgnoreList(const Json::Value& config) {
|
||||||
std::vector<std::string> ignore_list;
|
std::vector<std::string> ignore_list;
|
||||||
if (config["ignore-list"].isArray()) {
|
if (config["ignore-list"].isArray()) {
|
||||||
@@ -29,7 +35,7 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
|||||||
box_(bar.orientation, 0),
|
box_(bar.orientation, 0),
|
||||||
watcher_(SNI::Watcher::getInstance()),
|
watcher_(SNI::Watcher::getInstance()),
|
||||||
ignore_list_(parseIgnoreList(config)),
|
ignore_list_(parseIgnoreList(config)),
|
||||||
host_(nb_hosts_, config, bar, ignore_list_,
|
host_((initIconsConfig(config), nb_hosts_), config, bar, ignore_list_,
|
||||||
std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||||
std::bind(&Tray::onRemove, this, std::placeholders::_1),
|
std::bind(&Tray::onRemove, this, std::placeholders::_1),
|
||||||
std::bind(&Tray::queueUpdate, this)) {
|
std::bind(&Tray::queueUpdate, this)) {
|
||||||
@@ -43,9 +49,6 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
|||||||
box_.set_spacing(config_["spacing"].asUInt());
|
box_.set_spacing(config_["spacing"].asUInt());
|
||||||
}
|
}
|
||||||
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