core: fix workspace persistence tracking (#11239)

This commit is contained in:
Vaxry 2025-07-27 18:46:23 +02:00 committed by GitHub
parent 5d4b4ecbfb
commit c63d0003a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 140 additions and 10 deletions

View file

@ -3109,6 +3109,8 @@ void CCompositor::ensurePersistentWorkspacesPresent(const std::vector<SWorkspace
if (!m_lastMonitor)
return;
std::vector<PHLWORKSPACE> persistentFound;
for (const auto& rule : rules) {
if (!rule.isPersistent)
continue;
@ -3142,17 +3144,20 @@ void CCompositor::ensurePersistentWorkspacesPresent(const std::vector<SWorkspace
}
PWORKSPACE = getWorkspaceByID(id);
if (!PWORKSPACE)
createNewWorkspace(id, PMONITOR ? PMONITOR->m_id : m_lastMonitor->m_id, wsname, false);
PWORKSPACE = createNewWorkspace(id, PMONITOR ? PMONITOR->m_id : m_lastMonitor->m_id, wsname, false);
}
if (PWORKSPACE)
PWORKSPACE->m_persistent = true;
if (!PMONITOR) {
Debug::log(ERR, "ensurePersistentWorkspacesPresent: couldn't resolve monitor for {}, skipping", rule.monitor);
continue;
}
if (PWORKSPACE)
PWORKSPACE->setPersistent(true);
if (!pWorkspace)
persistentFound.emplace_back(PWORKSPACE);
if (PWORKSPACE) {
if (PWORKSPACE->m_monitor == PMONITOR) {
Debug::log(LOG, "ensurePersistentWorkspacesPresent: workspace persistent {} already on {}", rule.workspaceString, PMONITOR->m_name);
@ -3165,4 +3170,22 @@ void CCompositor::ensurePersistentWorkspacesPresent(const std::vector<SWorkspace
continue;
}
}
if (!pWorkspace) {
// check non-persistent and downgrade if workspace is no longer persistent
std::vector<PHLWORKSPACEREF> toDowngrade;
for (auto& w : getWorkspaces()) {
if (!w->isPersistent())
continue;
if (std::ranges::contains(persistentFound, w.lock()))
continue;
toDowngrade.emplace_back(w);
}
for (auto& ws : toDowngrade) {
ws->setPersistent(false);
}
}
}