Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add display-condition configuration option #4001

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions man/waybar-niri-workspaces.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ Addressed by *niri/workspaces*
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.

*on-update*: ++
typeof: string ++
Command to execute when the module is updated.
Expand Down
19 changes: 14 additions & 5 deletions src/modules/niri/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ void Workspaces::doUpdate() {
auto ipcLock = gIPC->lockData();

const auto alloutputs = config_["all-outputs"].asBool();
const auto display_cond = config_["display-condition"].asString();
std::vector<Json::Value> my_workspaces;
const auto &workspaces = gIPC->workspaces();
std::copy_if(workspaces.cbegin(), workspaces.cend(), std::back_inserter(my_workspaces),
[&](const auto &ws) {
if (alloutputs) return true;
return ws["output"].asString() == bar_.output->name;
});
std::copy_if(
workspaces.cbegin(), workspaces.cend(), std::back_inserter(my_workspaces),
[&](const auto &ws) {
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;
});

// Remove buttons for removed workspaces.
for (auto it = buttons_.begin(); it != buttons_.end();) {
Expand Down