Convert touchpad gestures into pointer moves & clicks
While the gestures library may return some events asynchronously (which
will require some changes to InputReader to handle), most are returned
during the call to PushHardwareState, allowing us to handle them easily.
Here we handle mouse movement, clicks, and drags.
I was going to send the BUTTON_PRESS events before the DOWN events, as
we'd discussed changing as part of the click event consistency work, but
doing so results in an input event injection failure from the
dispatcher, so for now I've kept the order the same as for mice.
Bug: 251196347
Test: connect Apple Magic Trackpad 2, move, click, and drag
Test: atest inputflinger_tests
Change-Id: I3a60ea6bd166bdb9b628f5a17d9e1b6e7341ba42
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
index 9d3a4b3..fe6b1fe 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
@@ -18,6 +18,8 @@
#include <memory>
+#include <PointerControllerInterface.h>
+
#include "EventHub.h"
#include "InputDevice.h"
#include "InputMapper.h"
@@ -33,21 +35,44 @@
class TouchpadInputMapper : public InputMapper {
public:
explicit TouchpadInputMapper(InputDeviceContext& deviceContext);
+ ~TouchpadInputMapper();
uint32_t getSources() const override;
[[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
[[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override;
+ void consumeGesture(const Gesture* gesture);
+
private:
- void sync(nsecs_t when);
+ [[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when, nsecs_t readTime);
+ [[nodiscard]] std::list<NotifyArgs> processGestures(nsecs_t when, nsecs_t readTime);
+ NotifyArgs handleMove(nsecs_t when, nsecs_t readTime, const Gesture& gesture);
+ [[nodiscard]] std::list<NotifyArgs> handleButtonsChange(nsecs_t when, nsecs_t readTime,
+ const Gesture& gesture);
+
+ NotifyMotionArgs makeMotionArgs(nsecs_t when, nsecs_t readTime, int32_t action,
+ int32_t actionButton, int32_t buttonState,
+ uint32_t pointerCount,
+ const PointerProperties* pointerProperties,
+ const PointerCoords* pointerCoords, float xCursorPosition,
+ float yCursorPosition);
std::unique_ptr<gestures::GestureInterpreter, void (*)(gestures::GestureInterpreter*)>
mGestureInterpreter;
+ std::shared_ptr<PointerControllerInterface> mPointerController;
CursorButtonAccumulator mCursorButtonAccumulator;
MultiTouchMotionAccumulator mMotionAccumulator;
TouchButtonAccumulator mTouchButtonAccumulator;
int32_t mMscTimestamp = 0;
+
+ bool mProcessing = false;
+ std::vector<Gesture> mGesturesToProcess;
+
+ // The current button state according to the gestures library, but converted into MotionEvent
+ // button values (AMOTION_EVENT_BUTTON_...).
+ uint32_t mButtonState = 0;
+ nsecs_t mDownTime = 0;
};
} // namespace android