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/Compositor.cpp | 59 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index f1ac7b2b..681cbf86 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -463,6 +463,25 @@ void CCompositor::removeLockFile() { std::filesystem::remove(PATH); } +void CCompositor::prepareFallbackOutput() { + // create a backup monitor + wlr_backend* headless = nullptr; + wlr_multi_for_each_backend( + m_sWLRBackend, + [](wlr_backend* b, void* data) { + if (wlr_backend_is_headless(b)) + *((wlr_backend**)data) = b; + }, + &headless); + + if (!headless) { + Debug::log(WARN, "Unsafe state will be ineffective, no fallback output"); + return; + } + + wlr_headless_add_output(headless, 1920, 1080); +} + void CCompositor::startCompositor() { initAllSignals(); @@ -514,6 +533,8 @@ void CCompositor::startCompositor() { throwError("The backend could not start!"); } + prepareFallbackOutput(); + g_pHyprRenderer->setCursorFromName("left_ptr"); #ifdef USES_SYSTEMD @@ -2657,24 +2678,10 @@ void CCompositor::enterUnsafeState() { Debug::log(LOG, "Entering unsafe state"); - m_bUnsafeState = true; - - // create a backup monitor - wlr_backend* headless = nullptr; - wlr_multi_for_each_backend( - m_sWLRBackend, - [](wlr_backend* b, void* data) { - if (wlr_backend_is_headless(b)) - *((wlr_backend**)data) = b; - }, - &headless); - - if (!headless) { - Debug::log(WARN, "Entering an unsafe state without a headless backend"); - return; - } + if (!m_pUnsafeOutput->m_bEnabled) + m_pUnsafeOutput->onConnect(false); - m_pUnsafeOutput = wlr_headless_add_output(headless, 1920, 1080); + m_bUnsafeState = true; } void CCompositor::leaveUnsafeState() { @@ -2685,10 +2692,22 @@ void CCompositor::leaveUnsafeState() { m_bUnsafeState = false; - if (m_pUnsafeOutput) - wlr_output_destroy(m_pUnsafeOutput); + CMonitor* pNewMonitor = nullptr; + for (auto& pMonitor : m_vMonitors) { + if (pMonitor->output != m_pUnsafeOutput->output) { + pNewMonitor = pMonitor.get(); + break; + } + } + + RASSERT(pNewMonitor, "Tried to leave unsafe without a monitor"); + + if (m_pUnsafeOutput->m_bEnabled) + m_pUnsafeOutput->onDisconnect(); - m_pUnsafeOutput = nullptr; + for (auto& m : m_vMonitors) { + scheduleFrameForMonitor(m.get()); + } } void CCompositor::setPreferredScaleForSurface(wlr_surface* pSurface, double scale) { -- cgit v1.2.3