monitors: fix disconnected monitors are reconnected to an empty workspace (#9874)

---------

Co-authored-by: nyx <nnyyxxxx@protonmail.com>
This commit is contained in:
Nathan Ollerenshaw
2025-04-14 02:07:53 -07:00
committed by GitHub
parent 99ab3e19d9
commit 533bc5115e
3 changed files with 60 additions and 40 deletions

View File

@@ -47,6 +47,7 @@ class CCompositor {
std::vector<PHLLSREF> m_vSurfacesFadingOut; std::vector<PHLLSREF> m_vSurfacesFadingOut;
std::unordered_map<std::string, MONITORID> m_mMonitorIDMap; std::unordered_map<std::string, MONITORID> m_mMonitorIDMap;
std::unordered_map<std::string, WORKSPACEID> m_mSeenMonitorWorkspaceMap; // map of seen monitor names to workspace IDs
void initServer(std::string socketName, int socketFd); void initServer(std::string socketName, int socketFd);
void startCompositor(); void startCompositor();

View File

@@ -235,6 +235,19 @@ void CMonitor::onConnect(bool noRule) {
} }
} }
Debug::log(LOG, "checking if we have seen this monitor before: {}", szName);
// if we saw this monitor before, set it to the workspace it was on
if (g_pCompositor->m_mSeenMonitorWorkspaceMap.contains(szName)) {
auto workspaceID = g_pCompositor->m_mSeenMonitorWorkspaceMap[szName];
Debug::log(LOG, "Monitor {} was on workspace {}, setting it to that", szName, workspaceID);
auto ws = g_pCompositor->getWorkspaceByID(workspaceID);
if (ws) {
g_pCompositor->moveWorkspaceToMonitor(ws, self.lock());
changeWorkspace(ws, true, false, false);
}
} else
Debug::log(LOG, "Monitor {} was not on any workspace", szName);
if (!found) if (!found)
g_pCompositor->setActiveMonitor(self.lock()); g_pCompositor->setActiveMonitor(self.lock());
@@ -273,6 +286,12 @@ void CMonitor::onDisconnect(bool destroy) {
events.disconnect.emit(); events.disconnect.emit();
// record what workspace this monitor was on
if (activeWorkspace) {
Debug::log(LOG, "Disconnecting Monitor {} was on workspace {}", szName, activeWorkspace->m_iID);
g_pCompositor->m_mSeenMonitorWorkspaceMap[szName] = activeWorkspace->m_iID;
}
// Cleanup everything. Move windows back, snap cursor, shit. // Cleanup everything. Move windows back, snap cursor, shit.
PHLMONITOR BACKUPMON = nullptr; PHLMONITOR BACKUPMON = nullptr;
for (auto const& m : g_pCompositor->m_vMonitors) { for (auto const& m : g_pCompositor->m_vMonitors) {