blob: b158cece19b83e62e8cdf4888499b6cad4266cbf [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 Schoedel4b64dd42017-03-07 13:06:25 -050021 status_t Attach() override;
22 status_t Detach() override;
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050023 status_t Touch(int touchpad, float x, float y, float pressure) override;
24 status_t ButtonState(int touchpad, int buttons) override;
Kevin Schoedel4b64dd42017-03-07 13:06:25 -050025 void dumpInternal(String8& result) override;
Kevin Schoedel89af70b2017-03-03 18:11:37 -050026
27 protected:
28 VirtualTouchpadEvdev() {}
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050029 ~VirtualTouchpadEvdev() override {}
Kevin Schoedel89af70b2017-03-03 18:11:37 -050030
Kevin Schoedel4b64dd42017-03-07 13:06:25 -050031 // Must be called only between construction and Attach().
Kevin Schoedel89af70b2017-03-03 18:11:37 -050032 inline void SetEvdevInjectorForTesting(EvdevInjector* injector) {
33 injector_ = injector;
34 }
35
36 private:
37 // Except for testing, the |EvdevInjector| used to inject evdev events.
38 std::unique_ptr<EvdevInjector> owned_injector_;
39
40 // Active pointer to |owned_injector_| or to a testing injector.
41 EvdevInjector* injector_ = nullptr;
42
43 // Previous (x, y) position in device space, to suppress redundant events.
44 int32_t last_device_x_ = INT32_MIN;
45 int32_t last_device_y_ = INT32_MIN;
46
47 // Records current touch state (0=up 1=down) in bit 0, and previous state
48 // in bit 1, to track transitions.
49 int touches_ = 0;
50
51 // Previous injected button state, to detect changes.
52 int32_t last_motion_event_buttons_ = 0;
53
54 VirtualTouchpadEvdev(const VirtualTouchpadEvdev&) = delete;
55 void operator=(const VirtualTouchpadEvdev&) = delete;
56};
57
58} // namespace dvr
59} // namespace android
60
61#endif // ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H