diff --git a/man/waybar-sway-workspaces.5.scd b/man/waybar-sway-workspaces.5.scd index 3d4e3ad02..9bffda3d3 100644 --- a/man/waybar-sway-workspaces.5.scd +++ b/man/waybar-sway-workspaces.5.scd @@ -22,6 +22,11 @@ Addressed by *sway/workspaces* default: {value} ++ 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*: ++ typeof: array ++ 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 - *#workspaces button* diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 182bf631c..88c090c58 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -329,24 +329,43 @@ auto Workspaces::update() -> void { } else { button.get_style_context()->remove_class("current_output"); } - std::string output = (*it)["name"].asString(); + std::string windows = ""; if (config_["window-rewrite"].isObject()) { updateWindows((*it), windows); } + + auto index = (*it)["num"].asInt(); + auto full_name = (*it)["name"].asString(); + if (config_["format"].isString()) { - auto format = config_["format"].asString(); - output = fmt::format( - fmt::runtime(format), fmt::arg("icon", getIcon(output, *it)), fmt::arg("value", output), - fmt::arg("name", trimWorkspaceName(output)), fmt::arg("index", (*it)["num"].asString()), - fmt::arg("windows", - windows.substr(0, windows.length() - m_formatWindowSeparator.length())), - fmt::arg("output", (*it)["output"].asString())); + std::string format; + if(config_["format-for-negative-index"].isString() && index < 0) { + format = config_["format-for-negative-index"].asString(); + } else { + format = config_["format"].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()) { - static_cast(button.get_children()[0])->set_markup(output); + static_cast(button.get_children()[0])->set_markup(full_name); } else { - button.set_label(output); + button.set_label(full_name); } onButtonReady(*it, button); }