diff --git a/src/core/Output.cpp b/src/core/Output.cpp index 82986bd..1a77287 100644 --- a/src/core/Output.cpp +++ b/src/core/Output.cpp @@ -18,10 +18,10 @@ COutput::COutput(SP output_, uint32_t name_) : name(name_), output(o output->setScale([this](CCWlOutput* r, int32_t sc) { scale = sc; }); output->setDone([this](CCWlOutput* r) { + done = true; Debug::log(LOG, "output {} done", name); - if (g_pHyprlock->m_bLocked && !sessionLockSurface) { - // if we are already locked, create a surface dynamically - Debug::log(LOG, "Creating a surface dynamically for output as we are already locked"); + if (g_pHyprlock->m_lockAquired && !sessionLockSurface) { + Debug::log(LOG, "output {} creating a new lock surface", name); sessionLockSurface = std::make_unique(this); } }); diff --git a/src/core/Output.hpp b/src/core/Output.hpp index d42c800..3b2d045 100644 --- a/src/core/Output.hpp +++ b/src/core/Output.hpp @@ -12,6 +12,7 @@ class COutput { uint32_t name = 0; bool focused = false; + bool done = false; wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL; Vector2D size; int scale = 1; diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 144b288..27db6fc 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -345,10 +345,8 @@ void CHyprlock::run() { } } - acquireSessionLock(); - - // Recieved finished - if (m_bTerminate) { + // Failed to lock the session + if (!acquireSessionLock()) { m_sLoopState.timerEvent = true; m_sLoopState.timerCV.notify_all(); g_pRenderer->asyncResourceGatherer->notify(); @@ -366,8 +364,6 @@ void CHyprlock::run() { registerSignalAction(SIGSEGV, handleCriticalSignal); registerSignalAction(SIGABRT, handleCriticalSignal); - createSessionLockSurfaces(); - pollfd pollfds[2]; pollfds[0] = { .fd = wl_display_get_fd(m_sWaylandState.display), @@ -433,7 +429,7 @@ void CHyprlock::run() { float least = 10000; for (auto& t : m_vTimers) { const auto TIME = std::clamp(t->leftMs(), 1.f, INFINITY); - least = std::min(TIME, least); + least = std::min(TIME, least); } m_sLoopState.timersMutex.unlock(); @@ -701,9 +697,13 @@ void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) { } } -void CHyprlock::acquireSessionLock() { +bool CHyprlock::acquireSessionLock() { Debug::log(LOG, "Locking session"); m_sLockState.lock = makeShared(m_sWaylandState.sessionLock->sendLock()); + if (!m_sLockState.lock) { + Debug::log(ERR, "Failed to create a lock object!"); + return false; + } m_sLockState.lock->setLocked([this](CCExtSessionLockV1* r) { onLockLocked(); }); @@ -711,6 +711,22 @@ void CHyprlock::acquireSessionLock() { // roundtrip in case the compositor sends `finished` right away wl_display_roundtrip(m_sWaylandState.display); + + // recieved finished right away (probably already locked) + if (m_bTerminate) + return false; + + m_lockAquired = true; + + // create a session lock surface for exiting outputs + for (auto& o : m_vOutputs) { + if (!o->done) + continue; + + o->sessionLockSurface = std::make_unique(o.get()); + } + + return true; } void CHyprlock::releaseSessionLock() { @@ -743,12 +759,6 @@ void CHyprlock::releaseSessionLock() { wl_display_roundtrip(m_sWaylandState.display); } -void CHyprlock::createSessionLockSurfaces() { - for (auto& o : m_vOutputs) { - o->sessionLockSurface = std::make_unique(o.get()); - } -} - void CHyprlock::onLockLocked() { Debug::log(LOG, "onLockLocked called"); diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 862348e..fac850b 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -48,11 +48,9 @@ class CHyprlock { void onLockLocked(); void onLockFinished(); - void acquireSessionLock(); + bool acquireSessionLock(); void releaseSessionLock(); - void createSessionLockSurfaces(); - void attemptRestoreOnDeath(); std::string spawnSync(const std::string& cmd); @@ -88,7 +86,8 @@ class CHyprlock { bool m_bTerminate = false; - bool m_bLocked = false; + bool m_lockAquired = false; + bool m_bLocked = false; bool m_bCapsLock = false; bool m_bNumLock = false;