From 533bc5115e49a6d0d093b45f7db65854bc9a0494 Mon Sep 17 00:00:00 2001 From: Nathan Ollerenshaw Date: Mon, 14 Apr 2025 02:07:53 -0700 Subject: monitors: fix disconnected monitors are reconnected to an empty workspace (#9874) --------- Co-authored-by: nyx --- src/helpers/Monitor.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/helpers/Monitor.cpp') diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 97f74609..e30849a7 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -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) g_pCompositor->setActiveMonitor(self.lock()); @@ -273,6 +286,12 @@ void CMonitor::onDisconnect(bool destroy) { 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. PHLMONITOR BACKUPMON = nullptr; for (auto const& m : g_pCompositor->m_vMonitors) { -- cgit v1.2.3