1 #ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H 2 #define ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H 3 4 #include "EvdevInjector.h" 5 #include "VirtualTouchpad.h" 6 7 namespace android { 8 namespace dvr { 9 10 class EvdevInjector; 11 12 // VirtualTouchpadEvdev implements a VirtualTouchpad by injecting evdev events. 13 // 14 class VirtualTouchpadEvdev : public VirtualTouchpad { 15 public: 16 static std::unique_ptr<VirtualTouchpad> Create(); ~VirtualTouchpadEvdev()17 ~VirtualTouchpadEvdev() override {} 18 19 // VirtualTouchpad implementation: 20 status_t Attach() override; 21 status_t Detach() override; 22 status_t Touch(int touchpad, float x, float y, float pressure) override; 23 status_t ButtonState(int touchpad, int buttons) override; 24 status_t Scroll(int touchpad, float x, float y) override; 25 void dumpInternal(String8& result) override; 26 27 protected: 28 static constexpr int kTouchpads = 2; 29 VirtualTouchpadEvdev()30 VirtualTouchpadEvdev() {} 31 void Reset(); 32 33 // Must be called only between construction (or Detach()) and Attach(). SetEvdevInjectorForTesting(int touchpad,EvdevInjector * injector)34 inline void SetEvdevInjectorForTesting(int touchpad, 35 EvdevInjector* injector) { 36 touchpad_[touchpad].injector = injector; 37 } 38 39 private: 40 // Per-touchpad state. 41 struct Touchpad { 42 // Except for testing, the |EvdevInjector| used to inject evdev events. 43 std::unique_ptr<EvdevInjector> owned_injector; 44 45 // Active pointer to |owned_injector_| or to a testing injector. 46 EvdevInjector* injector = nullptr; 47 48 // Previous (x, y) position in device space, to suppress redundant events. 49 int32_t last_device_x; 50 int32_t last_device_y; 51 52 // Records current touch state (0=up 1=down) in bit 0, and previous state 53 // in bit 1, to track transitions. 54 int touches; 55 56 // Previous injected button state, to detect changes. 57 int32_t last_motion_event_buttons; 58 }; 59 Touchpad touchpad_[kTouchpads]; 60 61 VirtualTouchpadEvdev(const VirtualTouchpadEvdev&) = delete; 62 void operator=(const VirtualTouchpadEvdev&) = delete; 63 }; 64 65 } // namespace dvr 66 } // namespace android 67 68 #endif // ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H 69