blob: fe6b1fe759641370523cee8da3192d9a424cbf5f [file] [log] [blame]
Harry Cutts79cc9fa2022-10-28 15:32:39 +00001/*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
Harry Cutts1f48a442022-11-15 17:38:36 +000019#include <memory>
20
Harry Cutts74235542022-11-24 15:52:53 +000021#include <PointerControllerInterface.h>
22
Harry Cutts79cc9fa2022-10-28 15:32:39 +000023#include "EventHub.h"
24#include "InputDevice.h"
25#include "InputMapper.h"
26#include "NotifyArgs.h"
Harry Cutts1f48a442022-11-15 17:38:36 +000027#include "accumulator/CursorButtonAccumulator.h"
28#include "accumulator/MultiTouchMotionAccumulator.h"
29#include "accumulator/TouchButtonAccumulator.h"
30
31#include "include/gestures.h"
Harry Cutts79cc9fa2022-10-28 15:32:39 +000032
33namespace android {
34
35class TouchpadInputMapper : public InputMapper {
36public:
37 explicit TouchpadInputMapper(InputDeviceContext& deviceContext);
Harry Cutts74235542022-11-24 15:52:53 +000038 ~TouchpadInputMapper();
Harry Cutts79cc9fa2022-10-28 15:32:39 +000039
Harry Cutts1f48a442022-11-15 17:38:36 +000040 uint32_t getSources() const override;
41 [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
42 [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override;
43
Harry Cutts74235542022-11-24 15:52:53 +000044 void consumeGesture(const Gesture* gesture);
45
Harry Cutts1f48a442022-11-15 17:38:36 +000046private:
Harry Cutts74235542022-11-24 15:52:53 +000047 [[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when, nsecs_t readTime);
48 [[nodiscard]] std::list<NotifyArgs> processGestures(nsecs_t when, nsecs_t readTime);
49 NotifyArgs handleMove(nsecs_t when, nsecs_t readTime, const Gesture& gesture);
50 [[nodiscard]] std::list<NotifyArgs> handleButtonsChange(nsecs_t when, nsecs_t readTime,
51 const Gesture& gesture);
52
53 NotifyMotionArgs makeMotionArgs(nsecs_t when, nsecs_t readTime, int32_t action,
54 int32_t actionButton, int32_t buttonState,
55 uint32_t pointerCount,
56 const PointerProperties* pointerProperties,
57 const PointerCoords* pointerCoords, float xCursorPosition,
58 float yCursorPosition);
Harry Cutts1f48a442022-11-15 17:38:36 +000059
60 std::unique_ptr<gestures::GestureInterpreter, void (*)(gestures::GestureInterpreter*)>
61 mGestureInterpreter;
Harry Cutts74235542022-11-24 15:52:53 +000062 std::shared_ptr<PointerControllerInterface> mPointerController;
Harry Cutts1f48a442022-11-15 17:38:36 +000063
64 CursorButtonAccumulator mCursorButtonAccumulator;
65 MultiTouchMotionAccumulator mMotionAccumulator;
66 TouchButtonAccumulator mTouchButtonAccumulator;
67 int32_t mMscTimestamp = 0;
Harry Cutts74235542022-11-24 15:52:53 +000068
69 bool mProcessing = false;
70 std::vector<Gesture> mGesturesToProcess;
71
72 // The current button state according to the gestures library, but converted into MotionEvent
73 // button values (AMOTION_EVENT_BUTTON_...).
74 uint32_t mButtonState = 0;
75 nsecs_t mDownTime = 0;
Harry Cutts79cc9fa2022-10-28 15:32:39 +000076};
77
78} // namespace android