From 230f8aadb5123dd7388143aa4f2a5a881a9c0a41 Mon Sep 17 00:00:00 2001 From: YoussefAswad <85849220+YoussefAswad@users.noreply.github.com> Date: Sat, 23 Mar 2024 17:02:03 +0200 Subject: [PATCH] config: add option to ignore empty input (#218) --- src/config/ConfigManager.cpp | 5 +++-- src/core/hyprlock.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 2c00e13..5fddf1c 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -30,7 +30,8 @@ static std::string getMainConfigPath() { return getConfigDir() + "/hypr/hyprlock.conf"; } -CConfigManager::CConfigManager(std::string configPath) : m_config(configPath.empty() ? getMainConfigPath().c_str() : configPath.c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = configPath.empty()}) { +CConfigManager::CConfigManager(std::string configPath) : + m_config(configPath.empty() ? getMainConfigPath().c_str() : configPath.c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = configPath.empty()}) { configCurrentPath = configPath.empty() ? getMainConfigPath() : configPath; } @@ -47,7 +48,7 @@ void CConfigManager::init() { m_config.addConfigValue("general:grace", Hyprlang::INT{0}); m_config.addConfigValue("general:no_fade_in", Hyprlang::INT{0}); m_config.addConfigValue("general:no_fade_out", Hyprlang::INT{0}); - + m_config.addConfigValue("general:ignore_empty_input", Hyprlang::INT{0}); 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 4203350..9513daf 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -814,6 +814,14 @@ void CHyprlock::onKey(uint32_t key, bool down) { } } else if (SYM == XKB_KEY_Return || SYM == XKB_KEY_KP_Enter) { Debug::log(LOG, "Authenticating"); + + static auto* const PIGNOREEMPTY = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:ignore_empty_input"); + + if (m_sPasswordState.passBuffer.empty() && **PIGNOREEMPTY) { + Debug::log(LOG, "Ignoring empty input"); + return; + } + m_sPasswordState.result = g_pPassword->verify(m_sPasswordState.passBuffer); } else if (SYM == XKB_KEY_Escape) { Debug::log(LOG, "Clearing password buffer");