From 7ee406bf9b11351e3d73e6b6b2aec7de93ba61bf Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Fri, 15 Mar 2024 19:49:07 +0100 Subject: [PATCH] core: fade out improvements (#194) * core: allow fade out for grace unlock * core: disable input once fade out started * core: render when fade out started * core: allow fade out for other compositors Works fine in sway altough it fades to a black screen not to the desktop. Still looks kinda good. * Revert "core: allow fade out for other compositors" This reverts commit adfeb543ad38805e165ee67c9ae2bcd29c1d6d9f. * misc: rename lock and unlock functions --- src/core/hyprlock.cpp | 54 +++++++++++++++++++++++++++---------------- src/core/hyprlock.hpp | 10 ++++---- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 38937de..512e639 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -304,7 +304,7 @@ static void registerSignalAction(int sig, void (*handler)(int), int sa_flags = 0 static void handleUnlockSignal(int sig) { if (sig == SIGUSR1) { Debug::log(LOG, "Unlocking with a SIGUSR1"); - g_pHyprlock->unlockSession(); + g_pHyprlock->releaseSessionLock(); } } @@ -377,7 +377,7 @@ void CHyprlock::run() { } } - lockSession(); + acquireSessionLock(); registerSignalAction(SIGUSR1, handleUnlockSignal, SA_RESTART); registerSignalAction(SIGUSR2, handleForceUpdateSignal); @@ -458,7 +458,7 @@ void CHyprlock::run() { m_sLoopState.loopCV.wait_for(lk, std::chrono::milliseconds(5000), [this] { return m_sLoopState.event; }); if (m_bTerminate || (std::chrono::system_clock::now() > m_tFadeEnds && m_bFadeStarted)) { - unlockSession(); + releaseSessionLock(); break; } std::lock_guard lg(m_sLoopState.eventLoopMutex); @@ -506,8 +506,8 @@ void CHyprlock::run() { passed.clear(); - if (m_bTerminate || (std::chrono::system_clock::now() > m_tFadeEnds && m_bFadeStarted)) { - unlockSession(); + if (m_bTerminate || (std::chrono::system_clock::now() > m_tFadeEnds && m_bFadeStarted)) { + releaseSessionLock(); break; } } @@ -531,6 +531,24 @@ void CHyprlock::run() { Debug::log(LOG, "Reached the end, exiting"); } +void CHyprlock::unlock() { + static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out"); + const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP"); + const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""}; + + if (**PNOFADEOUT || SZCURRENTD != "Hyprland") { + releaseSessionLock(); + return; + } + + m_tFadeEnds = std::chrono::system_clock::now() + std::chrono::milliseconds(500); + m_bFadeStarted = true; + + for (auto& o : m_vOutputs) { + o->sessionLockSurface->render(); + } +} + // wl_seat static void handlePointerEnter(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) { @@ -557,10 +575,10 @@ static void handlePointerAxis(void* data, wl_pointer* wl_pointer, uint32_t time, static void handlePointerMotion(void* data, struct wl_pointer* wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { if (g_pHyprlock->m_vLastEnterCoords.distance({wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)}) > 5 && - std::chrono::system_clock::now() < g_pHyprlock->m_tGraceEnds) { + std::chrono::system_clock::now() < g_pHyprlock->m_tGraceEnds && !g_pHyprlock->m_bFadeStarted) { Debug::log(LOG, "In grace and cursor moved more than 5px, unlocking!"); - g_pHyprlock->unlockSession(); + g_pHyprlock->unlock(); } } @@ -706,16 +724,9 @@ static const ext_session_lock_v1_listener sessionLockListener = { // end session_lock void CHyprlock::onPasswordCheckTimer() { - static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out"); - const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP"); - const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""}; - // check result if (m_sPasswordState.result->success) { - if (**PNOFADEOUT || SZCURRENTD != "Hyprland") - unlockSession(); - m_tFadeEnds = std::chrono::system_clock::now() + std::chrono::milliseconds(500); - m_bFadeStarted = true; + unlock(); } else { Debug::log(LOG, "Authentication failed: {}", m_sPasswordState.result->failReason); m_sPasswordState.lastFailReason = m_sPasswordState.result->failReason; @@ -741,10 +752,11 @@ std::optional CHyprlock::passwordLastFailReason() { } void CHyprlock::onKey(uint32_t key, bool down) { - const auto SYM = xkb_state_key_get_one_sym(m_pXKBState, key + 8); + if (m_bFadeStarted) + return; - if (down && std::chrono::system_clock::now() < g_pHyprlock->m_tGraceEnds) { - unlockSession(); + if (down && std::chrono::system_clock::now() < m_tGraceEnds) { + unlock(); return; } @@ -771,6 +783,8 @@ void CHyprlock::onKey(uint32_t key, bool down) { return; } + const auto SYM = xkb_state_key_get_one_sym(m_pXKBState, key + 8); + m_bCapsLock = xkb_state_mod_name_is_active(g_pHyprlock->m_pXKBState, XKB_MOD_NAME_CAPS, XKB_STATE_MODS_LOCKED); m_bNumLock = xkb_state_mod_name_is_active(g_pHyprlock->m_pXKBState, XKB_MOD_NAME_NUM, XKB_STATE_MODS_LOCKED); @@ -800,13 +814,13 @@ void CHyprlock::onKey(uint32_t key, bool down) { } } -void CHyprlock::lockSession() { +void CHyprlock::acquireSessionLock() { Debug::log(LOG, "Locking session"); m_sLockState.lock = ext_session_lock_manager_v1_lock(m_sWaylandState.sessionLock); ext_session_lock_v1_add_listener(m_sLockState.lock, &sessionLockListener, nullptr); } -void CHyprlock::unlockSession() { +void CHyprlock::releaseSessionLock() { Debug::log(LOG, "Unlocking session"); if (m_bTerminate && !m_sLockState.lock) { Debug::log(ERR, "Unlock already happend?"); diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 99d6e2d..088ff03 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -32,6 +32,8 @@ class CHyprlock { void run(); + void unlock(); + void onGlobal(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version); void onGlobalRemoved(void* data, struct wl_registry* registry, uint32_t name); @@ -41,8 +43,8 @@ class CHyprlock { void onLockLocked(); void onLockFinished(); - void lockSession(); - void unlockSession(); + void acquireSessionLock(); + void releaseSessionLock(); void attemptRestoreOnDeath(); @@ -79,8 +81,8 @@ class CHyprlock { bool m_bLocked = false; - bool m_bCapsLock = false; - bool m_bNumLock = false; + bool m_bCapsLock = false; + bool m_bNumLock = false; bool m_bFadeStarted = false; // std::chrono::system_clock::time_point m_tGraceEnds;