blob: f65ac3934a74fd3248e449517b1f1b20f492abe3 [file] [log] [blame]
Prabir Pradhanbaa5c822019-08-30 15:27:05 -07001/*
2 * Copyright (C) 2019 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#ifndef _UI_INPUTREADER_CURSOR_INPUT_MAPPER_H
18#define _UI_INPUTREADER_CURSOR_INPUT_MAPPER_H
19
20#include "CursorButtonAccumulator.h"
21#include "CursorScrollAccumulator.h"
22#include "InputMapper.h"
23
24#include <PointerControllerInterface.h>
25#include <input/VelocityControl.h>
26
27namespace android {
28
29class VelocityControl;
30class PointerControllerInterface;
31
32class CursorButtonAccumulator;
33class CursorScrollAccumulator;
34
35/* Keeps track of cursor movements. */
36class CursorMotionAccumulator {
37public:
38 CursorMotionAccumulator();
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080039 void reset(InputDeviceContext& deviceContext);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070040
41 void process(const RawEvent* rawEvent);
42 void finishSync();
43
44 inline int32_t getRelativeX() const { return mRelX; }
45 inline int32_t getRelativeY() const { return mRelY; }
46
47private:
48 int32_t mRelX;
49 int32_t mRelY;
50
51 void clearRelativeAxes();
52};
53
54class CursorInputMapper : public InputMapper {
55public:
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080056 explicit CursorInputMapper(InputDeviceContext& deviceContext);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070057 virtual ~CursorInputMapper();
58
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -070059 virtual uint32_t getSources() override;
60 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo) override;
61 virtual void dump(std::string& dump) override;
62 virtual void configure(nsecs_t when, const InputReaderConfiguration* config,
63 uint32_t changes) override;
64 virtual void reset(nsecs_t when) override;
65 virtual void process(const RawEvent* rawEvent) override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070066
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -070067 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070068
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -070069 virtual std::optional<int32_t> getAssociatedDisplayId() override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070070
71private:
72 // Amount that trackball needs to move in order to generate a key event.
73 static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
74
75 // Immutable configuration parameters.
76 struct Parameters {
77 enum Mode {
78 MODE_POINTER,
79 MODE_POINTER_RELATIVE,
80 MODE_NAVIGATION,
81 };
82
83 Mode mode;
84 bool hasAssociatedDisplay;
85 bool orientationAware;
86 } mParameters;
87
88 CursorButtonAccumulator mCursorButtonAccumulator;
89 CursorMotionAccumulator mCursorMotionAccumulator;
90 CursorScrollAccumulator mCursorScrollAccumulator;
91
92 int32_t mSource;
93 float mXScale;
94 float mYScale;
95 float mXPrecision;
96 float mYPrecision;
97
98 float mVWheelScale;
99 float mHWheelScale;
100
101 // Velocity controls for mouse pointer and wheel movements.
102 // The controls for X and Y wheel movements are separate to keep them decoupled.
103 VelocityControl mPointerVelocityControl;
104 VelocityControl mWheelXVelocityControl;
105 VelocityControl mWheelYVelocityControl;
106
107 int32_t mOrientation;
108
109 sp<PointerControllerInterface> mPointerController;
110
111 int32_t mButtonState;
112 nsecs_t mDownTime;
113
114 void configureParameters();
115 void dumpParameters(std::string& dump);
116
117 void sync(nsecs_t when);
118};
119
120} // namespace android
121
Garfield Tan888a6a42020-01-09 11:39:16 -0800122#endif // _UI_INPUTREADER_CURSOR_INPUT_MAPPER_H