From e45883088d5d75515632729157231fdd8ac0e4a5 Mon Sep 17 00:00:00 2001 From: arnaud-ma Date: Sat, 19 Jul 2025 03:18:48 +0200 Subject: [PATCH] hyprland: Remove redundant workspace rules loading --- include/modules/hyprland/workspaces.hpp | 1 - src/modules/hyprland/workspaces.cpp | 48 +++++-------------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 9a44e594..4f9eda47 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -118,7 +118,6 @@ class Workspaces : public AModule, public EventHandler { void initializeWorkspaces(); void setCurrentMonitorId(); void loadPersistentWorkspacesFromConfig(Json::Value const& clientsJson); - void loadPersistentWorkspacesFromWorkspaceRules(const Json::Value& clientsJson); bool m_allOutputs = false; bool m_showSpecial = false; diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 06a6ed3c..739f0a9d 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -71,12 +71,12 @@ void Workspaces::createWorkspace(Json::Value const &workspace_data, // avoid recreating existing workspaces auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr const &w) { - if (workspaceId > 0) { - return w->id() == workspaceId; - } - return (workspaceName.starts_with("special:") && workspaceName.substr(8) == w->name()) || - workspaceName == w->name(); - }); + if (workspaceId > 0) { + return w->id() == workspaceId; + } + return (workspaceName.starts_with("special:") && workspaceName.substr(8) == w->name()) || + workspaceName == w->name(); + }); if (workspace != m_workspaces.end()) { // don't recreate workspace, but update persistency if necessary @@ -206,8 +206,9 @@ void Workspaces::initializeWorkspaces() { // a persistent workspace config is defined, so use that instead of workspace rules loadPersistentWorkspacesFromConfig(clientsJson); } - // load Hyprland's workspace rules - loadPersistentWorkspacesFromWorkspaceRules(clientsJson); + // persistent workspaces configured with hyprland's workspace rules + // are already listed in 'workspacesJson', so we don't need to + // load them again. } bool isDoubleSpecial(std::string const &workspace_name) { @@ -282,37 +283,6 @@ void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJs } } -void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value &clientsJson) { - spdlog::info("Loading persistent workspaces from Hyprland workspace rules"); - - auto const workspaceRules = m_ipc.getSocket1JsonReply("workspacerules"); - for (Json::Value const &rule : workspaceRules) { - if (!rule["workspaceString"].isString()) { - spdlog::warn("Workspace rules: invalid workspaceString, skipping: {}", rule); - continue; - } - if (!rule["persistent"].asBool()) { - continue; - } - auto const &workspace = rule.isMember("defaultName") ? rule["defaultName"].asString() - : rule["workspaceString"].asString(); - auto const &monitor = rule["monitor"].asString(); - // create this workspace persistently if: - // 1. the allOutputs config option is enabled - // 2. the rule's monitor is the current monitor - // 3. no monitor is specified in the rule => assume it needs to be persistent on every monitor - if (allOutputs() || m_bar.output->name == monitor || monitor.empty()) { - // => persistent workspace should be shown on this monitor - auto workspaceData = createMonitorWorkspaceData(workspace, m_bar.output->name); - workspaceData["persistent-rule"] = true; - m_workspacesToCreate.emplace_back(workspaceData, clientsJson); - } else { - // This can be any workspace selector. - m_workspacesToRemove.emplace_back(workspace); - } - } -} - void Workspaces::onEvent(const std::string &ev) { std::lock_guard lock(m_mutex); std::string eventName(begin(ev), begin(ev) + ev.find_first_of('>'));