feat(Workspaces): urgent, visible, focused icons

This commit is contained in:
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:
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();

View File

@ -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
},

View File

@ -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<std::string> 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;
}