From d9144291942cc9df2d9c18b435c7767b9d591aa0 Mon Sep 17 00:00:00 2001 From: Alexis Date: Tue, 18 Sep 2018 20:58:11 +0200 Subject: [PATCH] feat(Workspaces): format --- resources/config | 1 + resources/style.css | 4 ---- src/modules/sway/workspaces.cpp | 17 ++++++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/resources/config b/resources/config index 9e5cc6a2..f17acc3a 100644 --- a/resources/config +++ b/resources/config @@ -11,6 +11,7 @@ // "sway/workspaces": { // "disable-scroll": true, // "all-outputs": true, + // "format": "{name}: {icon}", // "format-icons": { // "1": "", // "2": "", diff --git a/resources/style.css b/resources/style.css index 2ef0bdf4..cacdb67e 100644 --- a/resources/style.css +++ b/resources/style.css @@ -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; diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index b5c6602f..3e74801b 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -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); - button.set_label(icon); + 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] {