Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/auth/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,27 @@ void CAuth::terminate() {
}
}

static void passwordSuccCallback(ASP<CTimer> self, void* data) {
g_pAuth->m_bDisplaySuccText = true;

g_pHyprlock->enqueueForceUpdateTimers();

g_pHyprlock->renderAllOutputs();
}

static void unlockCallback(ASP<CTimer> self, void* data) {
g_pHyprlock->fadeOutAndUnlock();
}

void CAuth::enqueueUnlock() {
g_pHyprlock->addTimer(std::chrono::milliseconds(0), unlockCallback, nullptr);
static const auto SUCCTIMEOUT = g_pConfigManager->getValue<Hyprlang::INT>("general:succ_timeout");

if (*SUCCTIMEOUT > 0) {
g_pHyprlock->addTimer(std::chrono::milliseconds(0), passwordSuccCallback, nullptr);
g_pHyprlock->addTimer(std::chrono::milliseconds(*SUCCTIMEOUT), unlockCallback, nullptr);
} else {
g_pHyprlock->addTimer(std::chrono::milliseconds(0), unlockCallback, nullptr);
}
}

static void passwordFailCallback(ASP<CTimer> self, void* data) {
Expand Down
1 change: 1 addition & 0 deletions src/auth/Auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CAuth {
void resetDisplayFail();

// Should only be set via the main thread
bool m_bDisplaySuccText = false;
bool m_bDisplayFailText = false;

private:
Expand Down
1 change: 1 addition & 0 deletions src/auth/Pam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void CPam::init() {
if (!AUTHENTICATED)
g_pAuth->enqueueFail(m_sConversationState.failText, AUTH_IMPL_PAM);
else {
m_bBlockInput = false;
g_pAuth->enqueueUnlock();
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,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:succ_timeout", Hyprlang::INT{0});
m_config.addConfigValue("general:fail_timeout", Hyprlang::INT{2000});

m_config.addConfigValue("auth:pam:enabled", Hyprlang::INT{1});
Expand Down Expand Up @@ -329,7 +330,9 @@ void CConfigManager::init() {
m_config.addSpecialConfigValue("input-field", "hide_input_base_color", Hyprlang::INT{0xEE00FF99});
m_config.addSpecialConfigValue("input-field", "rounding", Hyprlang::INT{-1});
m_config.addSpecialConfigValue("input-field", "check_color", GRADIENTCONFIG("0xFF22CC88"));
m_config.addSpecialConfigValue("input-field", "succ_color", GRADIENTCONFIG("0xFF22CC88"));
m_config.addSpecialConfigValue("input-field", "fail_color", GRADIENTCONFIG("0xFFCC2222"));
m_config.addSpecialConfigValue("input-field", "succ_text", Hyprlang::STRING{""});
m_config.addSpecialConfigValue("input-field", "fail_text", Hyprlang::STRING{"<i>$FAIL</i>"});
m_config.addSpecialConfigValue("input-field", "check_text", Hyprlang::STRING{""});
m_config.addSpecialConfigValue("input-field", "capslock_color", GRADIENTCONFIG(""));
Expand Down Expand Up @@ -511,7 +514,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
{"hide_input_base_color", m_config.getSpecialConfigValue("input-field", "hide_input_base_color", k.c_str())},
{"rounding", m_config.getSpecialConfigValue("input-field", "rounding", k.c_str())},
{"check_color", m_config.getSpecialConfigValue("input-field", "check_color", k.c_str())},
{"succ_color", m_config.getSpecialConfigValue("input-field", "succ_color", k.c_str())},
{"fail_color", m_config.getSpecialConfigValue("input-field", "fail_color", k.c_str())},
{"succ_text", m_config.getSpecialConfigValue("input-field", "succ_text", k.c_str())},
{"fail_text", m_config.getSpecialConfigValue("input-field", "fail_text", k.c_str())},
{"check_text", m_config.getSpecialConfigValue("input-field", "check_text", k.c_str())},
{"capslock_color", m_config.getSpecialConfigValue("input-field", "capslock_color", k.c_str())},
Expand Down
3 changes: 3 additions & 0 deletions src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ void CHyprlock::onKey(uint32_t key, bool down) {
return;
}

if (g_pAuth->m_bDisplaySuccText)
return;

if (g_pAuth->m_bDisplayFailText)
g_pAuth->resetDisplayFail();

Expand Down
13 changes: 11 additions & 2 deletions src/renderer/widgets/PasswordInputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ void CPasswordInputField::configure(const std::unordered_map<std::string, std::a
hiddenInputState.enabled = std::any_cast<Hyprlang::INT>(props.at("hide_input"));
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
configPlaceholderText = std::any_cast<Hyprlang::STRING>(props.at("placeholder_text"));
configSuccText = std::any_cast<Hyprlang::STRING>(props.at("succ_text"));
configFailText = std::any_cast<Hyprlang::STRING>(props.at("fail_text"));
configCheckText = std::any_cast<Hyprlang::STRING>(props.at("check_text"));
fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
colorConfig.outer = CGradientValueData::fromAnyPv(props.at("outer_color"));
colorConfig.inner = std::any_cast<Hyprlang::INT>(props.at("inner_color"));
colorConfig.font = std::any_cast<Hyprlang::INT>(props.at("font_color"));
colorConfig.succ = CGradientValueData::fromAnyPv(props.at("succ_color"));
colorConfig.fail = CGradientValueData::fromAnyPv(props.at("fail_color"));
colorConfig.check = CGradientValueData::fromAnyPv(props.at("check_color"));
colorConfig.both = CGradientValueData::fromAnyPv(props.at("bothlock_color"));
Expand Down Expand Up @@ -184,6 +186,7 @@ bool CPasswordInputField::draw(const SRenderData& data) {

passwordLength = g_pHyprlock->getPasswordBufferDisplayLen();
checkWaiting = g_pAuth->checkWaiting();
displaySucc = g_pAuth->m_bDisplaySuccText;
displayFail = g_pAuth->m_bDisplayFailText;

updateFade();
Expand Down Expand Up @@ -348,7 +351,9 @@ void CPasswordInputField::updatePlaceholder() {
if (displayFail) {
newText = formatString(configFailText).formatted;
placeholder.failedAttempts = g_pAuth->getFailedAttempts();
} else if (checkWaiting && !configCheckText.empty())
} else if (displaySucc && !configSuccText.empty())
newText = formatString(configSuccText).formatted;
else if (checkWaiting && !configCheckText.empty())
newText = formatString(configCheckText).formatted;
else
newText = formatString(configPlaceholderText).formatted;
Expand Down Expand Up @@ -440,14 +445,18 @@ void CPasswordInputField::updateColors() {

if (checkWaiting)
targetGrad = colorConfig.check;
else if (displaySucc)
targetGrad = colorConfig.succ;
else if (displayFail && passwordLength == 0)
targetGrad = colorConfig.fail;

CGradientValueData* outerTarget = colorConfig.outer;
CHyprColor innerTarget = colorConfig.inner;
CHyprColor fontTarget = colorConfig.font;

if (displayFail)
if (displaySucc)
fontTarget = colorConfig.succ->m_vColors.front();
else if (displayFail)
fontTarget = colorConfig.fail->m_vColors.front();
else if (checkWaiting)
fontTarget = configCheckText.empty() ? colorConfig.font : colorConfig.check->m_vColors.front();
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/widgets/PasswordInputField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CPasswordInputField : public IWidget {
bool firstRender = true;
bool redrawShadow = false;
bool checkWaiting = false;
bool displaySucc = false;
bool displayFail = false;

size_t passwordLength = 0;
Expand All @@ -56,7 +57,7 @@ class CPasswordInputField : public IWidget {
Vector2D configPos;
Vector2D configSize;

std::string halign, valign, configFailText, configCheckText, outputStringPort, configPlaceholderText, fontFamily;
std::string halign, valign, configSuccText, configFailText, configCheckText, outputStringPort, configPlaceholderText, fontFamily;
uint64_t configFailTimeoutMs = 2000;

int outThick, rounding;
Expand Down Expand Up @@ -98,6 +99,7 @@ class CPasswordInputField : public IWidget {
CGradientValueData* outer = nullptr;
CHyprColor inner;
CHyprColor font;
CGradientValueData* succ = nullptr;
CGradientValueData* fail = nullptr;
CGradientValueData* check = nullptr;
CGradientValueData* caps = nullptr;
Expand Down