Remove ws index from sway ws names

This commit is contained in:
Caleb Bassi 2018-12-28 09:35:21 -08:00
parent aa6da11ba4
commit 8ea0659ee2
2 changed files with 12 additions and 2 deletions

View File

@ -22,6 +22,7 @@ class Workspaces : public IModule {
bool handleScroll(GdkEventScroll*);
std::string getPrevWorkspace();
std::string getNextWorkspace();
std::string trimWorkspaceName(std::string);
const Bar& bar_;
const Json::Value& config_;

View File

@ -87,7 +87,7 @@ auto waybar::modules::sway::Workspaces::update() -> void
if (config_["format"].isString()) {
auto format = config_["format"].asString();
button.set_label(fmt::format(format, fmt::arg("icon", icon),
fmt::arg("name", node["name"].asString()),
fmt::arg("name", trimWorkspaceName(node["name"].asString())),
fmt::arg("index", node["num"].asString())));
} else {
button.set_label(icon);
@ -105,7 +105,7 @@ void waybar::modules::sway::Workspaces::addWorkspace(Json::Value node)
auto icon = getIcon(node["name"].asString(), node);
auto format = config_["format"].isString()
? fmt::format(config_["format"].asString(), fmt::arg("icon", icon),
fmt::arg("name", node["name"].asString()),
fmt::arg("name", trimWorkspaceName(node["name"].asString())),
fmt::arg("index", node["num"].asString()))
: icon;
auto pair = buttons_.emplace(node["name"].asString(), format);
@ -235,3 +235,12 @@ std::string waybar::modules::sway::Workspaces::getNextWorkspace()
waybar::modules::sway::Workspaces::operator Gtk::Widget &() {
return box_;
}
std::string waybar::modules::sway::Workspaces::trimWorkspaceName(std::string name)
{
std::size_t found = name.find(":");
if (found!=std::string::npos) {
return name.substr(found+1);
}
return name;
}