From 7c86f1ccb47f6c33fc0f11d2497fe0805354388e Mon Sep 17 00:00:00 2001 From: Emiliano Deustua Date: Thu, 17 Jul 2025 10:59:33 -0500 Subject: [PATCH 1/3] fix: Use workspace ID to handle workspace updates --- src/modules/hyprland/workspaces.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 46402055..50eba51b 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -79,18 +79,14 @@ Json::Value Workspaces::createMonitorWorkspaceData(std::string const& name, void Workspaces::createWorkspace(Json::Value const& workspace_data, Json::Value const& clients_data) { - auto workspaceName = workspace_data["name"].asString(); auto workspaceId = workspace_data["id"].asInt(); - spdlog::debug("Creating workspace {}", workspaceName); + spdlog::debug("Creating workspace {}", workspaceId); // 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(); - }); + auto workspace = + std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr const& w) { + return workspaceId == w->id(); + }); if (workspace != m_workspaces.end()) { // don't recreate workspace, but update persistency if necessary @@ -98,14 +94,14 @@ void Workspaces::createWorkspace(Json::Value const& workspace_data, const auto* k = "persistent-rule"; if (std::ranges::find(keys, k) != keys.end()) { - spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceName, + spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceId, workspace_data[k].asBool() ? "true" : "false"); (*workspace)->setPersistentRule(workspace_data[k].asBool()); } k = "persistent-config"; if (std::ranges::find(keys, k) != keys.end()) { - spdlog::debug("Set config persistency of workspace {} to: {}", workspaceName, + spdlog::debug("Set config persistency of workspace {} to: {}", workspaceId, workspace_data[k].asBool() ? "true" : "false"); (*workspace)->setPersistentConfig(workspace_data[k].asBool()); } @@ -1101,8 +1097,7 @@ void Workspaces::updateWindowCount() { const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces"); for (auto const& workspace : m_workspaces) { auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const& x) { - return x["name"].asString() == workspace->name() || - (workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name()); + return x["id"].asInt() == workspace->id(); }); uint32_t count = 0; if (workspaceJson != workspacesJson.end()) { @@ -1171,9 +1166,7 @@ void Workspaces::updateWorkspaceStates() { workspaceTooltip = workspace->selectString(m_tooltipMap); } auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto& w) { - auto wNameRaw = w["name"].asString(); - auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw; - return wName == workspace->name(); + return w["id"].asInt() == workspace->id(); }); if (updatedWorkspace != updatedWorkspaces.end()) { workspace->setOutput((*updatedWorkspace)["monitor"].asString()); From 95664c7662c16de57b0c763030565551e0dcacf5 Mon Sep 17 00:00:00 2001 From: Emiliano Deustua Date: Tue, 14 Oct 2025 20:18:50 -0500 Subject: [PATCH 2/3] fix: Remove load persistent workspaces from workspace rules --- src/modules/hyprland/workspaces.cpp | 47 ----------------------------- 1 file changed, 47 deletions(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 50eba51b..8d217972 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -217,8 +217,6 @@ 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); } bool isDoubleSpecial(std::string const& workspace_name) { @@ -293,51 +291,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 workspace = rule.isMember("defaultName") ? rule["defaultName"].asString() - : rule["workspaceString"].asString(); - - // There could be persistent special workspaces, only show those when show-special is enabled. - if (workspace.starts_with("special:") && !showSpecial()) { - continue; - } - - // The prefix "name:" cause mismatches with workspace names taken anywhere else. - if (workspace.starts_with("name:")) { - workspace = workspace.substr(5); - } - 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()) { - // => skip ignore-workspaces even if its a persistent - if (isWorkspaceIgnored(workspace)) { - continue; - } - // => 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); From 5f7629a36e4fca584f66167e244b0ee593db788a Mon Sep 17 00:00:00 2001 From: Emiliano Deustua Date: Tue, 14 Oct 2025 21:33:11 -0500 Subject: [PATCH 3/3] format: Fix clang formatting --- src/modules/hyprland/workspaces.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 8d217972..4cd0d2ae 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -83,10 +83,9 @@ void Workspaces::createWorkspace(Json::Value const& workspace_data, spdlog::debug("Creating workspace {}", workspaceId); // avoid recreating existing workspaces - auto workspace = - std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr const& w) { - return workspaceId == w->id(); - }); + auto workspace = std::ranges::find_if( + m_workspaces, + [workspaceId](std::unique_ptr const& w) { return workspaceId == w->id(); }); if (workspace != m_workspaces.end()) { // don't recreate workspace, but update persistency if necessary @@ -1049,9 +1048,8 @@ auto Workspaces::update() -> void { void Workspaces::updateWindowCount() { const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces"); for (auto const& workspace : m_workspaces) { - auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const& x) { - return x["id"].asInt() == workspace->id(); - }); + auto workspaceJson = std::ranges::find_if( + workspacesJson, [&](Json::Value const& x) { return x["id"].asInt() == workspace->id(); }); uint32_t count = 0; if (workspaceJson != workspacesJson.end()) { try {