From 8606fb644fa3b41eadada8bc27d168beefe87e76 Mon Sep 17 00:00:00 2001 From: Rehan Date: Sat, 28 Oct 2023 00:03:26 -0400 Subject: [PATCH] wip --- include/modules/hyprland/workspaces.hpp | 2 ++ src/modules/hyprland/workspaces.cpp | 37 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index a17c2db4..cadf04c1 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -194,6 +194,8 @@ class Workspaces : public AModule, public EventHandler { std::vector m_windowsToCreate; std::vector m_ignoreWorkspaces; + std::vector exclude_persistence_point_; + std::vector prune_past_persistence_point_; std::mutex m_mutex; const Bar& m_bar; diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 7ad87bab..dca90561 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -127,6 +127,20 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void { m_windowRewriteRules = util::RegexCollection( windowRewrite, windowRewriteDefault, [this](std::string &window_rule) { return windowRewritePriorityFunction(window_rule); }); + + Json::Value exclude_persistence_point = config["exclude-persistence-point"]; + if (exclude_persistence_point.isArray()) { + for (Json::Value &ws_id : exclude_persistence_point) { + if (ws_id.isInt()) exclude_persistence_point_.emplace_back(ws_id.asInt()); + } + } + + Json::Value prune_past_persistence_point = config["prune-past-persistence-point"]; + if (prune_past_persistence_point.isArray()) { + for (Json::Value &ws_id : prune_past_persistence_point) { + if (ws_id.isInt()) prune_past_persistence_point_.emplace_back(ws_id.asInt()); + } + } } auto Workspaces::registerIpc() -> void { @@ -179,7 +193,19 @@ auto Workspaces::update() -> void { visibleWorkspaces.push_back(ws["name"].asString()); } } + int persist_point = -1; + if (!prune_past_persistence_point_.empty()) { + for (int i = m_workspaces.size() - 1; i >= 0; i--) { + if ((!m_workspaces[i]->isEmpty() || m_workspaces[i]->isActive() || m_workspaces[i]->isVisible()) && + !m_workspaces[i]->name().starts_with("special") && + std::find(exclude_persistence_point_.begin(), exclude_persistence_point_.end(), m_workspaces[i]->id()) == exclude_persistence_point_.end()) { + persist_point = i; + break; + } + } + } + int i = 0; for (auto &workspace : m_workspaces) { // active workspace->setActive(workspace->name() == m_activeWorkspaceName); @@ -198,6 +224,15 @@ auto Workspaces::update() -> void { workspaceIcon = workspace->selectIcon(m_iconsMap); } workspace->update(m_format, workspaceIcon); + + if (!prune_past_persistence_point_.empty() && + workspace->isPersistent() && + i > persist_point && + std::find(prune_past_persistence_point_.begin(), prune_past_persistence_point_.end(), m_workspaces[i]->id()) != prune_past_persistence_point_.end()) { + workspace->button().hide(); + } + + i++; } bool anyWindowCreated = false; @@ -637,6 +672,8 @@ void Workspaces::init() { sortWorkspaces(); + update(); + dp.emit(); }