summaryrefslogtreecommitdiff
path: root/src/tangara/input/input_trigger.hpp
blob: 5bf8e13c45a89f1e3ef75af348380ce5256e2662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright 2024 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#pragma once

#include <cstdint>
#include <optional>

namespace input {

const uint16_t kDoubleClickDelayMs = 500;
const uint16_t kLongPressDelayMs = 400;
const uint16_t kRepeatDelayMs = 100;

class Trigger {
 public:
  enum class State {
    kNone,
    kClick,
    kDoubleClick,
    kLongPress,
    kRepeatPress,
    kPress
  };

  Trigger();

  auto update(bool is_pressed) -> State;
  auto cancel() -> void;

 private:
  std::optional<uint64_t> touch_time_ms_;
  bool was_pressed_;

  bool was_double_click_;
  uint16_t times_long_pressed_;
};

}  // namespace input