Merge pull request #4747 from cartok/feat/sway-workspaces-format-for-negative-indices

feat(sway/workspaces): add format for negative indices
This commit is contained in:
Alexis Rouillard
2026-07-03 22:27:14 +02:00
committed by GitHub
2 changed files with 39 additions and 12 deletions
+12
View File
@@ -22,6 +22,11 @@ Addressed by *sway/workspaces*
default: {value} ++ default: {value} ++
The format, how information should be displayed. The format, how information should be displayed.
*format-for-negative-index*: ++
typeof: string ++
default: *format* ++
An alternative format, which will be used for workspaces with no explict or negative index ("num" in sway terms). Requires *format* to be set.
*format-icons*: ++ *format-icons*: ++
typeof: array ++ typeof: array ++
Based on the workspace name and state, the corresponding icon gets selected. See *icons*. Based on the workspace name and state, the corresponding icon gets selected. See *icons*.
@@ -187,6 +192,13 @@ n.b.: the list of outputs can be obtained from command line using *swaymsg -t ge
} }
``` ```
```
"sway/workspaces": {
"format": "{index} - {name}",
"format-for-negative-index": "{name}"
}
```
# Style # Style
- *#workspaces button* - *#workspaces button*
+27 -12
View File
@@ -332,29 +332,44 @@ auto Workspaces::update() -> void {
} else { } else {
button.get_style_context()->remove_class("current_output"); button.get_style_context()->remove_class("current_output");
} }
std::string output; std::string full_name;
if (!config_["disable-markup"].asBool()) { if (!config_["disable-markup"].asBool()) {
output = g_markup_escape_text((*it)["name"].asString().c_str(), -1); full_name = g_markup_escape_text((*it)["name"].asString().c_str(), -1);
} else { } else {
output = (*it)["name"].asString(); full_name = (*it)["name"].asString();
} }
std::string windows = ""; std::string windows = "";
if (config_["window-rewrite"].isObject()) { if (config_["window-rewrite"].isObject()) {
updateWindows((*it), windows); updateWindows((*it), windows);
} }
auto index = (*it)["num"].asInt();
if (config_["format"].isString()) { if (config_["format"].isString()) {
auto format = config_["format"].asString(); std::string format;
output = fmt::format( if (config_["format-for-negative-index"].isString() && index < 0) {
fmt::runtime(format), fmt::arg("icon", getIcon(output, *it)), fmt::arg("value", output), format = config_["format-for-negative-index"].asString();
fmt::arg("name", trimWorkspaceName(output)), fmt::arg("index", (*it)["num"].asString()), } else {
fmt::arg("windows", format = config_["format"].asString();
windows.substr(0, windows.length() - m_formatWindowSeparator.length())), }
fmt::arg("output", (*it)["output"].asString()));
auto name = trimWorkspaceName(full_name);
auto output = (*it)["output"].asString();
auto icon = getIcon(full_name, *it);
auto separated_windows =
windows.substr(0, windows.length() - m_formatWindowSeparator.length());
full_name =
fmt::format(fmt::runtime(format), fmt::arg("index", index), fmt::arg("name", name),
fmt::arg("value", full_name), fmt::arg("output", output),
fmt::arg("icon", icon), fmt::arg("windows", separated_windows));
} }
if (!config_["disable-markup"].asBool()) { if (!config_["disable-markup"].asBool()) {
static_cast<Gtk::Label*>(button.get_children()[0])->set_markup(output); static_cast<Gtk::Label*>(button.get_children()[0])->set_markup(full_name);
} else { } else {
button.set_label(output); button.set_label(full_name);
} }
onButtonReady(*it, button); onButtonReady(*it, button);
} }