Public Access
An Off screen turns on dimmed for the Toast's duration so the user can see what beeped. It isn't user activity: the timeouts aren't restarted, and a key pressed meanwhile reaches the App. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include "power_policy.h"
|
|
|
|
namespace roro {
|
|
|
|
bool PowerPolicy::activity(uint32_t nowMs) {
|
|
bool swallow = state_ == ScreenState::Off;
|
|
lastActivityMs_ = nowMs;
|
|
state_ = ScreenState::On;
|
|
return swallow;
|
|
}
|
|
|
|
ScreenState PowerPolicy::update(uint32_t nowMs) {
|
|
uint32_t idle = nowMs - lastActivityMs_;
|
|
state_ = idle >= offMs_ ? ScreenState::Off : idle >= dimMs_ ? ScreenState::Dimmed : ScreenState::On;
|
|
if (notifying_) {
|
|
if (static_cast<int32_t>(nowMs - notifyUntilMs_) >= 0)
|
|
notifying_ = false;
|
|
else if (state_ == ScreenState::Off)
|
|
state_ = ScreenState::Dimmed;
|
|
}
|
|
return state_;
|
|
}
|
|
|
|
ButtonAction PowerButton::update(bool pressed, uint32_t nowMs) {
|
|
if (pressed && !pressed_) {
|
|
pressed_ = true;
|
|
longFired_ = false;
|
|
pressedAtMs_ = nowMs;
|
|
return ButtonAction::None;
|
|
}
|
|
if (pressed && !longFired_ && nowMs - pressedAtMs_ >= longMs_) {
|
|
longFired_ = true;
|
|
return ButtonAction::LongPress;
|
|
}
|
|
if (!pressed && pressed_) {
|
|
pressed_ = false;
|
|
return longFired_ ? ButtonAction::None : ButtonAction::ShortPress;
|
|
}
|
|
return ButtonAction::None;
|
|
}
|
|
|
|
} // namespace roro
|