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