feat(sway/workspaces): add format for negative indices
This commit is contained in:
@@ -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*
|
||||||
|
|||||||
@@ -329,24 +329,43 @@ 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 = (*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();
|
||||||
|
auto full_name = (*it)["name"].asString();
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user