Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 18 | |
Christine Franks | 46d8a1e | 2022-01-05 16:11:48 -0800 | [diff] [blame] | 19 | #include <android/os/IInputConstants.h> |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 20 | #include <input/DisplayViewport.h> |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 21 | #include <input/Input.h> |
| 22 | #include <input/InputDevice.h> |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 23 | #include <input/VelocityControl.h> |
| 24 | #include <input/VelocityTracker.h> |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 25 | #include <stddef.h> |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 26 | #include <ui/Rotation.h> |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 27 | #include <unistd.h> |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 28 | #include <utils/Errors.h> |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 29 | #include <utils/RefBase.h> |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 30 | |
Siarhei Vishniakou | c6f6119 | 2019-07-23 18:12:31 +0000 | [diff] [blame] | 31 | #include <optional> |
| 32 | #include <set> |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 33 | #include <unordered_map> |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 34 | #include <vector> |
| 35 | |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 36 | #include "PointerControllerInterface.h" |
| 37 | #include "VibrationElement.h" |
| 38 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 39 | // Maximum supported size of a vibration pattern. |
| 40 | // Must be at least 2. |
| 41 | #define MAX_VIBRATE_PATTERN_SIZE 100 |
| 42 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 43 | namespace android { |
| 44 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 45 | // --- InputReaderConfiguration --- |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Input reader configuration. |
| 49 | * |
| 50 | * Specifies various options that modify the behavior of the input reader. |
| 51 | */ |
| 52 | struct InputReaderConfiguration { |
| 53 | // Describes changes that have occurred. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 54 | enum class Change : uint32_t { |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 55 | // The mouse pointer speed changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 56 | POINTER_SPEED = 1u << 0, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 57 | |
| 58 | // The pointer gesture control changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 59 | POINTER_GESTURE_ENABLEMENT = 1u << 1, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 60 | |
| 61 | // The display size or orientation changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 62 | DISPLAY_INFO = 1u << 2, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 63 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 64 | // The keyboard layouts must be reloaded. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 65 | KEYBOARD_LAYOUTS = 1u << 4, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 66 | |
| 67 | // The device name alias supplied by the may have changed for some devices. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 68 | DEVICE_ALIAS = 1u << 5, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 69 | |
| 70 | // The location calibration matrix changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 71 | TOUCH_AFFINE_TRANSFORMATION = 1u << 6, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 72 | |
| 73 | // The presence of an external stylus has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 74 | EXTERNAL_STYLUS_PRESENCE = 1u << 7, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 75 | |
| 76 | // The pointer capture mode has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 77 | POINTER_CAPTURE = 1u << 8, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 78 | |
| 79 | // The set of disabled input devices (disabledDevices) has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 80 | ENABLED_STATE = 1u << 9, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 81 | |
Ambrus Weisz | 7bc23bf | 2022-10-04 13:13:07 +0000 | [diff] [blame] | 82 | // The device type has been updated. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 83 | DEVICE_TYPE = 1u << 10, |
Ambrus Weisz | 7bc23bf | 2022-10-04 13:13:07 +0000 | [diff] [blame] | 84 | |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 85 | // The keyboard layout association has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 86 | KEYBOARD_LAYOUT_ASSOCIATION = 1u << 11, |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 87 | |
Prabir Pradhan | 7aa7ff0 | 2022-12-21 21:05:38 +0000 | [diff] [blame] | 88 | // The stylus button reporting configurations has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 89 | STYLUS_BUTTON_REPORTING = 1u << 12, |
Prabir Pradhan | 7aa7ff0 | 2022-12-21 21:05:38 +0000 | [diff] [blame] | 90 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 91 | // The touchpad settings changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 92 | TOUCHPAD_SETTINGS = 1u << 13, |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 93 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 94 | // All devices must be reopened. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 95 | MUST_REOPEN = 1u << 31, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | // Gets the amount of time to disable virtual keys after the screen is touched |
| 99 | // in order to filter out accidental virtual key presses due to swiping gestures |
| 100 | // or taps near the edge of the display. May be 0 to disable the feature. |
| 101 | nsecs_t virtualKeyQuietTime; |
| 102 | |
| 103 | // The excluded device names for the platform. |
| 104 | // Devices with these names will be ignored. |
| 105 | std::vector<std::string> excludedDeviceNames; |
| 106 | |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 107 | // The associations between input ports and display ports. |
| 108 | // Used to determine which DisplayViewport should be tied to which InputDevice. |
| 109 | std::unordered_map<std::string, uint8_t> portAssociations; |
| 110 | |
Antonio Kantek | 0ac5e09 | 2024-04-22 17:10:27 +0000 | [diff] [blame] | 111 | // The associations between input device ports and display unique ids. |
Christine Franks | 1ba71cc | 2021-04-07 14:37:42 -0700 | [diff] [blame] | 112 | // Used to determine which DisplayViewport should be tied to which InputDevice. |
Antonio Kantek | 0ac5e09 | 2024-04-22 17:10:27 +0000 | [diff] [blame] | 113 | std::unordered_map<std::string, std::string> uniqueIdAssociationsByPort; |
| 114 | |
| 115 | // The associations between input device descriptor and display unique ids. |
| 116 | // Used to determine which DisplayViewport should be tied to which InputDevice. |
| 117 | std::unordered_map<std::string, std::string> uniqueIdAssociationsByDescriptor; |
Christine Franks | 1ba71cc | 2021-04-07 14:37:42 -0700 | [diff] [blame] | 118 | |
Ambrus Weisz | 7bc23bf | 2022-10-04 13:13:07 +0000 | [diff] [blame] | 119 | // The associations between input device ports device types. |
| 120 | // This is used to determine which device type and source should be tied to which InputDevice. |
| 121 | std::unordered_map<std::string, std::string> deviceTypeAssociations; |
| 122 | |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 123 | // The map from the input device physical port location to the input device layout info. |
| 124 | // Can be used to determine the layout of the keyboard device. |
| 125 | std::unordered_map<std::string, KeyboardLayoutInfo> keyboardLayoutAssociations; |
| 126 | |
Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 127 | // The suggested display ID to show the cursor. |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 128 | ui::LogicalDisplayId defaultPointerDisplayId; |
Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 129 | |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 130 | // The mouse pointer speed, as a number from -7 (slowest) to 7 (fastest). |
| 131 | // |
| 132 | // Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled. |
| 133 | int32_t mousePointerSpeed; |
| 134 | |
Prabir Pradhan | 777245c | 2024-01-19 20:44:36 +0000 | [diff] [blame] | 135 | // Displays on which an acceleration curve shouldn't be applied for pointer movements from mice. |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 136 | // |
| 137 | // Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled. |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 138 | std::set<ui::LogicalDisplayId> displaysWithMousePointerAccelerationDisabled; |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 139 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 140 | // Velocity control parameters for mouse pointer movements. |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 141 | // |
| 142 | // If the enable_new_mouse_pointer_ballistics flag is enabled, these are ignored and the values |
| 143 | // of mousePointerSpeed and mousePointerAccelerationEnabled used instead. |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 144 | VelocityControlParameters pointerVelocityControlParameters; |
| 145 | |
| 146 | // Velocity control parameters for mouse wheel movements. |
| 147 | VelocityControlParameters wheelVelocityControlParameters; |
| 148 | |
| 149 | // True if pointer gestures are enabled. |
| 150 | bool pointerGesturesEnabled; |
| 151 | |
| 152 | // Quiet time between certain pointer gesture transitions. |
| 153 | // Time to allow for all fingers or buttons to settle into a stable state before |
| 154 | // starting a new gesture. |
| 155 | nsecs_t pointerGestureQuietInterval; |
| 156 | |
| 157 | // The minimum speed that a pointer must travel for us to consider switching the active |
| 158 | // touch pointer to it during a drag. This threshold is set to avoid switching due |
| 159 | // to noise from a finger resting on the touch pad (perhaps just pressing it down). |
| 160 | float pointerGestureDragMinSwitchSpeed; // in pixels per second |
| 161 | |
| 162 | // Tap gesture delay time. |
| 163 | // The time between down and up must be less than this to be considered a tap. |
| 164 | nsecs_t pointerGestureTapInterval; |
| 165 | |
| 166 | // Tap drag gesture delay time. |
| 167 | // The time between the previous tap's up and the next down must be less than |
| 168 | // this to be considered a drag. Otherwise, the previous tap is finished and a |
| 169 | // new tap begins. |
| 170 | // |
| 171 | // Note that the previous tap will be held down for this entire duration so this |
| 172 | // interval must be shorter than the long press timeout. |
| 173 | nsecs_t pointerGestureTapDragInterval; |
| 174 | |
| 175 | // The distance in pixels that the pointer is allowed to move from initial down |
| 176 | // to up and still be called a tap. |
| 177 | float pointerGestureTapSlop; // in pixels |
| 178 | |
| 179 | // Time after the first touch points go down to settle on an initial centroid. |
| 180 | // This is intended to be enough time to handle cases where the user puts down two |
| 181 | // fingers at almost but not quite exactly the same time. |
| 182 | nsecs_t pointerGestureMultitouchSettleInterval; |
| 183 | |
| 184 | // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when |
| 185 | // at least two pointers have moved at least this far from their starting place. |
| 186 | float pointerGestureMultitouchMinDistance; // in pixels |
| 187 | |
| 188 | // The transition from PRESS to SWIPE gesture mode can only occur when the |
| 189 | // cosine of the angle between the two vectors is greater than or equal to than this value |
| 190 | // which indicates that the vectors are oriented in the same direction. |
| 191 | // When the vectors are oriented in the exactly same direction, the cosine is 1.0. |
| 192 | // (In exactly opposite directions, the cosine is -1.0.) |
| 193 | float pointerGestureSwipeTransitionAngleCosine; |
| 194 | |
| 195 | // The transition from PRESS to SWIPE gesture mode can only occur when the |
| 196 | // fingers are no more than this far apart relative to the diagonal size of |
| 197 | // the touch pad. For example, a ratio of 0.5 means that the fingers must be |
| 198 | // no more than half the diagonal size of the touch pad apart. |
| 199 | float pointerGestureSwipeMaxWidthRatio; |
| 200 | |
| 201 | // The gesture movement speed factor relative to the size of the display. |
| 202 | // Movement speed applies when the fingers are moving in the same direction. |
| 203 | // Without acceleration, a full swipe of the touch pad diagonal in movement mode |
| 204 | // will cover this portion of the display diagonal. |
| 205 | float pointerGestureMovementSpeedRatio; |
| 206 | |
| 207 | // The gesture zoom speed factor relative to the size of the display. |
| 208 | // Zoom speed applies when the fingers are mostly moving relative to each other |
| 209 | // to execute a scale gesture or similar. |
| 210 | // Without acceleration, a full swipe of the touch pad diagonal in zoom mode |
| 211 | // will cover this portion of the display diagonal. |
| 212 | float pointerGestureZoomSpeedRatio; |
| 213 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 214 | // The latest request to enable or disable Pointer Capture. |
| 215 | PointerCaptureRequest pointerCaptureRequest; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 216 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 217 | // The touchpad pointer speed, as a number from -7 (slowest) to 7 (fastest). |
| 218 | int32_t touchpadPointerSpeed; |
| 219 | |
| 220 | // True to invert the touchpad scrolling direction, so that moving two fingers downwards on the |
| 221 | // touchpad scrolls the content upwards. |
| 222 | bool touchpadNaturalScrollingEnabled; |
| 223 | |
| 224 | // True to enable tap-to-click on touchpads. |
| 225 | bool touchpadTapToClickEnabled; |
| 226 | |
Harry Cutts | e0e799d | 2024-01-24 16:27:56 +0000 | [diff] [blame] | 227 | // True to enable tap dragging on touchpads. |
| 228 | bool touchpadTapDraggingEnabled; |
| 229 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 230 | // True to enable a zone on the right-hand side of touchpads where clicks will be turned into |
| 231 | // context (a.k.a. "right") clicks. |
| 232 | bool touchpadRightClickZoneEnabled; |
| 233 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 234 | // The set of currently disabled input devices. |
Siarhei Vishniakou | c6f6119 | 2019-07-23 18:12:31 +0000 | [diff] [blame] | 235 | std::set<int32_t> disabledDevices; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 236 | |
Prabir Pradhan | 7aa7ff0 | 2022-12-21 21:05:38 +0000 | [diff] [blame] | 237 | // True if stylus button reporting through motion events should be enabled, in which case |
| 238 | // stylus button state changes are reported through motion events. |
| 239 | bool stylusButtonMotionEventsEnabled; |
| 240 | |
Seunghwan Choi | 2de48e4 | 2023-01-17 20:45:15 +0900 | [diff] [blame] | 241 | // True if a pointer icon should be shown for direct stylus pointers. |
| 242 | bool stylusPointerIconEnabled; |
| 243 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 244 | InputReaderConfiguration() |
| 245 | : virtualKeyQuietTime(0), |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 246 | defaultPointerDisplayId(ui::ADISPLAY_ID_DEFAULT), |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 247 | mousePointerSpeed(0), |
Prabir Pradhan | 777245c | 2024-01-19 20:44:36 +0000 | [diff] [blame] | 248 | displaysWithMousePointerAccelerationDisabled(), |
Christine Franks | 46d8a1e | 2022-01-05 16:11:48 -0800 | [diff] [blame] | 249 | pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, |
| 250 | static_cast<float>( |
| 251 | android::os::IInputConstants:: |
| 252 | DEFAULT_POINTER_ACCELERATION)), |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 253 | wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f), |
| 254 | pointerGesturesEnabled(true), |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 255 | pointerGestureQuietInterval(100 * 1000000LL), // 100 ms |
| 256 | pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second |
| 257 | pointerGestureTapInterval(150 * 1000000LL), // 150 ms |
| 258 | pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms |
| 259 | pointerGestureTapSlop(10.0f), // 10 pixels |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 260 | pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 261 | pointerGestureMultitouchMinDistance(15), // 15 pixels |
| 262 | pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 263 | pointerGestureSwipeMaxWidthRatio(0.25f), |
| 264 | pointerGestureMovementSpeedRatio(0.8f), |
| 265 | pointerGestureZoomSpeedRatio(0.3f), |
Prabir Pradhan | 7aa7ff0 | 2022-12-21 21:05:38 +0000 | [diff] [blame] | 266 | pointerCaptureRequest(), |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 267 | touchpadPointerSpeed(0), |
| 268 | touchpadNaturalScrollingEnabled(true), |
| 269 | touchpadTapToClickEnabled(true), |
Harry Cutts | e0e799d | 2024-01-24 16:27:56 +0000 | [diff] [blame] | 270 | touchpadTapDraggingEnabled(false), |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 271 | touchpadRightClickZoneEnabled(false), |
Seunghwan Choi | 2de48e4 | 2023-01-17 20:45:15 +0900 | [diff] [blame] | 272 | stylusButtonMotionEventsEnabled(true), |
| 273 | stylusPointerIconEnabled(false) {} |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 274 | |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 275 | std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const; |
| 276 | std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId) |
| 277 | const; |
| 278 | std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const; |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 279 | std::optional<DisplayViewport> getDisplayViewportById(ui::LogicalDisplayId displayId) const; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 280 | void setDisplayViewports(const std::vector<DisplayViewport>& viewports); |
| 281 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 282 | void dump(std::string& dump) const; |
| 283 | void dumpViewport(std::string& dump, const DisplayViewport& viewport) const; |
| 284 | |
| 285 | private: |
| 286 | std::vector<DisplayViewport> mDisplays; |
| 287 | }; |
| 288 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 289 | using ConfigurationChanges = ftl::Flags<InputReaderConfiguration::Change>; |
| 290 | |
| 291 | // --- InputReaderInterface --- |
| 292 | |
| 293 | /* The interface for the InputReader shared library. |
| 294 | * |
| 295 | * Manages one or more threads that process raw input events and sends cooked event data to an |
| 296 | * input listener. |
| 297 | * |
| 298 | * The implementation must guarantee thread safety for this interface. However, since the input |
| 299 | * listener is NOT thread safe, all calls to the listener must happen from the same thread. |
| 300 | */ |
| 301 | class InputReaderInterface { |
| 302 | public: |
| 303 | InputReaderInterface() {} |
| 304 | virtual ~InputReaderInterface() {} |
| 305 | /* Dumps the state of the input reader. |
| 306 | * |
| 307 | * This method may be called on any thread (usually by the input manager). */ |
| 308 | virtual void dump(std::string& dump) = 0; |
| 309 | |
| 310 | /* Called by the heartbeat to ensures that the reader has not deadlocked. */ |
| 311 | virtual void monitor() = 0; |
| 312 | |
| 313 | /* Returns true if the input device is enabled. */ |
| 314 | virtual bool isInputDeviceEnabled(int32_t deviceId) = 0; |
| 315 | |
| 316 | /* Makes the reader start processing events from the kernel. */ |
| 317 | virtual status_t start() = 0; |
| 318 | |
| 319 | /* Makes the reader stop processing any more events. */ |
| 320 | virtual status_t stop() = 0; |
| 321 | |
| 322 | /* Gets information about all input devices. |
| 323 | * |
| 324 | * This method may be called on any thread (usually by the input manager). |
| 325 | */ |
| 326 | virtual std::vector<InputDeviceInfo> getInputDevices() const = 0; |
| 327 | |
| 328 | /* Query current input state. */ |
| 329 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) = 0; |
| 330 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) = 0; |
| 331 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) = 0; |
| 332 | |
| 333 | virtual void addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, |
| 334 | int32_t toKeyCode) const = 0; |
| 335 | |
| 336 | virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; |
| 337 | |
| 338 | /* Toggle Caps Lock */ |
| 339 | virtual void toggleCapsLockState(int32_t deviceId) = 0; |
| 340 | |
| 341 | /* Determine whether physical keys exist for the given framework-domain key codes. */ |
| 342 | virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 343 | const std::vector<int32_t>& keyCodes, uint8_t* outFlags) = 0; |
| 344 | |
| 345 | /* Requests that a reconfiguration of all input devices. |
| 346 | * The changes flag is a bitfield that indicates what has changed and whether |
| 347 | * the input devices must all be reopened. */ |
| 348 | virtual void requestRefreshConfiguration(ConfigurationChanges changes) = 0; |
| 349 | |
| 350 | /* Controls the vibrator of a particular input device. */ |
| 351 | virtual void vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat, |
| 352 | int32_t token) = 0; |
| 353 | virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0; |
| 354 | |
| 355 | virtual bool isVibrating(int32_t deviceId) = 0; |
| 356 | |
| 357 | virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0; |
| 358 | /* Get battery level of a particular input device. */ |
| 359 | virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) = 0; |
| 360 | /* Get battery status of a particular input device. */ |
| 361 | virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0; |
| 362 | /* Get the device path for the battery of an input device. */ |
| 363 | virtual std::optional<std::string> getBatteryDevicePath(int32_t deviceId) = 0; |
| 364 | |
| 365 | virtual std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) = 0; |
| 366 | |
| 367 | virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0; |
| 368 | |
| 369 | /* Return true if the device can send input events to the specified display. */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 370 | virtual bool canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) = 0; |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 371 | |
| 372 | /* Enable sensor in input reader mapper. */ |
| 373 | virtual bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType, |
| 374 | std::chrono::microseconds samplingPeriod, |
| 375 | std::chrono::microseconds maxBatchReportLatency) = 0; |
| 376 | |
| 377 | /* Disable sensor in input reader mapper. */ |
| 378 | virtual void disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0; |
| 379 | |
| 380 | /* Flush sensor data in input reader mapper. */ |
| 381 | virtual void flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0; |
| 382 | |
| 383 | /* Set color for the light */ |
| 384 | virtual bool setLightColor(int32_t deviceId, int32_t lightId, int32_t color) = 0; |
| 385 | /* Set player ID for the light */ |
| 386 | virtual bool setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) = 0; |
| 387 | /* Get light color */ |
| 388 | virtual std::optional<int32_t> getLightColor(int32_t deviceId, int32_t lightId) = 0; |
| 389 | /* Get light player ID */ |
| 390 | virtual std::optional<int32_t> getLightPlayerId(int32_t deviceId, int32_t lightId) = 0; |
| 391 | |
| 392 | /* Get the Bluetooth address of an input device, if known. */ |
| 393 | virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0; |
| 394 | |
| 395 | /* Sysfs node change reported. Recreate device if required to incorporate the new sysfs nodes */ |
| 396 | virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0; |
| 397 | }; |
| 398 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 399 | // --- TouchAffineTransformation --- |
| 400 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 401 | struct TouchAffineTransformation { |
| 402 | float x_scale; |
| 403 | float x_ymix; |
| 404 | float x_offset; |
| 405 | float y_xmix; |
| 406 | float y_scale; |
| 407 | float y_offset; |
| 408 | |
| 409 | TouchAffineTransformation() : |
| 410 | x_scale(1.0f), x_ymix(0.0f), x_offset(0.0f), |
| 411 | y_xmix(0.0f), y_scale(1.0f), y_offset(0.0f) { |
| 412 | } |
| 413 | |
| 414 | TouchAffineTransformation(float xscale, float xymix, float xoffset, |
| 415 | float yxmix, float yscale, float yoffset) : |
| 416 | x_scale(xscale), x_ymix(xymix), x_offset(xoffset), |
| 417 | y_xmix(yxmix), y_scale(yscale), y_offset(yoffset) { |
| 418 | } |
| 419 | |
| 420 | void applyTo(float& x, float& y) const; |
| 421 | }; |
| 422 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 423 | // --- InputReaderPolicyInterface --- |
| 424 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 425 | /* |
| 426 | * Input reader policy interface. |
| 427 | * |
| 428 | * The input reader policy is used by the input reader to interact with the Window Manager |
| 429 | * and other system components. |
| 430 | * |
| 431 | * The actual implementation is partially supported by callbacks into the DVM |
| 432 | * via JNI. This interface is also mocked in the unit tests. |
| 433 | * |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 434 | * These methods will NOT re-enter the input reader interface, so they may be called from |
| 435 | * any method in the input reader interface. |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 436 | */ |
| 437 | class InputReaderPolicyInterface : public virtual RefBase { |
| 438 | protected: |
| 439 | InputReaderPolicyInterface() { } |
| 440 | virtual ~InputReaderPolicyInterface() { } |
| 441 | |
| 442 | public: |
| 443 | /* Gets the input reader configuration. */ |
| 444 | virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0; |
| 445 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 446 | /* Notifies the input reader policy that some input devices have changed |
| 447 | * and provides information about all current input devices. |
| 448 | */ |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 449 | virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) = 0; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 450 | |
| 451 | /* Gets the keyboard layout for a particular input device. */ |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 452 | virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay( |
Vaibhav Devmurari | dec3080 | 2023-07-11 15:02:03 +0000 | [diff] [blame] | 453 | const InputDeviceIdentifier& identifier, |
| 454 | const std::optional<KeyboardLayoutInfo> keyboardLayoutInfo) = 0; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 455 | |
| 456 | /* Gets a user-supplied alias for a particular input device, or an empty string if none. */ |
| 457 | virtual std::string getDeviceAlias(const InputDeviceIdentifier& identifier) = 0; |
| 458 | |
| 459 | /* Gets the affine calibration associated with the specified device. */ |
| 460 | virtual TouchAffineTransformation getTouchAffineTransformation( |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 461 | const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation) = 0; |
Prabir Pradhan | da20b17 | 2022-09-26 17:01:18 +0000 | [diff] [blame] | 462 | /* Notifies the input reader policy that a stylus gesture has started. */ |
| 463 | virtual void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) = 0; |
Arpit Singh | b3b3f73 | 2023-07-04 14:30:05 +0000 | [diff] [blame] | 464 | |
| 465 | /* Returns true if any InputConnection is currently active. */ |
| 466 | virtual bool isInputMethodConnectionActive() = 0; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 467 | |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 468 | /* Gets the viewport of a particular display that the pointer device is associated with. If |
| 469 | * the pointer device is not associated with any display, it should ADISPLAY_IS_NONE to get |
| 470 | * the viewport that should be used. The device should get a new viewport using this method |
| 471 | * every time there is a display configuration change. The logical bounds of the viewport should |
| 472 | * be used as the range of possible values for pointing devices, like mice and touchpads. |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 473 | */ |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 474 | virtual std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 475 | ui::LogicalDisplayId associatedDisplayId = ui::ADISPLAY_ID_NONE) = 0; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 476 | }; |
| 477 | |
| 478 | } // namespace android |