feat(Workspaces): format

This commit is contained in:
Alexis 2018-09-18 20:58:11 +02:00
parent 55e1905284
commit d914429194
No known key found for this signature in database
GPG Key ID: 20B1EC2EBBA96BD9
3 changed files with 13 additions and 9 deletions

View File

@ -11,6 +11,7 @@
// "sway/workspaces": {
// "disable-scroll": true,
// "all-outputs": true,
// "format": "{name}: {icon}",
// "format-icons": {
// "1": "",
// "2": "",

View File

@ -18,10 +18,6 @@ window {
border-bottom: 3px solid transparent;
}
#workspaces button.icon label {
font-size: 10px;
}
#workspaces button.focused {
background: #64727D;
border-bottom: 3px solid white;

View File

@ -79,7 +79,13 @@ auto waybar::modules::sway::Workspaces::update() -> void
box_.reorder_child(button, node["num"].asInt());
}
auto icon = getIcon(node["name"].asString(), node);
if (config_["format"]) {
auto format = config_["format"].asString();
button.set_label(fmt::format(format, fmt::arg("icon", icon),
fmt::arg("name", node["name"].asString())));
} else {
button.set_label(icon);
}
button.show();
}
}
@ -91,11 +97,12 @@ auto waybar::modules::sway::Workspaces::update() -> void
void waybar::modules::sway::Workspaces::addWorkspace(Json::Value node)
{
auto icon = getIcon(node["name"].asString(), node);
auto pair = buttons_.emplace(node["num"].asInt(), icon);
auto format = config_["format"]
? fmt::format(config_["format"].asString(), fmt::arg("icon", icon),
fmt::arg("name", node["name"].asString()))
: icon;
auto pair = buttons_.emplace(node["num"].asInt(), format);
auto &button = pair.first->second;
if (icon != node["name"].asString()) {
button.get_style_context()->add_class("icon");
}
box_.pack_start(button, false, false, 0);
button.set_relief(Gtk::RELIEF_NONE);
button.signal_clicked().connect([this, pair] {