From 410da2e46fc44d93196cd902a070391a416cff01 Mon Sep 17 00:00:00 2001 From: Roberto Previdi Date: Sat, 15 Feb 2025 15:01:52 +0100 Subject: workspaces: update persistence on workspace rename (#9368) --- src/Compositor.cpp | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 6d9e8d7e..5389844f 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -3043,34 +3043,53 @@ bool CCompositor::shouldChangePreferredImageDescription() { return false; } -void CCompositor::ensurePersistentWorkspacesPresent(const std::vector& rules) { +void CCompositor::ensurePersistentWorkspacesPresent(const std::vector& rules, PHLWORKSPACE pWorkspace) { + for (const auto& rule : rules) { if (!rule.isPersistent) continue; + PHLWORKSPACE PWORKSPACE = nullptr; + if (pWorkspace) { + if (pWorkspace->matchesStaticSelector(rule.workspaceString)) + PWORKSPACE = pWorkspace; + else + continue; + } + const auto PMONITOR = getMonitorFromString(rule.monitor); - if (!PMONITOR) { - Debug::log(ERR, "ensurePersistentWorkspacesPresent: couldn't resolve monitor for {}, skipping", rule.monitor); - continue; - } + if (!PWORKSPACE) { + WORKSPACEID id = rule.workspaceId; + std::string wsname = rule.workspaceName; - WORKSPACEID id = rule.workspaceId; - std::string wsname = rule.workspaceName; - if (id == WORKSPACE_INVALID) { - const auto R = getWorkspaceIDNameFromString(rule.workspaceString); - id = R.id; - wsname = R.name; + if (id == WORKSPACE_INVALID) { + const auto R = getWorkspaceIDNameFromString(rule.workspaceString); + id = R.id; + wsname = R.name; + } + + if (id == WORKSPACE_INVALID) { + Debug::log(ERR, "ensurePersistentWorkspacesPresent: couldn't resolve id for workspace {}", rule.workspaceString); + continue; + } + PWORKSPACE = getWorkspaceByID(id); + if (!PWORKSPACE) + createNewWorkspace(id, PMONITOR ? PMONITOR : m_pLastMonitor.lock(), wsname, false); } - if (id == WORKSPACE_INVALID) { - Debug::log(ERR, "ensurePersistentWorkspacesPresent: couldn't resolve id for workspace {}", rule.workspaceString); + if (PWORKSPACE) + PWORKSPACE->m_bPersistent = true; + + if (!PMONITOR) { + Debug::log(ERR, "ensurePersistentWorkspacesPresent: couldn't resolve monitor for {}, skipping", rule.monitor); continue; } - if (const auto PWORKSPACE = getWorkspaceByID(id); PWORKSPACE) { + if (PWORKSPACE) { if (PWORKSPACE->m_pMonitor == PMONITOR) { Debug::log(LOG, "ensurePersistentWorkspacesPresent: workspace persistent {} already on {}", rule.workspaceString, PMONITOR->szName); + continue; } @@ -3078,8 +3097,6 @@ void CCompositor::ensurePersistentWorkspacesPresent(const std::vector