blob: ec8006b67cf00b54b7e43a497793e3ebe56a438d [file] [log] [blame]
Kevin Schoedel89af70b2017-03-03 18:11:37 -05001#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:
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050021 status_t Touch(int touchpad, float x, float y, float pressure) override;
22 status_t ButtonState(int touchpad, int buttons) override;
Kevin Schoedel89af70b2017-03-03 18:11:37 -050023
24 protected:
25 VirtualTouchpadEvdev() {}
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050026 ~VirtualTouchpadEvdev() override {}
Kevin Schoedel89af70b2017-03-03 18:11:37 -050027 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