1use std::time::{Duration, Instant};
2
3#[derive(Debug, Copy, Clone, PartialEq, Eq)]
4pub enum ChromeState {
5 Visible,
6 Idle,
7}
8
9pub struct Chrome {
10 idle_after: Duration,
11 last_input: Option<Instant>,
12}
13
14impl Chrome {
15 pub fn new(idle_after: Duration) -> Self {
16 Self {
17 idle_after,
18 last_input: None,
19 }
20 }
21 pub fn touch(&mut self, now: Instant) {
22 self.last_input = Some(now);
23 }
24 pub fn state(&self, now: Instant) -> ChromeState {
25 match self.last_input {
26 Some(t) if now.saturating_duration_since(t) < self.idle_after => ChromeState::Visible,
27 _ => ChromeState::Idle,
28 }
29 }
30}