Skip to content

Commit

Permalink
core: add passwordEmptyTimerCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
PaideiaDilemma committed Mar 6, 2024
1 parent 428e85e commit 2b430c5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{""});
Expand Down
29 changes: 26 additions & 3 deletions src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -654,6 +656,14 @@ static const ext_session_lock_v1_listener sessionLockListener = {

// end session_lock

static void passwordEmptyTimerCallback(std::shared_ptr<CTimer> 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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -920,4 +943,4 @@ void CHyprlock::attemptRestoreOnDeath() {

spawnSync("hyprctl keyword misc:allow_session_lock_restore true");
spawnAsync("sleep 2 && hyprlock & disown");
}
}
4 changes: 3 additions & 1 deletion src/core/hyprlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::unique_ptr<COutput>> m_vOutputs;

Expand Down Expand Up @@ -117,6 +118,7 @@ class CHyprlock {
std::string passBuffer = "";
std::shared_ptr<CPassword::SVerificationResult> result;
std::optional<std::string> lastFailReason;
std::shared_ptr<CTimer> emptyBufferTimer;
} m_sPasswordState;

struct {
Expand Down

0 comments on commit 2b430c5

Please sign in to comment.