From 2b430c5d8a6d17b6621761107b9453835eff9787 Mon Sep 17 00:00:00 2001 From: Maximilian Seidler Date: Wed, 6 Mar 2024 11:36:51 +0100 Subject: [PATCH] core: add passwordEmptyTimerCallback --- src/config/ConfigManager.cpp | 1 + src/core/hyprlock.cpp | 29 ++++++++++++++++++++++++++--- src/core/hyprlock.hpp | 4 +++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 97db9ead..590694d7 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -46,6 +46,7 @@ void CConfigManager::init() { m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0}); m_config.addConfigValue("general:grace", Hyprlang::INT{0}); m_config.addConfigValue("general:no_fade_in", Hyprlang::INT{0}); + m_config.addConfigValue("general:input_empty_fade_timeout", Hyprlang::INT{1000}); m_config.addSpecialCategory("background", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true}); m_config.addSpecialConfigValue("background", "monitor", Hyprlang::STRING{""}); diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index b33ac7aa..731cd595 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -30,8 +30,10 @@ CHyprlock::CHyprlock(const std::string& wlDisplay) { if (!m_pXKBContext) Debug::log(ERR, "Failed to create xkb context"); - const auto GRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace"); - m_tGraceEnds = **GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**GRACE) : std::chrono::system_clock::from_time_t(0); + const auto GRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace"); + m_tGraceEnds = **GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**GRACE) : std::chrono::system_clock::from_time_t(0); + const auto FADETIMEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:input_empty_fade_timeout"); + m_iEmptyPasswordTimeoutMs = **FADETIMEOUT; } // wl_seat @@ -654,6 +656,14 @@ static const ext_session_lock_v1_listener sessionLockListener = { // end session_lock +static void passwordEmptyTimerCallback(std::shared_ptr self, void* data) { + g_pRenderer->onEmptyPasswordFade(); + + for (auto& o : g_pHyprlock->m_vOutputs) { + o->sessionLockSurface->render(); + } +} + void CHyprlock::onPasswordCheckTimer() { // check result if (m_sPasswordState.result->success) { @@ -669,6 +679,12 @@ void CHyprlock::onPasswordCheckTimer() { } m_sPasswordState.result.reset(); + + if (m_sPasswordState.emptyBufferTimer.get()) { + m_sPasswordState.emptyBufferTimer->cancel(); + m_sPasswordState.emptyBufferTimer.reset(); + } + m_sPasswordState.emptyBufferTimer = addTimer(std::chrono::milliseconds(m_iEmptyPasswordTimeoutMs), passwordEmptyTimerCallback, nullptr); } bool CHyprlock::passwordCheckWaiting() { @@ -730,6 +746,13 @@ void CHyprlock::onKey(uint32_t key, bool down) { m_sPasswordState.passBuffer += std::string{buf, len - 1}; } + if (m_sPasswordState.passBuffer.empty() && !m_sPasswordState.emptyBufferTimer.get()) + m_sPasswordState.emptyBufferTimer = addTimer(std::chrono::milliseconds(m_iEmptyPasswordTimeoutMs), passwordEmptyTimerCallback, nullptr); + else if (!m_sPasswordState.passBuffer.empty() && m_sPasswordState.emptyBufferTimer.get()) { + m_sPasswordState.emptyBufferTimer->cancel(); + m_sPasswordState.emptyBufferTimer.reset(); + } + for (auto& o : m_vOutputs) { o->sessionLockSurface->render(); } @@ -920,4 +943,4 @@ void CHyprlock::attemptRestoreOnDeath() { spawnSync("hyprctl keyword misc:allow_session_lock_restore true"); spawnAsync("sleep 2 && hyprlock & disown"); -} \ No newline at end of file +} diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index d21e3811..24bb2bcb 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -78,7 +78,8 @@ class CHyprlock { // std::chrono::system_clock::time_point m_tGraceEnds; - Vector2D m_vLastEnterCoords = {}; + Vector2D m_vLastEnterCoords = {}; + uint64_t m_iEmptyPasswordTimeoutMs = 0; std::vector> m_vOutputs; @@ -117,6 +118,7 @@ class CHyprlock { std::string passBuffer = ""; std::shared_ptr result; std::optional lastFailReason; + std::shared_ptr emptyBufferTimer; } m_sPasswordState; struct {