From ce1eb7b5f9f95f3d6af96702784dd032101e753a Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Wed, 2 Apr 2025 22:13:22 +0200 Subject: [PATCH] core: move fail_timeout from input-field to general (#718) --- src/auth/Auth.cpp | 29 ++++++++++++++++++--- src/auth/Auth.hpp | 4 +++ src/config/ConfigManager.cpp | 3 +-- src/core/hyprlock.cpp | 3 +++ src/renderer/widgets/PasswordInputField.cpp | 19 ++++---------- src/renderer/widgets/PasswordInputField.hpp | 2 -- 6 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/auth/Auth.cpp b/src/auth/Auth.cpp index 0cc9c04..6337f5e 100644 --- a/src/auth/Auth.cpp +++ b/src/auth/Auth.cpp @@ -76,6 +76,14 @@ void CAuth::terminate() { } } +static void passwordUnlockCallback(std::shared_ptr self, void* data) { + g_pHyprlock->unlock(); +} + +void CAuth::enqueueUnlock() { + g_pHyprlock->addTimer(std::chrono::milliseconds(0), passwordUnlockCallback, nullptr); +} + static void passwordFailCallback(std::shared_ptr self, void* data) { g_pAuth->m_bDisplayFailText = true; @@ -84,20 +92,33 @@ static void passwordFailCallback(std::shared_ptr self, void* data) { g_pHyprlock->renderAllOutputs(); } -static void passwordUnlockCallback(std::shared_ptr self, void* data) { - g_pHyprlock->unlock(); +static void displayFailTimeoutCallback(std::shared_ptr self, void* data) { + if (g_pAuth->m_bDisplayFailText) { + g_pAuth->m_bDisplayFailText = false; + g_pHyprlock->renderAllOutputs(); + } } void CAuth::enqueueFail(const std::string& failText, eAuthImplementations implType) { + const auto FAILTIMEOUT = g_pConfigManager->getValue("general:fail_timeout"); + m_sCurrentFail.failText = failText; m_sCurrentFail.failSource = implType; m_sCurrentFail.failedAttempts++; Debug::log(LOG, "Failed attempts: {}", m_sCurrentFail.failedAttempts); + if (m_resetDisplayFailTimer) { + m_resetDisplayFailTimer->cancel(); + m_resetDisplayFailTimer.reset(); + } + g_pHyprlock->addTimer(std::chrono::milliseconds(0), passwordFailCallback, nullptr); + m_resetDisplayFailTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(*FAILTIMEOUT), displayFailTimeoutCallback, nullptr); } -void CAuth::enqueueUnlock() { - g_pHyprlock->addTimer(std::chrono::milliseconds(0), passwordUnlockCallback, nullptr); +void CAuth::resetDisplayFail() { + g_pAuth->m_bDisplayFailText = false; + m_resetDisplayFailTimer->cancel(); + m_resetDisplayFailTimer.reset(); } diff --git a/src/auth/Auth.hpp b/src/auth/Auth.hpp index ef9236f..ed41c78 100644 --- a/src/auth/Auth.hpp +++ b/src/auth/Auth.hpp @@ -4,6 +4,7 @@ #include #include "../defines.hpp" +#include "../core/Timer.hpp" enum eAuthImplementations { AUTH_IMPL_PAM = 0, @@ -47,6 +48,8 @@ class CAuth { void enqueueUnlock(); void enqueueFail(const std::string& failText, eAuthImplementations implType); + void resetDisplayFail(); + // Should only be set via the main thread bool m_bDisplayFailText = false; @@ -58,6 +61,7 @@ class CAuth { } m_sCurrentFail; std::vector> m_vImpls; + std::shared_ptr m_resetDisplayFailTimer; }; inline UP g_pAuth; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 02bd72b..27c5e3f 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -216,6 +216,7 @@ void CConfigManager::init() { m_config.addConfigValue("general:immediate_render", Hyprlang::INT{0}); m_config.addConfigValue("general:fractional_scaling", Hyprlang::INT{2}); m_config.addConfigValue("general:screencopy_mode", Hyprlang::INT{0}); + m_config.addConfigValue("general:fail_timeout", Hyprlang::INT{2000}); m_config.addConfigValue("auth:pam:enabled", Hyprlang::INT{1}); m_config.addConfigValue("auth:pam:module", Hyprlang::STRING{"hyprlock"}); @@ -297,7 +298,6 @@ void CConfigManager::init() { m_config.addSpecialConfigValue("input-field", "check_color", GRADIENTCONFIG("0xFF22CC88")); m_config.addSpecialConfigValue("input-field", "fail_color", GRADIENTCONFIG("0xFFCC2222")); m_config.addSpecialConfigValue("input-field", "fail_text", Hyprlang::STRING{"$FAIL"}); - m_config.addSpecialConfigValue("input-field", "fail_timeout", Hyprlang::INT{2000}); m_config.addSpecialConfigValue("input-field", "capslock_color", GRADIENTCONFIG("")); m_config.addSpecialConfigValue("input-field", "numlock_color", GRADIENTCONFIG("")); m_config.addSpecialConfigValue("input-field", "bothlock_color", GRADIENTCONFIG("")); @@ -473,7 +473,6 @@ std::vector CConfigManager::getWidgetConfigs() { {"check_color", m_config.getSpecialConfigValue("input-field", "check_color", k.c_str())}, {"fail_color", m_config.getSpecialConfigValue("input-field", "fail_color", k.c_str())}, {"fail_text", m_config.getSpecialConfigValue("input-field", "fail_text", k.c_str())}, - {"fail_timeout", m_config.getSpecialConfigValue("input-field", "fail_timeout", k.c_str())}, {"capslock_color", m_config.getSpecialConfigValue("input-field", "capslock_color", k.c_str())}, {"numlock_color", m_config.getSpecialConfigValue("input-field", "numlock_color", k.c_str())}, {"bothlock_color", m_config.getSpecialConfigValue("input-field", "bothlock_color", k.c_str())}, diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 8455f7e..0ce0856 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -602,6 +602,9 @@ void CHyprlock::onKey(uint32_t key, bool down) { return; } + if (g_pAuth->m_bDisplayFailText) + g_pAuth->resetDisplayFail(); + if (down) { m_bCapsLock = xkb_state_mod_name_is_active(g_pSeatManager->m_pXKBState, XKB_MOD_NAME_CAPS, XKB_STATE_MODS_LOCKED); m_bNumLock = xkb_state_mod_name_is_active(g_pSeatManager->m_pXKBState, XKB_MOD_NAME_NUM, XKB_STATE_MODS_LOCKED); diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index a3aa405..f7a9b5b 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -48,7 +48,6 @@ void CPasswordInputField::configure(const std::unordered_map(props.at("rounding")); configPlaceholderText = std::any_cast(props.at("placeholder_text")); configFailText = std::any_cast(props.at("fail_text")); - configFailTimeoutMs = std::any_cast(props.at("fail_timeout")); fontFamily = std::any_cast(props.at("font_family")); colorConfig.outer = CGradientValueData::fromAnyPv(props.at("outer_color")); colorConfig.inner = std::any_cast(props.at("inner_color")); @@ -326,13 +325,6 @@ bool CPasswordInputField::draw(const SRenderData& data) { return redrawShadow || forceReload; } -static void failTimeoutCallback(std::shared_ptr self, void* data) { - if (g_pAuth->m_bDisplayFailText) { - g_pAuth->m_bDisplayFailText = false; - g_pHyprlock->renderAllOutputs(); - } -} - void CPasswordInputField::updatePlaceholder() { if (passwordLength != 0) { if (placeholder.asset && /* keep prompt asset cause it is likely to be used again */ displayFail) { @@ -351,12 +343,7 @@ void CPasswordInputField::updatePlaceholder() { placeholder.failedAttempts = g_pAuth->getFailedAttempts(); - std::string newText; - if (displayFail) { - g_pHyprlock->addTimer(std::chrono::milliseconds(configFailTimeoutMs), failTimeoutCallback, nullptr); - newText = formatString(configFailText).formatted; - } else - newText = formatString(configPlaceholderText).formatted; + std::string newText = (displayFail) ? formatString(configFailText).formatted : formatString(configPlaceholderText).formatted; // if the text is unchanged we don't need to do anything, unless we are swapping font color const auto ALLOWCOLORSWAP = outThick == 0 && colorConfig.swapFont; @@ -388,6 +375,10 @@ void CPasswordInputField::updatePlaceholder() { request.props["font_family"] = fontFamily; request.props["color"] = colorState.font; request.props["font_size"] = (int)size->value().y / 4; + request.callback = [REF = m_self] { + if (const auto SELF = REF.lock(); SELF) + g_pHyprlock->renderOutput(SELF->outputStringPort); + }; g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); } diff --git a/src/renderer/widgets/PasswordInputField.hpp b/src/renderer/widgets/PasswordInputField.hpp index 83d4fea..86ff7e2 100644 --- a/src/renderer/widgets/PasswordInputField.hpp +++ b/src/renderer/widgets/PasswordInputField.hpp @@ -7,7 +7,6 @@ #include "Shadowable.hpp" #include "../../config/ConfigDataValues.hpp" #include "../../helpers/AnimatedVariable.hpp" -#include #include #include #include @@ -83,7 +82,6 @@ class CPasswordInputField : public IWidget { size_t failedAttempts = 0; std::vector registeredResourceIDs; - } placeholder; struct {