From 21e9313c100e005ec2a9a5100c29258a2885546b Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Wed, 1 Nov 2023 18:53:36 +0000 Subject: Core: various unsafe state improvements (#3713) Fixes #3637 --- src/helpers/Monitor.cpp | 53 +++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'src/helpers/Monitor.cpp') diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index e96da35c..6d6b40e0 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -109,20 +109,20 @@ void CMonitor::onConnect(bool noRule) { m_bRenderingInitPassed = true; } - if (!m_pThisWrap) { + std::shared_ptr* thisWrapper = nullptr; - // find the wrap - for (auto& m : g_pCompositor->m_vRealMonitors) { - if (m->ID == ID) { - m_pThisWrap = &m; - break; - } + // find the wrap + for (auto& m : g_pCompositor->m_vRealMonitors) { + if (m->ID == ID) { + thisWrapper = &m; + break; } } - if (std::find_if(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](auto& other) { return other.get() == this; }) == g_pCompositor->m_vMonitors.end()) { - g_pCompositor->m_vMonitors.push_back(*m_pThisWrap); - } + RASSERT(thisWrapper->get(), "CMonitor::onConnect: Had no wrapper???"); + + if (std::find_if(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](auto& other) { return other.get() == this; }) == g_pCompositor->m_vMonitors.end()) + g_pCompositor->m_vMonitors.push_back(*thisWrapper); m_bEnabled = true; @@ -132,6 +132,8 @@ void CMonitor::onConnect(bool noRule) { if (!noRule) g_pHyprRenderer->applyMonitorRule(this, &monitorRule, true); + wlr_output_commit(output); + wlr_damage_ring_set_bounds(&damage, vecTransformedSize.x, vecTransformedSize.y); wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, scale); @@ -152,8 +154,6 @@ void CMonitor::onConnect(bool noRule) { if (scale < 0.1) scale = getDefaultScale(); - m_pThisWrap = nullptr; - forceFullFrames = 3; // force 3 full frames to make sure there is no blinking due to double-buffering. // @@ -184,6 +184,8 @@ void CMonitor::onConnect(bool noRule) { g_pCompositor->setActiveMonitor(this); renderTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, ratHandler, this); + + g_pCompositor->scheduleFrameForMonitor(this); } void CMonitor::onDisconnect() { @@ -221,9 +223,6 @@ void CMonitor::onDisconnect() { g_pConfigManager->m_bWantsMonitorReload = true; } - m_bEnabled = false; - m_bRenderingInitPassed = false; - hyprListener_monitorFrame.removeCallback(); hyprListener_monitorDamage.removeCallback(); hyprListener_monitorNeedsFrame.removeCallback(); @@ -248,6 +247,9 @@ void CMonitor::onDisconnect() { g_pCompositor->enterUnsafeState(); } + m_bEnabled = false; + m_bRenderingInitPassed = false; + if (BACKUPMON) { // snap cursor wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, BACKUPMON->vecPosition.x + BACKUPMON->vecTransformedSize.x / 2.f, @@ -256,7 +258,7 @@ void CMonitor::onDisconnect() { // move workspaces std::deque wspToMove; for (auto& w : g_pCompositor->m_vWorkspaces) { - if (w->m_iMonitorID == ID) { + if (w->m_iMonitorID == ID || !g_pCompositor->getMonitorFromID(w->m_iMonitorID)) { wspToMove.push_back(w.get()); } } @@ -414,19 +416,22 @@ void CMonitor::setMirror(const std::string& mirrorOf) { vecPosition = RULE.offset; // push to mvmonitors - if (!m_pThisWrap) { - // find the wrap - for (auto& m : g_pCompositor->m_vRealMonitors) { - if (m->ID == ID) { - m_pThisWrap = &m; - break; - } + + std::shared_ptr* thisWrapper = nullptr; + + // find the wrap + for (auto& m : g_pCompositor->m_vRealMonitors) { + if (m->ID == ID) { + thisWrapper = &m; + break; } } + RASSERT(thisWrapper->get(), "CMonitor::setMirror: Had no wrapper???"); + if (std::find_if(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](auto& other) { return other.get() == this; }) == g_pCompositor->m_vMonitors.end()) { - g_pCompositor->m_vMonitors.push_back(*m_pThisWrap); + g_pCompositor->m_vMonitors.push_back(*thisWrapper); } setupDefaultWS(RULE); -- cgit v1.2.3