diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 672d63d..2aaf297 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -165,7 +165,11 @@ void CHyprlock::run() { m_sLoopState.timersMutex.unlock(); std::unique_lock lk(m_sLoopState.timerRequestMutex); - m_sLoopState.timerCV.wait_for(lk, std::chrono::milliseconds((int)least + 1), [this] { return m_sLoopState.event; }); + m_sLoopState.timerCV.wait_for(lk, std::chrono::milliseconds((int)least + 1), [this] { return m_sLoopState.timerEvent; }); + m_sLoopState.timerEvent = false; + + if (m_bTerminate) + break; // notify main std::lock_guard lg2(m_sLoopState.eventLoopMutex); @@ -230,6 +234,9 @@ void CHyprlock::run() { } while (ret > 0); } + std::lock_guard lg2(m_sLoopState.timerRequestMutex); + m_sLoopState.timerCV.notify_all(); + Debug::log(LOG, "Reached the end, exiting"); } @@ -493,5 +500,8 @@ size_t CHyprlock::getPasswordBufferLen() { std::shared_ptr CHyprlock::addTimer(const std::chrono::system_clock::duration& timeout, std::function self, void* data)> cb_, void* data) { std::lock_guard lg(m_sLoopState.timersMutex); - return m_vTimers.emplace_back(std::make_shared(timeout, cb_, data)); + const auto T = m_vTimers.emplace_back(std::make_shared(timeout, cb_, data)); + m_sLoopState.timerEvent = true; + m_sLoopState.timerCV.notify_all(); + return T; } diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 82684bd..3295260 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -81,6 +81,7 @@ class CHyprlock { std::condition_variable timerCV; std::mutex timerRequestMutex; + bool timerEvent = false; } m_sLoopState; std::vector> m_vOutputs;