feat(Workspaces): urgent, visible, focused icons

pull/46/head
Alexis 2018-09-05 00:16:56 +02:00
parent 28c65c64e6
commit 7020af7653
No known key found for this signature in database
GPG Key ID: 20B1EC2EBBA96BD9
3 changed files with 30 additions and 19 deletions

View File

@ -18,7 +18,7 @@ class Workspaces : public IModule {
private: private:
void worker(); void worker();
void addWorkspace(Json::Value); void addWorkspace(Json::Value);
std::string getIcon(std::string); std::string getIcon(std::string, Json::Value);
bool handleScroll(GdkEventScroll*); bool handleScroll(GdkEventScroll*);
int getPrevWorkspace(); int getPrevWorkspace();
int getNextWorkspace(); int getNextWorkspace();

View File

@ -8,7 +8,7 @@
"modules-center": ["sway/window"], "modules-center": ["sway/window"],
"modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "clock"], "modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "clock"],
// Modules configuration // Modules configuration
"sway/workspaces": { // "sway/workspaces": {
// "disable-scroll": true, // "disable-scroll": true,
// "all-outputs": true, // "all-outputs": true,
// "format-icons": { // "format-icons": {
@ -16,9 +16,12 @@
// "2": "", // "2": "",
// "3": "", // "3": "",
// "4": "", // "4": "",
// "5": "" // "5": "",
// "urgent": "",
// "focused": "",
// "default": ""
// } // }
}, // },
"sway/window": { "sway/window": {
"max-length": 50 "max-length": 50
}, },

View File

@ -78,6 +78,8 @@ auto waybar::modules::sway::Workspaces::update() -> void
if (needReorder) { if (needReorder) {
box_.reorder_child(button, node["num"].asInt()); box_.reorder_child(button, node["num"].asInt());
} }
auto icon = getIcon(node["name"].asString(), node);
button.set_label(icon);
button.show(); button.show();
} }
} }
@ -88,7 +90,7 @@ auto waybar::modules::sway::Workspaces::update() -> void
void waybar::modules::sway::Workspaces::addWorkspace(Json::Value node) 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 pair = buttons_.emplace(node["num"].asInt(), icon);
auto &button = pair.first->second; auto &button = pair.first->second;
if (icon != node["name"].asString()) { if (icon != node["name"].asString()) {
@ -123,13 +125,19 @@ void waybar::modules::sway::Workspaces::addWorkspace(Json::Value node)
button.show(); 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]) { std::vector<std::string> keys = {
return config_["format-icons"][name].asString(); 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();
} }
if (config_["format-icons"]["default"]) {
return config_["format-icons"]["default"].asString();
} }
return name; return name;
} }