From a9d7526aae38dcdceb391fe9f00919c6c400abe3 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 26 Mar 2024 02:26:09 +0000 Subject: [PATCH] core: ensure m_pLastMonitor validity over unsafe state ref #5241 --- src/Compositor.cpp | 2 ++ src/events/Windows.cpp | 4 ++++ src/helpers/Monitor.cpp | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 2d6e7856..68db0091 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2808,6 +2808,8 @@ void CCompositor::enterUnsafeState() { m_pUnsafeOutput->onConnect(false); m_bUnsafeState = true; + + setActiveMonitor(m_pUnsafeOutput); } void CCompositor::leaveUnsafeState() { diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index d1cf9552..0d1665b7 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -53,6 +53,10 @@ void Events::listener_mapWindow(void* owner, void* data) { static auto PNEWTAKESOVERFS = CConfigValue("misc:new_window_takes_over_fullscreen"); auto PMONITOR = g_pCompositor->m_pLastMonitor; + if (!g_pCompositor->m_pLastMonitor) { + g_pCompositor->setActiveMonitor(g_pCompositor->getMonitorFromVector({})); + PMONITOR = g_pCompositor->m_pLastMonitor; + } auto PWORKSPACE = PMONITOR->specialWorkspaceID ? g_pCompositor->getWorkspaceByID(PMONITOR->specialWorkspaceID) : g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); PWINDOW->m_iMonitorID = PMONITOR->ID; PWINDOW->m_iWorkspaceID = PMONITOR->specialWorkspaceID ? PMONITOR->specialWorkspaceID : PMONITOR->activeWorkspace; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 3edb7ca4..219257b9 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -310,7 +310,7 @@ void CMonitor::onDisconnect(bool destroy) { Debug::log(WARN, "wlr_output_commit_state failed in CMonitor::onDisconnect"); if (g_pCompositor->m_pLastMonitor == this) - g_pCompositor->setActiveMonitor(BACKUPMON); + g_pCompositor->setActiveMonitor(BACKUPMON ? BACKUPMON : g_pCompositor->m_pUnsafeOutput); if (g_pHyprRenderer->m_pMostHzMonitor == this) { int mostHz = 0;