VirtualTouchpadEvdev.h revision 89af70bce420f011adfeb0f80984b3895c4d7d9b
1#ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H
2#define ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H
3
4#include <memory>
5
6#include "VirtualTouchpad.h"
7#include "EvdevInjector.h"
8
9namespace android {
10namespace dvr {
11
12class EvdevInjector;
13
14// VirtualTouchpadEvdev implements a VirtualTouchpad by injecting evdev events.
15//
16class VirtualTouchpadEvdev : public VirtualTouchpad {
17 public:
18  static sp<VirtualTouchpad> Create();
19
20  // VirtualTouchpad implementation:
21  status_t Touch(float x, float y, float pressure) override;
22  status_t ButtonState(int buttons) override;
23
24 protected:
25  VirtualTouchpadEvdev() {}
26  ~VirtualTouchpadEvdev() {}
27  status_t Initialize();
28
29  // Must be called only between construction and Initialize().
30  inline void SetEvdevInjectorForTesting(EvdevInjector* injector) {
31    injector_ = injector;
32  }
33
34 private:
35  // Except for testing, the |EvdevInjector| used to inject evdev events.
36  std::unique_ptr<EvdevInjector> owned_injector_;
37
38  // Active pointer to |owned_injector_| or to a testing injector.
39  EvdevInjector* injector_ = nullptr;
40
41  // Previous (x, y) position in device space, to suppress redundant events.
42  int32_t last_device_x_ = INT32_MIN;
43  int32_t last_device_y_ = INT32_MIN;
44
45  // Records current touch state (0=up 1=down) in bit 0, and previous state
46  // in bit 1, to track transitions.
47  int touches_ = 0;
48
49  // Previous injected button state, to detect changes.
50  int32_t last_motion_event_buttons_ = 0;
51
52  VirtualTouchpadEvdev(const VirtualTouchpadEvdev&) = delete;
53  void operator=(const VirtualTouchpadEvdev&) = delete;
54};
55
56}  // namespace dvr
57}  // namespace android
58
59#endif  // ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H
60