From 7c2822bfdb4a7b73ea0b03981fd3376c4d9ff74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Rodon?= Date: Sat, 9 May 2026 09:15:11 +0200 Subject: [PATCH] refactor(fingerprint): consolidate activity notification --- src/auth/Fingerprint.cpp | 17 +++++++++++++---- src/auth/Fingerprint.hpp | 2 +- src/core/Seat.cpp | 2 +- src/core/hyprlock.cpp | 27 ++++++++++++--------------- src/core/hyprlock.hpp | 3 ++- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/auth/Fingerprint.cpp b/src/auth/Fingerprint.cpp index 8fc37aa..dae1324 100644 --- a/src/auth/Fingerprint.cpp +++ b/src/auth/Fingerprint.cpp @@ -107,6 +107,15 @@ void CFingerprint::terminate() { releaseDevice(); } +static void inactivityTimerCallback(ASP self, void* data) { + if (!g_pAuth) + return; + auto fpImpl = g_pAuth->getImpl(AUTH_IMPL_FINGERPRINT); + if (!fpImpl) + return; + ((CFingerprint*)fpImpl.get())->onInactivityTimeout(); +} + void CFingerprint::setupInactivityTimer() { if (m_sInactiveTimeout <= 0 || m_sDBUSState.abort || m_sDBUSState.done) return; @@ -116,11 +125,12 @@ void CFingerprint::setupInactivityTimer() { m_pInactivityTimer.reset(); } - m_pInactivityTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(m_sInactiveTimeout * 1000), - [](ASP self, void* data) { ((CFingerprint*)data)->onInactivityTimeout(); }, this); + m_pInactivityTimer = g_pHyprlock->addTimer(std::chrono::seconds(m_sInactiveTimeout), inactivityTimerCallback, nullptr); } void CFingerprint::onActivity() { + setupInactivityTimer(); + if (!m_sDBUSState.verifying) { Debug::log(LOG, "fprint: activity detected, resuming verification"); startVerify(); @@ -132,9 +142,7 @@ void CFingerprint::onInactivityTimeout() { return; Debug::log(LOG, "fprint: inactivity timeout, pausing verification"); - stopVerify(); - releaseDevice(); m_sDBUSState.device.reset(); @@ -143,6 +151,7 @@ void CFingerprint::onInactivityTimeout() { m_sPrompt = ""; g_pHyprlock->enqueueForceUpdateTimers(); + m_pInactivityTimer->cancel(); m_pInactivityTimer.reset(); } diff --git a/src/auth/Fingerprint.hpp b/src/auth/Fingerprint.hpp index b940063..42d2055 100644 --- a/src/auth/Fingerprint.hpp +++ b/src/auth/Fingerprint.hpp @@ -23,6 +23,7 @@ class CFingerprint : public IAuthImplementation { virtual void terminate(); void onActivity(); + void onInactivityTimeout(); std::shared_ptr getConnection(); @@ -56,6 +57,5 @@ class CFingerprint : public IAuthImplementation { bool stopVerify(); bool releaseDevice(); - void onInactivityTimeout(); void setupInactivityTimer(); }; diff --git a/src/core/Seat.cpp b/src/core/Seat.cpp index 4bf10e6..f13e3fd 100644 --- a/src/core/Seat.cpp +++ b/src/core/Seat.cpp @@ -34,7 +34,7 @@ void CSeatManager::registerSeat(SP seat) { m_pPointer->setMotion([](CCWlPointer* r, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { g_pHyprlock->m_vMouseLocation = {wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)}; - g_pHyprlock->onMouseMove(g_pHyprlock->m_vMouseLocation); + g_pHyprlock->notifyActivityToFingerprint(); if (!*HIDECURSOR) g_pHyprlock->onHover(g_pHyprlock->m_vMouseLocation); diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index c782615..c334991 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -644,6 +644,8 @@ void CHyprlock::onKey(uint32_t key, bool down) { xkb_compose_state_reset(g_pSeatManager->m_pXKBComposeState); renderAllOutputs(); + + notifyActivityToFingerprint(); } void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) { @@ -696,12 +698,7 @@ void CHyprlock::onClick(uint32_t button, bool down, const Vector2D& pos) { if (!m_focusedOutput->m_sessionLockSurface) return; - if (g_pAuth) { - auto fpImpl = g_pAuth->getImpl(AUTH_IMPL_FINGERPRINT); - if (fpImpl) { - ((CFingerprint*)fpImpl.get())->onActivity(); - } - } + notifyActivityToFingerprint(); const auto SCALEDPOS = pos * m_focusedOutput->m_sessionLockSurface->fractionalScale; const auto widgets = g_pRenderer->getOrCreateWidgetsFor(*m_focusedOutput->m_sessionLockSurface); @@ -750,15 +747,6 @@ void CHyprlock::onHover(const Vector2D& pos) { m_focusedOutput->m_sessionLockSurface->render(); } -void CHyprlock::onMouseMove(const Vector2D& pos) { - if (g_pAuth) { - auto fpImpl = g_pAuth->getImpl(AUTH_IMPL_FINGERPRINT); - if (fpImpl) { - ((CFingerprint*)fpImpl.get())->onActivity(); - } - } -} - bool CHyprlock::acquireSessionLock() { Log::logger->log(Log::INFO, "Locking session"); m_sLockState.lock = makeShared(m_sWaylandState.sessionLock->sendLock()); @@ -931,6 +919,15 @@ void CHyprlock::enqueueForceUpdateTimers() { nullptr, false); } +void CHyprlock::notifyActivityToFingerprint() { + if (!g_pAuth) + return; + auto fpImpl = g_pAuth->getImpl(AUTH_IMPL_FINGERPRINT); + if (!fpImpl) + return; + ((CFingerprint*)fpImpl.get())->onActivity(); +} + SP CHyprlock::getScreencopy() { return m_sWaylandState.screencopy; } diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 3964f19..77ab1bb 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -49,7 +49,6 @@ class CHyprlock { void onKey(uint32_t key, bool down); void onClick(uint32_t button, bool down, const Vector2D& pos); void onHover(const Vector2D& pos); - void onMouseMove(const Vector2D& pos); void startKeyRepeat(xkb_keysym_t sym); void repeatKey(xkb_keysym_t sym); void handleKeySym(xkb_keysym_t sym, bool compose); @@ -58,6 +57,8 @@ class CHyprlock { bool passwordCheckWaiting(); std::optional passwordLastFailReason(); + void notifyActivityToFingerprint(); + void renderOutput(const std::string& stringPort); void renderAllOutputs();