Skip to content

Commit fa3ab26

Browse files
committed
fix: Use workspace ID to handle workspace updates
1 parent 9477792 commit fa3ab26

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/modules/hyprland/workspaces.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,13 @@ Json::Value Workspaces::createMonitorWorkspaceData(std::string const &name,
6464

6565
void Workspaces::createWorkspace(Json::Value const &workspace_data,
6666
Json::Value const &clients_data) {
67-
auto workspaceName = workspace_data["name"].asString();
6867
auto workspaceId = workspace_data["id"].asInt();
69-
spdlog::debug("Creating workspace {}", workspaceName);
68+
spdlog::debug("Creating workspace {}", workspaceId);
7069

7170
// avoid recreating existing workspaces
7271
auto workspace =
73-
std::ranges::find_if(m_workspaces, [&](std::unique_ptr<Workspace> const &w) {
74-
if (workspaceId > 0) {
75-
return w->id() == workspaceId;
76-
}
77-
return (workspaceName.starts_with("special:") && workspaceName.substr(8) == w->name()) ||
78-
workspaceName == w->name();
72+
std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr<Workspace> const &w) {
73+
return workspaceId == w->id();
7974
});
8075

8176
if (workspace != m_workspaces.end()) {
@@ -84,14 +79,14 @@ void Workspaces::createWorkspace(Json::Value const &workspace_data,
8479

8580
const auto *k = "persistent-rule";
8681
if (std::ranges::find(keys, k) != keys.end()) {
87-
spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceName,
82+
spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceId,
8883
workspace_data[k].asBool() ? "true" : "false");
8984
(*workspace)->setPersistentRule(workspace_data[k].asBool());
9085
}
9186

9287
k = "persistent-config";
9388
if (std::ranges::find(keys, k) != keys.end()) {
94-
spdlog::debug("Set config persistency of workspace {} to: {}", workspaceName,
89+
spdlog::debug("Set config persistency of workspace {} to: {}", workspaceId,
9590
workspace_data[k].asBool() ? "true" : "false");
9691
(*workspace)->setPersistentConfig(workspace_data[k].asBool());
9792
}
@@ -902,8 +897,7 @@ void Workspaces::updateWindowCount() {
902897
const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces");
903898
for (auto &workspace : m_workspaces) {
904899
auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const &x) {
905-
return x["name"].asString() == workspace->name() ||
906-
(workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name());
900+
return x["id"].asInt() == workspace->id();
907901
});
908902
uint32_t count = 0;
909903
if (workspaceJson != workspacesJson.end()) {
@@ -968,9 +962,7 @@ void Workspaces::updateWorkspaceStates() {
968962
workspaceIcon = workspace->selectIcon(m_iconsMap);
969963
}
970964
auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto &w) {
971-
auto wNameRaw = w["name"].asString();
972-
auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw;
973-
return wName == workspace->name();
965+
return w["id"].asInt() == workspace->id();
974966
});
975967
if (updatedWorkspace != updatedWorkspaces.end()) {
976968
workspace->setOutput((*updatedWorkspace)["monitor"].asString());

0 commit comments

Comments
 (0)