From 46d66f4bcc95d9fb7fede18ad5c2c043796b9071 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:04:38 +0100 Subject: internal: Further unsafe state improvements (#3404) Instead of allowing Hyprland to sit in a state where there are no monitors, which various parts of the code don't like, we create a fake headless output on all monitor disconnect, and then remove it when a monitor appears --- src/Compositor.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 92545faf..4ddac879 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2604,3 +2604,43 @@ void CCompositor::arrangeMonitors() { m->xwaylandScale = 1.f; } } + +void CCompositor::enterUnsafeState() { + if (m_bUnsafeState) + return; + + 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; + } + + m_pUnsafeOutput = wlr_headless_add_output(headless, 1920, 1080); +} + +void CCompositor::leaveUnsafeState() { + if (!m_bUnsafeState) + return; + + Debug::log(LOG, "Leaving unsafe state"); + + m_bUnsafeState = false; + + if (m_pUnsafeOutput) + wlr_output_destroy(m_pUnsafeOutput); + + m_pUnsafeOutput = nullptr; +} -- cgit v1.2.3