Skip to content

Commit 4bce96c

Browse files
committed
fix: Use workspace ID to handle workspace updates
1 parent 559079e commit 4bce96c

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/modules/hyprland/workspaces.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,29 @@ 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
72-
auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr<Workspace> const &w) {
73-
if (workspaceId > 0) {
74-
return w->id() == workspaceId;
75-
}
76-
return (workspaceName.starts_with("special:") && workspaceName.substr(8) == w->name()) ||
77-
workspaceName == w->name();
78-
});
71+
auto workspace =
72+
std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr<Workspace> const &w) {
73+
return workspaceId == w->id();
74+
});
7975

8076
if (workspace != m_workspaces.end()) {
8177
// don't recreate workspace, but update persistency if necessary
8278
const auto keys = workspace_data.getMemberNames();
8379

8480
const auto *k = "persistent-rule";
8581
if (std::ranges::find(keys, k) != keys.end()) {
86-
spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceName,
82+
spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceId,
8783
workspace_data[k].asBool() ? "true" : "false");
8884
(*workspace)->setPersistentRule(workspace_data[k].asBool());
8985
}
9086

9187
k = "persistent-config";
9288
if (std::ranges::find(keys, k) != keys.end()) {
93-
spdlog::debug("Set config persistency of workspace {} to: {}", workspaceName,
89+
spdlog::debug("Set config persistency of workspace {} to: {}", workspaceId,
9490
workspace_data[k].asBool() ? "true" : "false");
9591
(*workspace)->setPersistentConfig(workspace_data[k].asBool());
9692
}
@@ -1014,8 +1010,7 @@ void Workspaces::updateWindowCount() {
10141010
const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces");
10151011
for (auto const &workspace : m_workspaces) {
10161012
auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const &x) {
1017-
return x["name"].asString() == workspace->name() ||
1018-
(workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name());
1013+
return x["id"].asInt() == workspace->id();
10191014
});
10201015
uint32_t count = 0;
10211016
if (workspaceJson != workspacesJson.end()) {
@@ -1080,9 +1075,7 @@ void Workspaces::updateWorkspaceStates() {
10801075
workspaceIcon = workspace->selectIcon(m_iconsMap);
10811076
}
10821077
auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto &w) {
1083-
auto wNameRaw = w["name"].asString();
1084-
auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw;
1085-
return wName == workspace->name();
1078+
return w["id"].asInt() == workspace->id();
10861079
});
10871080
if (updatedWorkspace != updatedWorkspaces.end()) {
10881081
workspace->setOutput((*updatedWorkspace)["monitor"].asString());

0 commit comments

Comments
 (0)