Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 27 | namespace android { |
| 28 | |
| 29 | class VelocityControl; |
| 30 | class PointerControllerInterface; |
| 31 | |
| 32 | class CursorButtonAccumulator; |
| 33 | class CursorScrollAccumulator; |
| 34 | |
| 35 | /* Keeps track of cursor movements. */ |
| 36 | class CursorMotionAccumulator { |
| 37 | public: |
| 38 | CursorMotionAccumulator(); |
| 39 | void reset(InputDevice* device); |
| 40 | |
| 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 | |
| 47 | private: |
| 48 | int32_t mRelX; |
| 49 | int32_t mRelY; |
| 50 | |
| 51 | void clearRelativeAxes(); |
| 52 | }; |
| 53 | |
| 54 | class CursorInputMapper : public InputMapper { |
| 55 | public: |
| 56 | explicit CursorInputMapper(InputDevice* device); |
| 57 | virtual ~CursorInputMapper(); |
| 58 | |
Prabir Pradhan | f1fbf9e | 2019-09-04 16:29:40 -0700 | [diff] [blame^] | 59 | 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 Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 66 | |
Prabir Pradhan | f1fbf9e | 2019-09-04 16:29:40 -0700 | [diff] [blame^] | 67 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 68 | |
Prabir Pradhan | f1fbf9e | 2019-09-04 16:29:40 -0700 | [diff] [blame^] | 69 | virtual void fadePointer() override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 70 | |
Prabir Pradhan | f1fbf9e | 2019-09-04 16:29:40 -0700 | [diff] [blame^] | 71 | virtual std::optional<int32_t> getAssociatedDisplayId() override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | // Amount that trackball needs to move in order to generate a key event. |
| 75 | static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6; |
| 76 | |
| 77 | // Immutable configuration parameters. |
| 78 | struct Parameters { |
| 79 | enum Mode { |
| 80 | MODE_POINTER, |
| 81 | MODE_POINTER_RELATIVE, |
| 82 | MODE_NAVIGATION, |
| 83 | }; |
| 84 | |
| 85 | Mode mode; |
| 86 | bool hasAssociatedDisplay; |
| 87 | bool orientationAware; |
| 88 | } mParameters; |
| 89 | |
| 90 | CursorButtonAccumulator mCursorButtonAccumulator; |
| 91 | CursorMotionAccumulator mCursorMotionAccumulator; |
| 92 | CursorScrollAccumulator mCursorScrollAccumulator; |
| 93 | |
| 94 | int32_t mSource; |
| 95 | float mXScale; |
| 96 | float mYScale; |
| 97 | float mXPrecision; |
| 98 | float mYPrecision; |
| 99 | |
| 100 | float mVWheelScale; |
| 101 | float mHWheelScale; |
| 102 | |
| 103 | // Velocity controls for mouse pointer and wheel movements. |
| 104 | // The controls for X and Y wheel movements are separate to keep them decoupled. |
| 105 | VelocityControl mPointerVelocityControl; |
| 106 | VelocityControl mWheelXVelocityControl; |
| 107 | VelocityControl mWheelYVelocityControl; |
| 108 | |
| 109 | int32_t mOrientation; |
| 110 | |
| 111 | sp<PointerControllerInterface> mPointerController; |
| 112 | |
| 113 | int32_t mButtonState; |
| 114 | nsecs_t mDownTime; |
| 115 | |
| 116 | void configureParameters(); |
| 117 | void dumpParameters(std::string& dump); |
| 118 | |
| 119 | void sync(nsecs_t when); |
| 120 | }; |
| 121 | |
| 122 | } // namespace android |
| 123 | |
| 124 | #endif // _UI_INPUTREADER_CURSOR_INPUT_MAPPER_H |