mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-17 07:15:57 +01:00
25 lines
No EOL
654 B
C++
25 lines
No EOL
654 B
C++
#include "Timer.hpp"
|
|
|
|
CTimer::CTimer(std::chrono::system_clock::duration timeout, std::function<void(std::shared_ptr<CTimer> self, void* data)> cb_, void* data_) : cb(cb_), data(data_) {
|
|
expires = std::chrono::system_clock::now() + timeout;
|
|
}
|
|
|
|
bool CTimer::passed() {
|
|
return std::chrono::system_clock::now() > expires;
|
|
}
|
|
|
|
void CTimer::cancel() {
|
|
wasCancelled = true;
|
|
}
|
|
|
|
bool CTimer::cancelled() {
|
|
return wasCancelled;
|
|
}
|
|
|
|
void CTimer::call(std::shared_ptr<CTimer> self) {
|
|
cb(self, data);
|
|
}
|
|
|
|
float CTimer::leftMs() {
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(expires - std::chrono::system_clock::now()).count();
|
|
} |