fix: Use workspace ID to handle workspace updates
This commit is contained in:
committed by
Alexays
parent
0bb207d56f
commit
7c86f1ccb4
@@ -79,17 +79,13 @@ 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<Workspace> 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<Workspace> const& w) {
|
||||
return workspaceId == w->id();
|
||||
});
|
||||
|
||||
if (workspace != m_workspaces.end()) {
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user