VirtualTouchpadEvdev.h revision 4b64dd48b6896d6b963f0a3a0259d3d2a7076a9e
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 Attach() override; 22 status_t Detach() override; 23 status_t Touch(int touchpad, float x, float y, float pressure) override; 24 status_t ButtonState(int touchpad, int buttons) override; 25 void dumpInternal(String8& result) override; 26 27 protected: 28 VirtualTouchpadEvdev() {} 29 ~VirtualTouchpadEvdev() override {} 30 31 // Must be called only between construction and Attach(). 32 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 62