From 69d37d2663bdd69a4d7891baf68acf4f81a5610a Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Sun, 14 Jul 2024 16:59:06 +0200 Subject: [PATCH] core: immediately create session lock surfaces (#421) * core: immediately create session lock surfaces Instead of waiting for the `locked` event, create session lock surfaces right away. * core: don't allow unlock_and_destroy if `locked` has never been recieved --- src/core/hyprlock.cpp | 21 +++++++++++++++++---- src/core/hyprlock.hpp | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 9359ce0..727d5c7 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -400,6 +400,9 @@ void CHyprlock::run() { acquireSessionLock(); + if (m_bTerminate) // Recieved finished + exit(1); + g_pAuth = std::make_unique(); g_pAuth->start(); @@ -409,6 +412,8 @@ void CHyprlock::run() { registerSignalAction(SIGSEGV, handleCriticalSignal); registerSignalAction(SIGABRT, handleCriticalSignal); + createSessionLockSurfaces(); + pollfd pollfds[] = { { .fd = wl_display_get_fd(m_sWaylandState.display), @@ -925,7 +930,7 @@ void CHyprlock::acquireSessionLock() { m_sLockState.lock = ext_session_lock_manager_v1_lock(m_sWaylandState.sessionLock); ext_session_lock_v1_add_listener(m_sLockState.lock, &sessionLockListener, nullptr); - // wait for wayland to signal whether the session lock has been acquired + // roundtrip in case the compositor sends `finished` right away wl_display_roundtrip(m_sWaylandState.display); } @@ -936,6 +941,12 @@ void CHyprlock::releaseSessionLock() { return; } + if (!m_bLocked) { + // Would be a protocol error to allow this + Debug::log(ERR, "Trying to unlock the session, but never recieved the locked event!"); + return; + } + ext_session_lock_v1_unlock_and_destroy(m_sLockState.lock); m_sLockState.lock = nullptr; @@ -947,12 +958,14 @@ void CHyprlock::releaseSessionLock() { wl_display_roundtrip(m_sWaylandState.display); } -void CHyprlock::onLockLocked() { - Debug::log(LOG, "onLockLocked called"); - +void CHyprlock::createSessionLockSurfaces() { for (auto& o : m_vOutputs) { o->sessionLockSurface = std::make_unique(o.get()); } +} + +void CHyprlock::onLockLocked() { + Debug::log(LOG, "onLockLocked called"); m_bLocked = true; } diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 97b1680..7d34c51 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -46,6 +46,8 @@ class CHyprlock { void acquireSessionLock(); void releaseSessionLock(); + void createSessionLockSurfaces(); + void attemptRestoreOnDeath(); void spawnAsync(const std::string& cmd);