Merge pull request #4537 from thomascrha/niri-workspace-ignore-workspaces

feat(niri/worspaces): add ignore-workspaces configuration option
This commit is contained in:
Alexis Rouillard
2026-07-04 00:52:19 +02:00
committed by GitHub
3 changed files with 46 additions and 0 deletions
+37
View File
@@ -39,6 +39,24 @@ Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value&
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);
// Parse ignore-workspaces rules.
auto ignoreWorkspaces = config["ignore-workspaces"];
if (ignoreWorkspaces.isArray()) {
for (const auto& workspaceRegex : ignoreWorkspaces) {
if (workspaceRegex.isString()) {
std::string ruleString = workspaceRegex.asString();
try {
const std::regex rule{ruleString, std::regex_constants::icase};
ignoreWorkspaces_.emplace_back(rule);
} catch (const std::regex_error& e) {
spdlog::error("Invalid ignore-workspaces rule {}: {}", ruleString, e.what());
}
} else {
spdlog::error("Not a string in ignore-workspaces: '{}'", workspaceRegex);
}
}
}
if (!gIPC) gIPC = std::make_unique<IPC>();
gIPC->registerForIPC("WorkspacesChanged", this);
@@ -67,6 +85,16 @@ void Workspaces::doUpdate() {
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;
}
if (alloutputs) return true;
return ws["output"].asString() == bar_.output->name;
});
@@ -231,6 +259,15 @@ std::string Workspaces::getIcon(const std::string& value, const Json::Value& ws)
return value;
}
bool Workspaces::isWorkspaceIgnored(const std::string& name) {
for (auto& rule : ignoreWorkspaces_) {
if (std::regex_match(name, rule)) {
return true;
}
}
return false;
}
bool Workspaces::handleScroll(GdkEventScroll* e) {
if (gdk_event_get_pointer_emulated((GdkEvent*)e) != 0) {
/**