From 7c86f1ccb47f6c33fc0f11d2497fe0805354388e Mon Sep 17 00:00:00 2001 From: Emiliano Deustua Date: Thu, 17 Jul 2025 10:59:33 -0500 Subject: [PATCH] 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());