From 7020af76538968ba1d1672376df29dc34b506230 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 5 Sep 2018 00:16:56 +0200 Subject: [PATCH] feat(Workspaces): urgent, visible, focused icons --- include/modules/sway/workspaces.hpp | 2 +- resources/config | 25 ++++++++++++++----------- src/modules/sway/workspaces.cpp | 22 +++++++++++++++------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/include/modules/sway/workspaces.hpp b/include/modules/sway/workspaces.hpp index 14adeed..88d4f1a 100644 --- a/include/modules/sway/workspaces.hpp +++ b/include/modules/sway/workspaces.hpp @@ -18,7 +18,7 @@ class Workspaces : public IModule { private: void worker(); void addWorkspace(Json::Value); - std::string getIcon(std::string); + std::string getIcon(std::string, Json::Value); bool handleScroll(GdkEventScroll*); int getPrevWorkspace(); int getNextWorkspace(); diff --git a/resources/config b/resources/config index e2dc801..9e5cc6a 100644 --- a/resources/config +++ b/resources/config @@ -8,17 +8,20 @@ "modules-center": ["sway/window"], "modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "clock"], // Modules configuration - "sway/workspaces": { - // "disable-scroll": true, - // "all-outputs": true, - // "format-icons": { - // "1": "", - // "2": "", - // "3": "", - // "4": "", - // "5": "" - // } - }, + // "sway/workspaces": { + // "disable-scroll": true, + // "all-outputs": true, + // "format-icons": { + // "1": "", + // "2": "", + // "3": "", + // "4": "", + // "5": "", + // "urgent": "", + // "focused": "", + // "default": "" + // } + // }, "sway/window": { "max-length": 50 }, diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 45be744..b5c6602 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -78,6 +78,8 @@ auto waybar::modules::sway::Workspaces::update() -> void if (needReorder) { box_.reorder_child(button, node["num"].asInt()); } + auto icon = getIcon(node["name"].asString(), node); + button.set_label(icon); button.show(); } } @@ -88,7 +90,7 @@ auto waybar::modules::sway::Workspaces::update() -> void void waybar::modules::sway::Workspaces::addWorkspace(Json::Value node) { - auto icon = getIcon(node["name"].asString()); + auto icon = getIcon(node["name"].asString(), node); auto pair = buttons_.emplace(node["num"].asInt(), icon); auto &button = pair.first->second; if (icon != node["name"].asString()) { @@ -123,13 +125,19 @@ void waybar::modules::sway::Workspaces::addWorkspace(Json::Value node) button.show(); } -std::string waybar::modules::sway::Workspaces::getIcon(std::string name) +std::string waybar::modules::sway::Workspaces::getIcon(std::string name, + Json::Value node) { - if (config_["format-icons"][name]) { - return config_["format-icons"][name].asString(); - } - if (config_["format-icons"]["default"]) { - return config_["format-icons"]["default"].asString(); + std::vector keys = { + name, "urgent", "focused", "visible", "default"}; + for (auto const& key : keys) { + if (key == "focused" || key == "visible" || key == "urgent") { + if (config_["format-icons"][key] && node[key].asBool()) { + return config_["format-icons"][key].asString(); + } + } else if (config_["format-icons"][key]) { + return config_["format-icons"][key].asString(); + } } return name; }