Skip to content
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
3 changes: 3 additions & 0 deletions include/modules/sway/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Workspaces : public AModule, public sigc::trackable {
static int convertWorkspaceNameToNum(const std::string& name);
static int windowRewritePriorityFunction(std::string const& window_rule);

auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void;
bool isWorkspaceIgnored(std::string const& name);
void onCmd(const struct Ipc::ipc_response&);
void onEvent(const struct Ipc::ipc_response&);
bool filterButtons();
Expand All @@ -49,6 +51,7 @@ class Workspaces : public AModule, public sigc::trackable {
std::vector<std::string> workspaces_order_;
Gtk::Box box_;
std::string m_formatWindowSeparator;
std::vector<std::regex> m_ignoreWorkspaces;
util::RegexCollection m_windowRewriteRules;
util::JsonParser parser_;
std::unordered_map<std::string, Gtk::Button> buttons_;
Expand Down
36 changes: 34 additions & 2 deletions src/modules/sway/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value&
m_windowRewriteRules = waybar::util::RegexCollection(
windowRewrite, std::move(windowRewriteDefault), windowRewritePriorityFunction);
}
populateIgnoreWorkspacesConfig(config);
ipc_.subscribe(R"(["workspace"])");
ipc_.subscribe(R"(["window"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));
Expand Down Expand Up @@ -97,6 +98,36 @@ void Workspaces::onEvent(const struct Ipc::ipc_response& res) {
}
}

auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value& config) -> void {
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};
m_ignoreWorkspaces.emplace_back(rule);
} catch (const std::regex_error& e) {
spdlog::error("Invalid rule {}: {}", ruleString, e.what());
}
} else {
spdlog::error("Not a string: '{}'", workspaceRegex);
}
}
}
}

bool Workspaces::isWorkspaceIgnored(std::string const& name) {
for (auto& rule : m_ignoreWorkspaces) {
if (std::regex_match(name, rule)) {
return true;
break;
}
}

return false;
}

void Workspaces::onCmd(const struct Ipc::ipc_response& res) {
if (res.type == IPC_GET_TREE) {
try {
Expand All @@ -118,8 +149,9 @@ void Workspaces::onCmd(const struct Ipc::ipc_response& res) {
});

for (auto& output : outputs) {
std::copy(output["nodes"].begin(), output["nodes"].end(),
std::back_inserter(workspaces_));
std::copy_if(
output["nodes"].begin(), output["nodes"].end(), std::back_inserter(workspaces_),
[&](const auto& node) { return !(isWorkspaceIgnored(node["name"].asString())); });
std::copy(output["floating_nodes"].begin(), output["floating_nodes"].end(),
std::back_inserter(workspaces_));
}
Expand Down