Skip to content

Commit 52e3480

Browse files
core: add passwordEmptyTimerCallback
1 parent 83d49ed commit 52e3480

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/config/ConfigManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void CConfigManager::init() {
3939
m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0});
4040
m_config.addConfigValue("general:grace", Hyprlang::INT{0});
4141
m_config.addConfigValue("general:no_fade_in", Hyprlang::INT{0});
42+
m_config.addConfigValue("general:input_empty_fade_timeout", Hyprlang::INT{1000});
4243

4344
m_config.addSpecialCategory("background", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
4445
m_config.addSpecialConfigValue("background", "monitor", Hyprlang::STRING{""});

src/core/hyprlock.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ CHyprlock::CHyprlock(const std::string& wlDisplay) {
2828
if (!m_pXKBContext)
2929
Debug::log(ERR, "Failed to create xkb context");
3030

31-
const auto GRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace");
32-
m_tGraceEnds = **GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**GRACE) : std::chrono::system_clock::from_time_t(0);
31+
const auto GRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace");
32+
m_tGraceEnds = **GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**GRACE) : std::chrono::system_clock::from_time_t(0);
33+
const auto FADETIMEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:input_empty_fade_timeout");
34+
m_iEmptyPasswordTimeoutMs = **FADETIMEOUT;
3335
}
3436

3537
// wl_seat
@@ -643,6 +645,14 @@ static const ext_session_lock_v1_listener sessionLockListener = {
643645

644646
// end session_lock
645647

648+
static void passwordEmptyTimerCallback(std::shared_ptr<CTimer> self, void* data) {
649+
g_pRenderer->onEmptyPasswordFade();
650+
651+
for (auto& o : g_pHyprlock->m_vOutputs) {
652+
o->sessionLockSurface->render();
653+
}
654+
}
655+
646656
void CHyprlock::onPasswordCheckTimer() {
647657
// check result
648658
if (m_sPasswordState.result->success) {
@@ -658,6 +668,12 @@ void CHyprlock::onPasswordCheckTimer() {
658668
}
659669

660670
m_sPasswordState.result.reset();
671+
672+
if (m_sPasswordState.emptyBufferTimer.get()) {
673+
m_sPasswordState.emptyBufferTimer->cancel();
674+
m_sPasswordState.emptyBufferTimer.reset();
675+
}
676+
m_sPasswordState.emptyBufferTimer = addTimer(std::chrono::milliseconds(m_iEmptyPasswordTimeoutMs), passwordEmptyTimerCallback, nullptr);
661677
}
662678

663679
bool CHyprlock::passwordCheckWaiting() {
@@ -717,6 +733,13 @@ void CHyprlock::onKey(uint32_t key, bool down) {
717733
m_sPasswordState.passBuffer += std::string{buf, len - 1};
718734
}
719735

736+
if (m_sPasswordState.passBuffer.empty() && !m_sPasswordState.emptyBufferTimer.get())
737+
m_sPasswordState.emptyBufferTimer = addTimer(std::chrono::milliseconds(m_iEmptyPasswordTimeoutMs), passwordEmptyTimerCallback, nullptr);
738+
else if (!m_sPasswordState.passBuffer.empty() && m_sPasswordState.emptyBufferTimer.get()) {
739+
m_sPasswordState.emptyBufferTimer->cancel();
740+
m_sPasswordState.emptyBufferTimer.reset();
741+
}
742+
720743
for (auto& o : m_vOutputs) {
721744
o->sessionLockSurface->render();
722745
}
@@ -870,4 +893,4 @@ std::string CHyprlock::spawnSync(const std::string& cmd) {
870893

871894
zwlr_screencopy_manager_v1* CHyprlock::getScreencopy() {
872895
return m_sWaylandState.screencopy;
873-
}
896+
}

src/core/hyprlock.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class CHyprlock {
7676

7777
//
7878
std::chrono::system_clock::time_point m_tGraceEnds;
79-
Vector2D m_vLastEnterCoords = {};
79+
Vector2D m_vLastEnterCoords = {};
80+
uint64_t m_iEmptyPasswordTimeoutMs = 0;
8081

8182
std::vector<std::unique_ptr<COutput>> m_vOutputs;
8283

@@ -115,6 +116,7 @@ class CHyprlock {
115116
std::string passBuffer = "";
116117
std::shared_ptr<CPassword::SVerificationResult> result;
117118
std::optional<std::string> lastFailReason;
119+
std::shared_ptr<CTimer> emptyBufferTimer;
118120
} m_sPasswordState;
119121

120122
struct {

0 commit comments

Comments
 (0)