diff --git a/man/waybar-niri-workspaces.5.scd b/man/waybar-niri-workspaces.5.scd index 5cd03aa2..977d6948 100644 --- a/man/waybar-niri-workspaces.5.scd +++ b/man/waybar-niri-workspaces.5.scd @@ -68,6 +68,16 @@ If none of the sorting options are enabled, workspaces keep their output/index o default: false ++ If set to true, only the active or focused workspace will be shown. +*display-condition*: ++ + typeof: string ++ + oneof: "show-all", "keep-named", "only-populated" ++ + default: "show-all" ++ + Specifies the conditions for showing workspace widgets. ++ + ++ + *show-all*: displays widgets for all workspaces. ++ + *keep-named*: always displays named workspaces, irrespective of whether they contain windows or not. ++ + *only-populated*: only displays widgets for workspaces that have windows. + *hide-empty*: ++ typeof: bool ++ default: false ++ diff --git a/src/modules/niri/workspaces.cpp b/src/modules/niri/workspaces.cpp index 5fa027f9..a3b9be9a 100644 --- a/src/modules/niri/workspaces.cpp +++ b/src/modules/niri/workspaces.cpp @@ -81,23 +81,32 @@ void Workspaces::doUpdate() { auto ipcLock = gIPC->lockData(); const auto alloutputs = config_["all-outputs"].asBool(); + const auto display_cond = config_["display-condition"].asString(); std::vector my_workspaces; const auto& workspaces = gIPC->workspaces(); - std::copy_if(workspaces.cbegin(), workspaces.cend(), std::back_inserter(my_workspaces), - [&](const auto& ws) { - std::string name; - if (ws["name"]) { - name = ws["name"].asString(); - } else { - name = std::to_string(ws["idx"].asUInt()); - } - if (isWorkspaceIgnored(name)) { - return false; - } + std::copy_if( + workspaces.cbegin(), workspaces.cend(), std::back_inserter(my_workspaces), + [&](const auto& ws) { + std::string name; + if (ws["name"]) { + name = ws["name"].asString(); + } else { + name = std::to_string(ws["idx"].asUInt()); + } + if (isWorkspaceIgnored(name)) { + return false; + } - if (alloutputs) return true; - return ws["output"].asString() == bar_.output->name; - }); + if (display_cond == "only-populated") { + if (ws["active_window_id"].isNull() && !ws["is_active"].asBool()) return false; + } else if (display_cond == "keep-named") { + if (ws["name"].isNull() && ws["active_window_id"].isNull() && !ws["is_active"].asBool()) + return false; + } + + if (alloutputs) return true; + return ws["output"].asString() == bar_.output->name; + }); sortWorkspaces(my_workspaces);