From afe8d8dfece87cb3b5f8429964e77d4ebf7b2959 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 6 May 2023 16:49:46 +0100 Subject: [PATCH] monitors: fix some bugs with re-plug --- src/Compositor.cpp | 22 ++++++++++++++-------- src/helpers/Monitor.cpp | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 4c6af7ab..c95cd58e 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1859,7 +1859,7 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni const auto POLDMON = getMonitorFromID(pWorkspace->m_iMonitorID); - const bool SWITCHINGISACTIVE = POLDMON->activeWorkspace == pWorkspace->m_iID; + const bool SWITCHINGISACTIVE = POLDMON ? POLDMON->activeWorkspace == pWorkspace->m_iID : false; // fix old mon int nextWorkspaceOnMonitorID = -1; @@ -1906,12 +1906,16 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni // additionally, move floating and fs windows manually if (w->m_bIsMapped && !w->isHidden()) { - if (w->m_bIsFloating) - w->m_vRealPosition = w->m_vRealPosition.vec() - POLDMON->vecPosition + pMonitor->vecPosition; + if (POLDMON) { + if (w->m_bIsFloating) + w->m_vRealPosition = w->m_vRealPosition.vec() - POLDMON->vecPosition + pMonitor->vecPosition; - if (w->m_bIsFullscreen) { - w->m_vRealPosition = pMonitor->vecPosition; - w->m_vRealSize = pMonitor->vecSize; + if (w->m_bIsFullscreen) { + w->m_vRealPosition = pMonitor->vecPosition; + w->m_vRealSize = pMonitor->vecSize; + } + } else { + w->m_vRealPosition = Vector2D{(int)w->m_vRealPosition.goalv().x % (int)pMonitor->vecSize.x, (int)w->m_vRealPosition.goalv().y % (int)pMonitor->vecSize.y}; } } @@ -1936,10 +1940,12 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni } // finalize - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID); + if (POLDMON) { + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID); + updateFullscreenFadeOnWorkspace(getWorkspaceByID(POLDMON->activeWorkspace)); + } updateFullscreenFadeOnWorkspace(pWorkspace); - updateFullscreenFadeOnWorkspace(getWorkspaceByID(POLDMON->activeWorkspace)); // event g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspace", pWorkspace->m_szName + "," + pMonitor->szName}); diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 1102517d..166a18d4 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -145,7 +145,7 @@ void CMonitor::onConnect(bool noRule) { setupDefaultWS(monitorRule); for (auto& ws : g_pCompositor->m_vWorkspaces) { - if (ws->m_szLastMonitor == szName) { + if (ws->m_szLastMonitor == szName || g_pCompositor->m_vMonitors.size() == 1 /* avoid lost workspaces on recover */) { g_pCompositor->moveWorkspaceToMonitor(ws.get(), this); ws->startAnim(true, true, true); ws->m_szLastMonitor = "";