summaryrefslogtreecommitdiff
path: root/src/Compositor.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2023-09-24 18:04:38 +0100
committerGitHub <noreply@github.com>2023-09-24 18:04:38 +0100
commit46d66f4bcc95d9fb7fede18ad5c2c043796b9071 (patch)
tree0631539b1c73ff76cf72fb1d9668f0adcd49b135 /src/Compositor.cpp
parent352ceb1117b79cd0bc3fa86ebe435b6909512ddb (diff)
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
Diffstat (limited to 'src/Compositor.cpp')
-rw-r--r--src/Compositor.cpp40
1 files changed, 40 insertions, 0 deletions
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;
+}