Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 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 | #define LOG_TAG "PointerChoreographer" |
| 18 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 19 | #include <android-base/logging.h> |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 20 | #include <com_android_input_flags.h> |
| 21 | #if defined(__ANDROID__) |
| 22 | #include <gui/SurfaceComposerClient.h> |
| 23 | #endif |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 24 | #include <input/Keyboard.h> |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 25 | #include <input/PrintTools.h> |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 26 | #include <unordered_set> |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 27 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 28 | #include "PointerChoreographer.h" |
| 29 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 30 | #define INDENT " " |
| 31 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 32 | namespace android { |
| 33 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 34 | namespace { |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 35 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 36 | bool isFromMouse(const NotifyMotionArgs& args) { |
| 37 | return isFromSource(args.source, AINPUT_SOURCE_MOUSE) && |
| 38 | args.pointerProperties[0].toolType == ToolType::MOUSE; |
| 39 | } |
| 40 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 41 | bool isFromTouchpad(const NotifyMotionArgs& args) { |
| 42 | return isFromSource(args.source, AINPUT_SOURCE_MOUSE) && |
| 43 | args.pointerProperties[0].toolType == ToolType::FINGER; |
| 44 | } |
| 45 | |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 46 | bool isFromDrawingTablet(const NotifyMotionArgs& args) { |
| 47 | return isFromSource(args.source, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS) && |
| 48 | isStylusToolType(args.pointerProperties[0].toolType); |
| 49 | } |
| 50 | |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 51 | bool isHoverAction(int32_t action) { |
| 52 | return action == AMOTION_EVENT_ACTION_HOVER_ENTER || |
| 53 | action == AMOTION_EVENT_ACTION_HOVER_MOVE || action == AMOTION_EVENT_ACTION_HOVER_EXIT; |
| 54 | } |
| 55 | |
| 56 | bool isStylusHoverEvent(const NotifyMotionArgs& args) { |
| 57 | return isStylusEvent(args.source, args.pointerProperties) && isHoverAction(args.action); |
| 58 | } |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 59 | |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 60 | bool isMouseOrTouchpad(uint32_t sources) { |
| 61 | // Check if this is a mouse or touchpad, but not a drawing tablet. |
| 62 | return isFromSource(sources, AINPUT_SOURCE_MOUSE_RELATIVE) || |
| 63 | (isFromSource(sources, AINPUT_SOURCE_MOUSE) && |
| 64 | !isFromSource(sources, AINPUT_SOURCE_STYLUS)); |
| 65 | } |
| 66 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 67 | inline void notifyPointerDisplayChange( |
| 68 | std::optional<std::tuple<ui::LogicalDisplayId, FloatPoint>> change, |
| 69 | PointerChoreographerPolicyInterface& policy) { |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 70 | if (!change) { |
| 71 | return; |
| 72 | } |
| 73 | const auto& [displayId, cursorPosition] = *change; |
| 74 | policy.notifyPointerDisplayIdChanged(displayId, cursorPosition); |
| 75 | } |
| 76 | |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 77 | void setIconForController(const std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle>& icon, |
| 78 | PointerControllerInterface& controller) { |
| 79 | if (std::holds_alternative<std::unique_ptr<SpriteIcon>>(icon)) { |
| 80 | if (std::get<std::unique_ptr<SpriteIcon>>(icon) == nullptr) { |
| 81 | LOG(FATAL) << "SpriteIcon should not be null"; |
| 82 | } |
| 83 | controller.setCustomPointerIcon(*std::get<std::unique_ptr<SpriteIcon>>(icon)); |
| 84 | } else { |
| 85 | controller.updatePointerIcon(std::get<PointerIconStyle>(icon)); |
| 86 | } |
| 87 | } |
| 88 | |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 89 | // filters and returns a set of privacy sensitive displays that are currently visible. |
| 90 | std::unordered_set<ui::LogicalDisplayId> getPrivacySensitiveDisplaysFromWindowInfos( |
| 91 | const std::vector<gui::WindowInfo>& windowInfos) { |
| 92 | std::unordered_set<ui::LogicalDisplayId> privacySensitiveDisplays; |
| 93 | for (const auto& windowInfo : windowInfos) { |
| 94 | if (!windowInfo.inputConfig.test(gui::WindowInfo::InputConfig::NOT_VISIBLE) && |
| 95 | windowInfo.inputConfig.test(gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)) { |
| 96 | privacySensitiveDisplays.insert(windowInfo.displayId); |
| 97 | } |
| 98 | } |
| 99 | return privacySensitiveDisplays; |
| 100 | } |
| 101 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 102 | } // namespace |
| 103 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 104 | // --- PointerChoreographer --- |
| 105 | |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 106 | PointerChoreographer::PointerChoreographer(InputListenerInterface& inputListener, |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 107 | PointerChoreographerPolicyInterface& policy) |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 108 | : PointerChoreographer( |
| 109 | inputListener, policy, |
| 110 | [](const sp<android::gui::WindowInfosListener>& listener) { |
| 111 | auto initialInfo = std::make_pair(std::vector<android::gui::WindowInfo>{}, |
| 112 | std::vector<android::gui::DisplayInfo>{}); |
| 113 | #if defined(__ANDROID__) |
| 114 | SurfaceComposerClient::getDefault()->addWindowInfosListener(listener, |
| 115 | &initialInfo); |
| 116 | #endif |
| 117 | return initialInfo.first; |
| 118 | }, |
| 119 | [](const sp<android::gui::WindowInfosListener>& listener) { |
| 120 | #if defined(__ANDROID__) |
| 121 | SurfaceComposerClient::getDefault()->removeWindowInfosListener(listener); |
| 122 | #endif |
| 123 | }) { |
| 124 | } |
| 125 | |
| 126 | PointerChoreographer::PointerChoreographer( |
| 127 | android::InputListenerInterface& listener, |
| 128 | android::PointerChoreographerPolicyInterface& policy, |
| 129 | const android::PointerChoreographer::WindowListenerRegisterConsumer& registerListener, |
| 130 | const android::PointerChoreographer::WindowListenerUnregisterConsumer& unregisterListener) |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 131 | : mTouchControllerConstructor([this]() { |
Prabir Pradhan | 1678879 | 2023-11-08 21:07:21 +0000 | [diff] [blame] | 132 | return mPolicy.createPointerController( |
| 133 | PointerControllerInterface::ControllerType::TOUCH); |
| 134 | }), |
| 135 | mNextListener(listener), |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 136 | mPolicy(policy), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 137 | mDefaultMouseDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 138 | mNotifiedPointerDisplayId(ui::LogicalDisplayId::INVALID), |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 139 | mShowTouchesEnabled(false), |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 140 | mStylusPointerIconEnabled(false), |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 141 | mCurrentFocusedDisplay(ui::LogicalDisplayId::DEFAULT), |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 142 | mRegisterListener(registerListener), |
| 143 | mUnregisterListener(unregisterListener) {} |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 144 | |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 145 | PointerChoreographer::~PointerChoreographer() { |
| 146 | std::scoped_lock _l(mLock); |
| 147 | if (mWindowInfoListener == nullptr) { |
| 148 | return; |
| 149 | } |
| 150 | mWindowInfoListener->onPointerChoreographerDestroyed(); |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 151 | mUnregisterListener(mWindowInfoListener); |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 154 | void PointerChoreographer::notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) { |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 155 | PointerDisplayChange pointerDisplayChange; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 156 | |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 157 | { // acquire lock |
| 158 | std::scoped_lock _l(mLock); |
| 159 | |
| 160 | mInputDeviceInfos = args.inputDeviceInfos; |
| 161 | pointerDisplayChange = updatePointerControllersLocked(); |
| 162 | } // release lock |
| 163 | |
| 164 | notifyPointerDisplayChange(pointerDisplayChange, mPolicy); |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 165 | mNextListener.notify(args); |
| 166 | } |
| 167 | |
| 168 | void PointerChoreographer::notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) { |
| 169 | mNextListener.notify(args); |
| 170 | } |
| 171 | |
| 172 | void PointerChoreographer::notifyKey(const NotifyKeyArgs& args) { |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 173 | fadeMouseCursorOnKeyPress(args); |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 174 | mNextListener.notify(args); |
| 175 | } |
| 176 | |
| 177 | void PointerChoreographer::notifyMotion(const NotifyMotionArgs& args) { |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 178 | NotifyMotionArgs newArgs = processMotion(args); |
| 179 | |
| 180 | mNextListener.notify(newArgs); |
| 181 | } |
| 182 | |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 183 | void PointerChoreographer::fadeMouseCursorOnKeyPress(const android::NotifyKeyArgs& args) { |
| 184 | if (args.action == AKEY_EVENT_ACTION_UP || isMetaKey(args.keyCode)) { |
| 185 | return; |
| 186 | } |
| 187 | // Meta state for these keys is ignored for dismissing cursor while typing |
| 188 | constexpr static int32_t ALLOW_FADING_META_STATE_MASK = AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON | |
| 189 | AMETA_SCROLL_LOCK_ON | AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_RIGHT_ON | AMETA_SHIFT_ON; |
| 190 | if (args.metaState & ~ALLOW_FADING_META_STATE_MASK) { |
| 191 | // Do not fade if any other meta state is active |
| 192 | return; |
| 193 | } |
| 194 | if (!mPolicy.isInputMethodConnectionActive()) { |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | std::scoped_lock _l(mLock); |
| 199 | ui::LogicalDisplayId targetDisplay = args.displayId; |
| 200 | if (targetDisplay == ui::LogicalDisplayId::INVALID) { |
| 201 | targetDisplay = mCurrentFocusedDisplay; |
| 202 | } |
| 203 | auto it = mMousePointersByDisplay.find(targetDisplay); |
| 204 | if (it != mMousePointersByDisplay.end()) { |
Arpit Singh | 849beb4 | 2024-06-06 07:14:17 +0000 | [diff] [blame] | 205 | mPolicy.notifyMouseCursorFadedOnTyping(); |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 206 | it->second->fade(PointerControllerInterface::Transition::GRADUAL); |
| 207 | } |
| 208 | } |
| 209 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 210 | NotifyMotionArgs PointerChoreographer::processMotion(const NotifyMotionArgs& args) { |
| 211 | std::scoped_lock _l(mLock); |
| 212 | |
| 213 | if (isFromMouse(args)) { |
| 214 | return processMouseEventLocked(args); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 215 | } else if (isFromTouchpad(args)) { |
| 216 | return processTouchpadEventLocked(args); |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 217 | } else if (isFromDrawingTablet(args)) { |
| 218 | processDrawingTabletEventLocked(args); |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 219 | } else if (mStylusPointerIconEnabled && isStylusHoverEvent(args)) { |
| 220 | processStylusHoverEventLocked(args); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 221 | } else if (isFromSource(args.source, AINPUT_SOURCE_TOUCHSCREEN)) { |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 222 | processTouchscreenAndStylusEventLocked(args); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 223 | } |
| 224 | return args; |
| 225 | } |
| 226 | |
| 227 | NotifyMotionArgs PointerChoreographer::processMouseEventLocked(const NotifyMotionArgs& args) { |
| 228 | if (args.getPointerCount() != 1) { |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 229 | LOG(FATAL) << "Only mouse events with a single pointer are currently supported: " |
| 230 | << args.dump(); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 231 | } |
| 232 | |
Prabir Pradhan | 5a31d3c | 2024-03-29 20:23:22 +0000 | [diff] [blame] | 233 | mMouseDevices.emplace(args.deviceId); |
Prabir Pradhan | 990d871 | 2024-03-05 00:31:36 +0000 | [diff] [blame] | 234 | auto [displayId, pc] = ensureMouseControllerLocked(args.displayId); |
Nergi Rahardi | e0a4cfe | 2024-03-11 13:18:59 +0900 | [diff] [blame] | 235 | NotifyMotionArgs newArgs(args); |
| 236 | newArgs.displayId = displayId; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 237 | |
Nergi Rahardi | e0a4cfe | 2024-03-11 13:18:59 +0900 | [diff] [blame] | 238 | if (MotionEvent::isValidCursorPosition(args.xCursorPosition, args.yCursorPosition)) { |
| 239 | // This is an absolute mouse device that knows about the location of the cursor on the |
| 240 | // display, so set the cursor position to the specified location. |
| 241 | const auto [x, y] = pc.getPosition(); |
| 242 | const float deltaX = args.xCursorPosition - x; |
| 243 | const float deltaY = args.yCursorPosition - y; |
| 244 | newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX); |
| 245 | newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY); |
| 246 | pc.setPosition(args.xCursorPosition, args.yCursorPosition); |
| 247 | } else { |
| 248 | // This is a relative mouse, so move the cursor by the specified amount. |
| 249 | const float deltaX = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X); |
| 250 | const float deltaY = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y); |
| 251 | pc.move(deltaX, deltaY); |
| 252 | const auto [x, y] = pc.getPosition(); |
| 253 | newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); |
| 254 | newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); |
| 255 | newArgs.xCursorPosition = x; |
| 256 | newArgs.yCursorPosition = y; |
| 257 | } |
Prabir Pradhan | 502ddbd | 2024-01-19 02:22:38 +0000 | [diff] [blame] | 258 | if (canUnfadeOnDisplay(displayId)) { |
| 259 | pc.unfade(PointerControllerInterface::Transition::IMMEDIATE); |
| 260 | } |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 261 | return newArgs; |
| 262 | } |
| 263 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 264 | NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMotionArgs& args) { |
Prabir Pradhan | 5a31d3c | 2024-03-29 20:23:22 +0000 | [diff] [blame] | 265 | mMouseDevices.emplace(args.deviceId); |
Prabir Pradhan | 990d871 | 2024-03-05 00:31:36 +0000 | [diff] [blame] | 266 | auto [displayId, pc] = ensureMouseControllerLocked(args.displayId); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 267 | |
| 268 | NotifyMotionArgs newArgs(args); |
| 269 | newArgs.displayId = displayId; |
| 270 | if (args.getPointerCount() == 1 && args.classification == MotionClassification::NONE) { |
| 271 | // This is a movement of the mouse pointer. |
| 272 | const float deltaX = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X); |
| 273 | const float deltaY = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y); |
| 274 | pc.move(deltaX, deltaY); |
Prabir Pradhan | 502ddbd | 2024-01-19 02:22:38 +0000 | [diff] [blame] | 275 | if (canUnfadeOnDisplay(displayId)) { |
| 276 | pc.unfade(PointerControllerInterface::Transition::IMMEDIATE); |
| 277 | } |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 278 | |
| 279 | const auto [x, y] = pc.getPosition(); |
| 280 | newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); |
| 281 | newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); |
| 282 | newArgs.xCursorPosition = x; |
| 283 | newArgs.yCursorPosition = y; |
| 284 | } else { |
| 285 | // This is a trackpad gesture with fake finger(s) that should not move the mouse pointer. |
Prabir Pradhan | 502ddbd | 2024-01-19 02:22:38 +0000 | [diff] [blame] | 286 | if (canUnfadeOnDisplay(displayId)) { |
| 287 | pc.unfade(PointerControllerInterface::Transition::IMMEDIATE); |
| 288 | } |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 289 | |
| 290 | const auto [x, y] = pc.getPosition(); |
| 291 | for (uint32_t i = 0; i < newArgs.getPointerCount(); i++) { |
| 292 | newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, |
| 293 | args.pointerCoords[i].getX() + x); |
| 294 | newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, |
| 295 | args.pointerCoords[i].getY() + y); |
| 296 | } |
| 297 | newArgs.xCursorPosition = x; |
| 298 | newArgs.yCursorPosition = y; |
| 299 | } |
| 300 | return newArgs; |
| 301 | } |
| 302 | |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 303 | void PointerChoreographer::processDrawingTabletEventLocked(const android::NotifyMotionArgs& args) { |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 304 | if (args.displayId == ui::LogicalDisplayId::INVALID) { |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | |
| 308 | if (args.getPointerCount() != 1) { |
| 309 | LOG(WARNING) << "Only drawing tablet events with a single pointer are currently supported: " |
| 310 | << args.dump(); |
| 311 | } |
| 312 | |
| 313 | // Use a mouse pointer controller for drawing tablets, or create one if it doesn't exist. |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 314 | auto [it, controllerAdded] = |
| 315 | mDrawingTabletPointersByDevice.try_emplace(args.deviceId, |
| 316 | getMouseControllerConstructor( |
| 317 | args.displayId)); |
| 318 | if (controllerAdded) { |
| 319 | onControllerAddedOrRemovedLocked(); |
| 320 | } |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 321 | |
| 322 | PointerControllerInterface& pc = *it->second; |
| 323 | |
| 324 | const float x = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X); |
| 325 | const float y = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y); |
| 326 | pc.setPosition(x, y); |
| 327 | if (args.action == AMOTION_EVENT_ACTION_HOVER_EXIT) { |
| 328 | // TODO(b/315815559): Do not fade and reset the icon if the hover exit will be followed |
| 329 | // immediately by a DOWN event. |
| 330 | pc.fade(PointerControllerInterface::Transition::IMMEDIATE); |
| 331 | pc.updatePointerIcon(PointerIconStyle::TYPE_NOT_SPECIFIED); |
| 332 | } else if (canUnfadeOnDisplay(args.displayId)) { |
| 333 | pc.unfade(PointerControllerInterface::Transition::IMMEDIATE); |
| 334 | } |
| 335 | } |
| 336 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 337 | /** |
| 338 | * When screen is touched, fade the mouse pointer on that display. We only call fade for |
| 339 | * ACTION_DOWN events.This would allow both mouse and touch to be used at the same time if the |
| 340 | * mouse device keeps moving and unfades the cursor. |
| 341 | * For touch events, we do not need to populate the cursor position. |
| 342 | */ |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 343 | void PointerChoreographer::processTouchscreenAndStylusEventLocked(const NotifyMotionArgs& args) { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 344 | if (!args.displayId.isValid()) { |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 345 | return; |
| 346 | } |
| 347 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 348 | if (const auto it = mMousePointersByDisplay.find(args.displayId); |
| 349 | it != mMousePointersByDisplay.end() && args.action == AMOTION_EVENT_ACTION_DOWN) { |
| 350 | it->second->fade(PointerControllerInterface::Transition::GRADUAL); |
| 351 | } |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 352 | |
| 353 | if (!mShowTouchesEnabled) { |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | // Get the touch pointer controller for the device, or create one if it doesn't exist. |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 358 | auto [it, controllerAdded] = |
| 359 | mTouchPointersByDevice.try_emplace(args.deviceId, mTouchControllerConstructor); |
| 360 | if (controllerAdded) { |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 361 | onControllerAddedOrRemovedLocked(); |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 362 | } |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 363 | |
| 364 | PointerControllerInterface& pc = *it->second; |
| 365 | |
| 366 | const PointerCoords* coords = args.pointerCoords.data(); |
| 367 | const int32_t maskedAction = MotionEvent::getActionMasked(args.action); |
| 368 | const uint8_t actionIndex = MotionEvent::getActionIndex(args.action); |
| 369 | std::array<uint32_t, MAX_POINTER_ID + 1> idToIndex; |
| 370 | BitSet32 idBits; |
| 371 | if (maskedAction != AMOTION_EVENT_ACTION_UP && maskedAction != AMOTION_EVENT_ACTION_CANCEL) { |
| 372 | for (size_t i = 0; i < args.getPointerCount(); i++) { |
| 373 | if (maskedAction == AMOTION_EVENT_ACTION_POINTER_UP && actionIndex == i) { |
| 374 | continue; |
| 375 | } |
| 376 | uint32_t id = args.pointerProperties[i].id; |
| 377 | idToIndex[id] = i; |
| 378 | idBits.markBit(id); |
| 379 | } |
| 380 | } |
| 381 | // The PointerController already handles setting spots per-display, so |
| 382 | // we do not need to manually manage display changes for touch spots for now. |
| 383 | pc.setSpots(coords, idToIndex.cbegin(), idBits, args.displayId); |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 386 | void PointerChoreographer::processStylusHoverEventLocked(const NotifyMotionArgs& args) { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 387 | if (!args.displayId.isValid()) { |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 388 | return; |
| 389 | } |
| 390 | |
| 391 | if (args.getPointerCount() != 1) { |
| 392 | LOG(WARNING) << "Only stylus hover events with a single pointer are currently supported: " |
| 393 | << args.dump(); |
| 394 | } |
| 395 | |
| 396 | // Get the stylus pointer controller for the device, or create one if it doesn't exist. |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 397 | auto [it, controllerAdded] = |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 398 | mStylusPointersByDevice.try_emplace(args.deviceId, |
| 399 | getStylusControllerConstructor(args.displayId)); |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 400 | if (controllerAdded) { |
| 401 | onControllerAddedOrRemovedLocked(); |
| 402 | } |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 403 | |
| 404 | PointerControllerInterface& pc = *it->second; |
| 405 | |
| 406 | const float x = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X); |
| 407 | const float y = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y); |
| 408 | pc.setPosition(x, y); |
| 409 | if (args.action == AMOTION_EVENT_ACTION_HOVER_EXIT) { |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 410 | // TODO(b/315815559): Do not fade and reset the icon if the hover exit will be followed |
| 411 | // immediately by a DOWN event. |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 412 | pc.fade(PointerControllerInterface::Transition::IMMEDIATE); |
Prabir Pradhan | 4b36db9 | 2024-01-03 20:56:57 +0000 | [diff] [blame] | 413 | pc.updatePointerIcon(PointerIconStyle::TYPE_NOT_SPECIFIED); |
Prabir Pradhan | 502ddbd | 2024-01-19 02:22:38 +0000 | [diff] [blame] | 414 | } else if (canUnfadeOnDisplay(args.displayId)) { |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 415 | pc.unfade(PointerControllerInterface::Transition::IMMEDIATE); |
| 416 | } |
| 417 | } |
| 418 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 419 | void PointerChoreographer::notifySwitch(const NotifySwitchArgs& args) { |
| 420 | mNextListener.notify(args); |
| 421 | } |
| 422 | |
| 423 | void PointerChoreographer::notifySensor(const NotifySensorArgs& args) { |
| 424 | mNextListener.notify(args); |
| 425 | } |
| 426 | |
| 427 | void PointerChoreographer::notifyVibratorState(const NotifyVibratorStateArgs& args) { |
| 428 | mNextListener.notify(args); |
| 429 | } |
| 430 | |
| 431 | void PointerChoreographer::notifyDeviceReset(const NotifyDeviceResetArgs& args) { |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 432 | processDeviceReset(args); |
| 433 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 434 | mNextListener.notify(args); |
| 435 | } |
| 436 | |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 437 | void PointerChoreographer::processDeviceReset(const NotifyDeviceResetArgs& args) { |
| 438 | std::scoped_lock _l(mLock); |
Prabir Pradhan | 1678879 | 2023-11-08 21:07:21 +0000 | [diff] [blame] | 439 | mTouchPointersByDevice.erase(args.deviceId); |
| 440 | mStylusPointersByDevice.erase(args.deviceId); |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 441 | mDrawingTabletPointersByDevice.erase(args.deviceId); |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 442 | onControllerAddedOrRemovedLocked(); |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 445 | void PointerChoreographer::onControllerAddedOrRemovedLocked() { |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 446 | if (!com::android::input::flags::hide_pointer_indicators_for_secure_windows()) { |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 447 | return; |
| 448 | } |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 449 | bool requireListener = !mTouchPointersByDevice.empty() || !mMousePointersByDisplay.empty() || |
| 450 | !mDrawingTabletPointersByDevice.empty() || !mStylusPointersByDevice.empty(); |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 451 | |
| 452 | if (requireListener && mWindowInfoListener == nullptr) { |
| 453 | mWindowInfoListener = sp<PointerChoreographerDisplayInfoListener>::make(this); |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 454 | mWindowInfoListener->setInitialDisplayInfos(mRegisterListener(mWindowInfoListener)); |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 455 | onPrivacySensitiveDisplaysChangedLocked(mWindowInfoListener->getPrivacySensitiveDisplays()); |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 456 | } else if (!requireListener && mWindowInfoListener != nullptr) { |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 457 | mUnregisterListener(mWindowInfoListener); |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 458 | mWindowInfoListener = nullptr; |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 459 | } else if (requireListener && mWindowInfoListener != nullptr) { |
| 460 | // controller may have been added to an existing privacy sensitive display, we need to |
| 461 | // update all controllers again |
| 462 | onPrivacySensitiveDisplaysChangedLocked(mWindowInfoListener->getPrivacySensitiveDisplays()); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | void PointerChoreographer::onPrivacySensitiveDisplaysChangedLocked( |
| 467 | const std::unordered_set<ui::LogicalDisplayId>& privacySensitiveDisplays) { |
| 468 | for (auto& [_, pc] : mTouchPointersByDevice) { |
| 469 | pc->clearSkipScreenshotFlags(); |
| 470 | for (auto displayId : privacySensitiveDisplays) { |
| 471 | pc->setSkipScreenshotFlagForDisplay(displayId); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | for (auto& [displayId, pc] : mMousePointersByDisplay) { |
| 476 | if (privacySensitiveDisplays.find(displayId) != privacySensitiveDisplays.end()) { |
| 477 | pc->setSkipScreenshotFlagForDisplay(displayId); |
| 478 | } else { |
| 479 | pc->clearSkipScreenshotFlags(); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | for (auto* pointerControllerByDevice : |
| 484 | {&mDrawingTabletPointersByDevice, &mStylusPointersByDevice}) { |
| 485 | for (auto& [_, pc] : *pointerControllerByDevice) { |
| 486 | auto displayId = pc->getDisplayId(); |
| 487 | if (privacySensitiveDisplays.find(displayId) != privacySensitiveDisplays.end()) { |
| 488 | pc->setSkipScreenshotFlagForDisplay(displayId); |
| 489 | } else { |
| 490 | pc->clearSkipScreenshotFlags(); |
| 491 | } |
| 492 | } |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 493 | } |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 494 | } |
| 495 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 496 | void PointerChoreographer::notifyPointerCaptureChanged( |
| 497 | const NotifyPointerCaptureChangedArgs& args) { |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 498 | if (args.request.isEnable()) { |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 499 | std::scoped_lock _l(mLock); |
| 500 | for (const auto& [_, mousePointerController] : mMousePointersByDisplay) { |
| 501 | mousePointerController->fade(PointerControllerInterface::Transition::IMMEDIATE); |
| 502 | } |
| 503 | } |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 504 | mNextListener.notify(args); |
| 505 | } |
| 506 | |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 507 | void PointerChoreographer::onPrivacySensitiveDisplaysChanged( |
| 508 | const std::unordered_set<ui::LogicalDisplayId>& privacySensitiveDisplays) { |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 509 | std::scoped_lock _l(mLock); |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 510 | onPrivacySensitiveDisplaysChangedLocked(privacySensitiveDisplays); |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 513 | void PointerChoreographer::dump(std::string& dump) { |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 514 | std::scoped_lock _l(mLock); |
| 515 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 516 | dump += "PointerChoreographer:\n"; |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 517 | dump += StringPrintf("show touches: %s\n", mShowTouchesEnabled ? "true" : "false"); |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 518 | dump += StringPrintf("stylus pointer icon enabled: %s\n", |
| 519 | mStylusPointerIconEnabled ? "true" : "false"); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 520 | |
| 521 | dump += INDENT "MousePointerControllers:\n"; |
| 522 | for (const auto& [displayId, mousePointerController] : mMousePointersByDisplay) { |
| 523 | std::string pointerControllerDump = addLinePrefix(mousePointerController->dump(), INDENT); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 524 | dump += INDENT + displayId.toString() + " : " + pointerControllerDump; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 525 | } |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 526 | dump += INDENT "TouchPointerControllers:\n"; |
| 527 | for (const auto& [deviceId, touchPointerController] : mTouchPointersByDevice) { |
| 528 | std::string pointerControllerDump = addLinePrefix(touchPointerController->dump(), INDENT); |
| 529 | dump += INDENT + std::to_string(deviceId) + " : " + pointerControllerDump; |
| 530 | } |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 531 | dump += INDENT "StylusPointerControllers:\n"; |
| 532 | for (const auto& [deviceId, stylusPointerController] : mStylusPointersByDevice) { |
| 533 | std::string pointerControllerDump = addLinePrefix(stylusPointerController->dump(), INDENT); |
| 534 | dump += INDENT + std::to_string(deviceId) + " : " + pointerControllerDump; |
| 535 | } |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 536 | dump += INDENT "DrawingTabletControllers:\n"; |
| 537 | for (const auto& [deviceId, drawingTabletController] : mDrawingTabletPointersByDevice) { |
| 538 | std::string pointerControllerDump = addLinePrefix(drawingTabletController->dump(), INDENT); |
| 539 | dump += INDENT + std::to_string(deviceId) + " : " + pointerControllerDump; |
| 540 | } |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 541 | dump += "\n"; |
| 542 | } |
| 543 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 544 | const DisplayViewport* PointerChoreographer::findViewportByIdLocked( |
| 545 | ui::LogicalDisplayId displayId) const { |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 546 | for (auto& viewport : mViewports) { |
| 547 | if (viewport.displayId == displayId) { |
| 548 | return &viewport; |
| 549 | } |
| 550 | } |
| 551 | return nullptr; |
| 552 | } |
| 553 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 554 | ui::LogicalDisplayId PointerChoreographer::getTargetMouseDisplayLocked( |
| 555 | ui::LogicalDisplayId associatedDisplayId) const { |
| 556 | return associatedDisplayId.isValid() ? associatedDisplayId : mDefaultMouseDisplayId; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 557 | } |
| 558 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 559 | std::pair<ui::LogicalDisplayId, PointerControllerInterface&> |
| 560 | PointerChoreographer::ensureMouseControllerLocked(ui::LogicalDisplayId associatedDisplayId) { |
| 561 | const ui::LogicalDisplayId displayId = getTargetMouseDisplayLocked(associatedDisplayId); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 562 | |
Prabir Pradhan | 990d871 | 2024-03-05 00:31:36 +0000 | [diff] [blame] | 563 | auto it = mMousePointersByDisplay.find(displayId); |
Prabir Pradhan | 5a31d3c | 2024-03-29 20:23:22 +0000 | [diff] [blame] | 564 | if (it == mMousePointersByDisplay.end()) { |
| 565 | it = mMousePointersByDisplay.emplace(displayId, getMouseControllerConstructor(displayId)) |
| 566 | .first; |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 567 | onControllerAddedOrRemovedLocked(); |
Prabir Pradhan | 5a31d3c | 2024-03-29 20:23:22 +0000 | [diff] [blame] | 568 | } |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 569 | |
| 570 | return {displayId, *it->second}; |
| 571 | } |
| 572 | |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 573 | InputDeviceInfo* PointerChoreographer::findInputDeviceLocked(DeviceId deviceId) { |
Prabir Pradhan | 1678879 | 2023-11-08 21:07:21 +0000 | [diff] [blame] | 574 | auto it = std::find_if(mInputDeviceInfos.begin(), mInputDeviceInfos.end(), |
| 575 | [deviceId](const auto& info) { return info.getId() == deviceId; }); |
| 576 | return it != mInputDeviceInfos.end() ? &(*it) : nullptr; |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 577 | } |
| 578 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 579 | bool PointerChoreographer::canUnfadeOnDisplay(ui::LogicalDisplayId displayId) { |
Prabir Pradhan | 502ddbd | 2024-01-19 02:22:38 +0000 | [diff] [blame] | 580 | return mDisplaysWithPointersHidden.find(displayId) == mDisplaysWithPointersHidden.end(); |
| 581 | } |
| 582 | |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 583 | PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerControllersLocked() { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 584 | std::set<ui::LogicalDisplayId /*displayId*/> mouseDisplaysToKeep; |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 585 | std::set<DeviceId> touchDevicesToKeep; |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 586 | std::set<DeviceId> stylusDevicesToKeep; |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 587 | std::set<DeviceId> drawingTabletDevicesToKeep; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 588 | |
Prabir Pradhan | 6506f6f | 2023-12-11 20:48:39 +0000 | [diff] [blame] | 589 | // Mark the displayIds or deviceIds of PointerControllers currently needed, and create |
| 590 | // new PointerControllers if necessary. |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 591 | for (const auto& info : mInputDeviceInfos) { |
Linnan Li | 48f80da | 2024-04-22 18:38:16 +0000 | [diff] [blame] | 592 | if (!info.isEnabled()) { |
| 593 | // If device is disabled, we should not keep it, and should not show pointer for |
| 594 | // disabled mouse device. |
| 595 | continue; |
| 596 | } |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 597 | const uint32_t sources = info.getSources(); |
Prabir Pradhan | 5a31d3c | 2024-03-29 20:23:22 +0000 | [diff] [blame] | 598 | const bool isKnownMouse = mMouseDevices.count(info.getId()) != 0; |
| 599 | |
| 600 | if (isMouseOrTouchpad(sources) || isKnownMouse) { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 601 | const ui::LogicalDisplayId displayId = |
| 602 | getTargetMouseDisplayLocked(info.getAssociatedDisplayId()); |
Prabir Pradhan | 6506f6f | 2023-12-11 20:48:39 +0000 | [diff] [blame] | 603 | mouseDisplaysToKeep.insert(displayId); |
| 604 | // For mice, show the cursor immediately when the device is first connected or |
| 605 | // when it moves to a new display. |
| 606 | auto [mousePointerIt, isNewMousePointer] = |
| 607 | mMousePointersByDisplay.try_emplace(displayId, |
| 608 | getMouseControllerConstructor(displayId)); |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 609 | if (isNewMousePointer) { |
| 610 | onControllerAddedOrRemovedLocked(); |
| 611 | } |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 612 | |
Prabir Pradhan | 5a31d3c | 2024-03-29 20:23:22 +0000 | [diff] [blame] | 613 | mMouseDevices.emplace(info.getId()); |
| 614 | if ((!isKnownMouse || isNewMousePointer) && canUnfadeOnDisplay(displayId)) { |
Prabir Pradhan | 6506f6f | 2023-12-11 20:48:39 +0000 | [diff] [blame] | 615 | mousePointerIt->second->unfade(PointerControllerInterface::Transition::IMMEDIATE); |
| 616 | } |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 617 | } |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 618 | if (isFromSource(sources, AINPUT_SOURCE_TOUCHSCREEN) && mShowTouchesEnabled && |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 619 | info.getAssociatedDisplayId().isValid()) { |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 620 | touchDevicesToKeep.insert(info.getId()); |
| 621 | } |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 622 | if (isFromSource(sources, AINPUT_SOURCE_STYLUS) && mStylusPointerIconEnabled && |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 623 | info.getAssociatedDisplayId().isValid()) { |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 624 | stylusDevicesToKeep.insert(info.getId()); |
| 625 | } |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 626 | if (isFromSource(sources, AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_MOUSE) && |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 627 | info.getAssociatedDisplayId().isValid()) { |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 628 | drawingTabletDevicesToKeep.insert(info.getId()); |
| 629 | } |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | // Remove PointerControllers no longer needed. |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 633 | std::erase_if(mMousePointersByDisplay, [&mouseDisplaysToKeep](const auto& pair) { |
Prabir Pradhan | 1678879 | 2023-11-08 21:07:21 +0000 | [diff] [blame] | 634 | return mouseDisplaysToKeep.find(pair.first) == mouseDisplaysToKeep.end(); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 635 | }); |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 636 | std::erase_if(mTouchPointersByDevice, [&touchDevicesToKeep](const auto& pair) { |
Prabir Pradhan | 1678879 | 2023-11-08 21:07:21 +0000 | [diff] [blame] | 637 | return touchDevicesToKeep.find(pair.first) == touchDevicesToKeep.end(); |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 638 | }); |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 639 | std::erase_if(mStylusPointersByDevice, [&stylusDevicesToKeep](const auto& pair) { |
Prabir Pradhan | 1678879 | 2023-11-08 21:07:21 +0000 | [diff] [blame] | 640 | return stylusDevicesToKeep.find(pair.first) == stylusDevicesToKeep.end(); |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 641 | }); |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 642 | std::erase_if(mDrawingTabletPointersByDevice, [&drawingTabletDevicesToKeep](const auto& pair) { |
| 643 | return drawingTabletDevicesToKeep.find(pair.first) == drawingTabletDevicesToKeep.end(); |
| 644 | }); |
Prabir Pradhan | 6506f6f | 2023-12-11 20:48:39 +0000 | [diff] [blame] | 645 | std::erase_if(mMouseDevices, [&](DeviceId id) REQUIRES(mLock) { |
| 646 | return std::find_if(mInputDeviceInfos.begin(), mInputDeviceInfos.end(), |
| 647 | [id](const auto& info) { return info.getId() == id; }) == |
| 648 | mInputDeviceInfos.end(); |
| 649 | }); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 650 | |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 651 | onControllerAddedOrRemovedLocked(); |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 652 | |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 653 | // Check if we need to notify the policy if there's a change on the pointer display ID. |
| 654 | return calculatePointerDisplayChangeToNotify(); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 655 | } |
| 656 | |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 657 | PointerChoreographer::PointerDisplayChange |
| 658 | PointerChoreographer::calculatePointerDisplayChangeToNotify() { |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 659 | ui::LogicalDisplayId displayIdToNotify = ui::LogicalDisplayId::INVALID; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 660 | FloatPoint cursorPosition = {0, 0}; |
| 661 | if (const auto it = mMousePointersByDisplay.find(mDefaultMouseDisplayId); |
| 662 | it != mMousePointersByDisplay.end()) { |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 663 | const auto& pointerController = it->second; |
| 664 | // Use the displayId from the pointerController, because it accurately reflects whether |
| 665 | // the viewport has been added for that display. Otherwise, we would have to check if |
| 666 | // the viewport exists separately. |
| 667 | displayIdToNotify = pointerController->getDisplayId(); |
| 668 | cursorPosition = pointerController->getPosition(); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 669 | } |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 670 | if (mNotifiedPointerDisplayId == displayIdToNotify) { |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 671 | return {}; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 672 | } |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 673 | mNotifiedPointerDisplayId = displayIdToNotify; |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 674 | return {{displayIdToNotify, cursorPosition}}; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 675 | } |
| 676 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 677 | void PointerChoreographer::setDefaultMouseDisplayId(ui::LogicalDisplayId displayId) { |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 678 | PointerDisplayChange pointerDisplayChange; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 679 | |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 680 | { // acquire lock |
| 681 | std::scoped_lock _l(mLock); |
| 682 | |
| 683 | mDefaultMouseDisplayId = displayId; |
| 684 | pointerDisplayChange = updatePointerControllersLocked(); |
| 685 | } // release lock |
| 686 | |
| 687 | notifyPointerDisplayChange(pointerDisplayChange, mPolicy); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | void PointerChoreographer::setDisplayViewports(const std::vector<DisplayViewport>& viewports) { |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 691 | PointerDisplayChange pointerDisplayChange; |
| 692 | |
| 693 | { // acquire lock |
| 694 | std::scoped_lock _l(mLock); |
| 695 | for (const auto& viewport : viewports) { |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 696 | const ui::LogicalDisplayId displayId = viewport.displayId; |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 697 | if (const auto it = mMousePointersByDisplay.find(displayId); |
| 698 | it != mMousePointersByDisplay.end()) { |
| 699 | it->second->setDisplayViewport(viewport); |
| 700 | } |
| 701 | for (const auto& [deviceId, stylusPointerController] : mStylusPointersByDevice) { |
| 702 | const InputDeviceInfo* info = findInputDeviceLocked(deviceId); |
| 703 | if (info && info->getAssociatedDisplayId() == displayId) { |
| 704 | stylusPointerController->setDisplayViewport(viewport); |
| 705 | } |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 706 | } |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 707 | for (const auto& [deviceId, drawingTabletController] : mDrawingTabletPointersByDevice) { |
| 708 | const InputDeviceInfo* info = findInputDeviceLocked(deviceId); |
| 709 | if (info && info->getAssociatedDisplayId() == displayId) { |
| 710 | drawingTabletController->setDisplayViewport(viewport); |
| 711 | } |
| 712 | } |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 713 | } |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 714 | mViewports = viewports; |
| 715 | pointerDisplayChange = calculatePointerDisplayChangeToNotify(); |
| 716 | } // release lock |
| 717 | |
| 718 | notifyPointerDisplayChange(pointerDisplayChange, mPolicy); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | std::optional<DisplayViewport> PointerChoreographer::getViewportForPointerDevice( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 722 | ui::LogicalDisplayId associatedDisplayId) { |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 723 | std::scoped_lock _l(mLock); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 724 | const ui::LogicalDisplayId resolvedDisplayId = getTargetMouseDisplayLocked(associatedDisplayId); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 725 | if (const auto viewport = findViewportByIdLocked(resolvedDisplayId); viewport) { |
| 726 | return *viewport; |
| 727 | } |
| 728 | return std::nullopt; |
| 729 | } |
| 730 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 731 | FloatPoint PointerChoreographer::getMouseCursorPosition(ui::LogicalDisplayId displayId) { |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 732 | std::scoped_lock _l(mLock); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 733 | const ui::LogicalDisplayId resolvedDisplayId = getTargetMouseDisplayLocked(displayId); |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 734 | if (auto it = mMousePointersByDisplay.find(resolvedDisplayId); |
| 735 | it != mMousePointersByDisplay.end()) { |
| 736 | return it->second->getPosition(); |
| 737 | } |
| 738 | return {AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION}; |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 741 | void PointerChoreographer::setShowTouchesEnabled(bool enabled) { |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 742 | PointerDisplayChange pointerDisplayChange; |
| 743 | |
| 744 | { // acquire lock |
| 745 | std::scoped_lock _l(mLock); |
| 746 | if (mShowTouchesEnabled == enabled) { |
| 747 | return; |
| 748 | } |
| 749 | mShowTouchesEnabled = enabled; |
| 750 | pointerDisplayChange = updatePointerControllersLocked(); |
| 751 | } // release lock |
| 752 | |
| 753 | notifyPointerDisplayChange(pointerDisplayChange, mPolicy); |
Byoungho Jung | 6f5b16b | 2023-10-27 18:22:07 +0900 | [diff] [blame] | 754 | } |
| 755 | |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 756 | void PointerChoreographer::setStylusPointerIconEnabled(bool enabled) { |
Prabir Pradhan | 5a51a22 | 2024-03-05 03:54:00 +0000 | [diff] [blame] | 757 | PointerDisplayChange pointerDisplayChange; |
| 758 | |
| 759 | { // acquire lock |
| 760 | std::scoped_lock _l(mLock); |
| 761 | if (mStylusPointerIconEnabled == enabled) { |
| 762 | return; |
| 763 | } |
| 764 | mStylusPointerIconEnabled = enabled; |
| 765 | pointerDisplayChange = updatePointerControllersLocked(); |
| 766 | } // release lock |
| 767 | |
| 768 | notifyPointerDisplayChange(pointerDisplayChange, mPolicy); |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 769 | } |
| 770 | |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 771 | bool PointerChoreographer::setPointerIcon( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 772 | std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, |
| 773 | ui::LogicalDisplayId displayId, DeviceId deviceId) { |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 774 | std::scoped_lock _l(mLock); |
| 775 | if (deviceId < 0) { |
Prabir Pradhan | 521f4fc | 2023-12-04 19:09:59 +0000 | [diff] [blame] | 776 | LOG(WARNING) << "Invalid device id " << deviceId << ". Cannot set pointer icon."; |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 777 | return false; |
| 778 | } |
| 779 | const InputDeviceInfo* info = findInputDeviceLocked(deviceId); |
| 780 | if (!info) { |
Prabir Pradhan | 521f4fc | 2023-12-04 19:09:59 +0000 | [diff] [blame] | 781 | LOG(WARNING) << "No input device info found for id " << deviceId |
| 782 | << ". Cannot set pointer icon."; |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 783 | return false; |
| 784 | } |
| 785 | const uint32_t sources = info->getSources(); |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 786 | |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 787 | if (isFromSource(sources, AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_MOUSE)) { |
| 788 | auto it = mDrawingTabletPointersByDevice.find(deviceId); |
| 789 | if (it != mDrawingTabletPointersByDevice.end()) { |
| 790 | setIconForController(icon, *it->second); |
| 791 | return true; |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 792 | } |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 793 | } |
| 794 | if (isFromSource(sources, AINPUT_SOURCE_STYLUS)) { |
| 795 | auto it = mStylusPointersByDevice.find(deviceId); |
| 796 | if (it != mStylusPointersByDevice.end()) { |
| 797 | setIconForController(icon, *it->second); |
| 798 | return true; |
| 799 | } |
| 800 | } |
| 801 | if (isFromSource(sources, AINPUT_SOURCE_MOUSE)) { |
| 802 | auto it = mMousePointersByDisplay.find(displayId); |
| 803 | if (it != mMousePointersByDisplay.end()) { |
| 804 | setIconForController(icon, *it->second); |
| 805 | return true; |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 806 | } else { |
Prabir Pradhan | 521f4fc | 2023-12-04 19:09:59 +0000 | [diff] [blame] | 807 | LOG(WARNING) << "No mouse pointer controller found for display " << displayId |
| 808 | << ", device " << deviceId << "."; |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 809 | return false; |
| 810 | } |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 811 | } |
Prabir Pradhan | 4c977a4 | 2024-03-15 16:47:37 +0000 | [diff] [blame] | 812 | LOG(WARNING) << "Cannot set pointer icon for display " << displayId << ", device " << deviceId |
| 813 | << "."; |
| 814 | return false; |
Byoungho Jung | 9932645 | 2023-11-03 20:19:17 +0900 | [diff] [blame] | 815 | } |
| 816 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 817 | void PointerChoreographer::setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) { |
Prabir Pradhan | 502ddbd | 2024-01-19 02:22:38 +0000 | [diff] [blame] | 818 | std::scoped_lock lock(mLock); |
| 819 | if (visible) { |
| 820 | mDisplaysWithPointersHidden.erase(displayId); |
| 821 | // We do not unfade the icons here, because we don't know when the last event happened. |
| 822 | return; |
| 823 | } |
| 824 | |
| 825 | mDisplaysWithPointersHidden.emplace(displayId); |
| 826 | |
| 827 | // Hide any icons that are currently visible on the display. |
| 828 | if (auto it = mMousePointersByDisplay.find(displayId); it != mMousePointersByDisplay.end()) { |
| 829 | const auto& [_, controller] = *it; |
| 830 | controller->fade(PointerControllerInterface::Transition::IMMEDIATE); |
| 831 | } |
| 832 | for (const auto& [_, controller] : mStylusPointersByDevice) { |
| 833 | if (controller->getDisplayId() == displayId) { |
| 834 | controller->fade(PointerControllerInterface::Transition::IMMEDIATE); |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 839 | void PointerChoreographer::setFocusedDisplay(ui::LogicalDisplayId displayId) { |
| 840 | std::scoped_lock lock(mLock); |
| 841 | mCurrentFocusedDisplay = displayId; |
| 842 | } |
| 843 | |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 844 | PointerChoreographer::ControllerConstructor PointerChoreographer::getMouseControllerConstructor( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 845 | ui::LogicalDisplayId displayId) { |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 846 | std::function<std::shared_ptr<PointerControllerInterface>()> ctor = |
| 847 | [this, displayId]() REQUIRES(mLock) { |
| 848 | auto pc = mPolicy.createPointerController( |
| 849 | PointerControllerInterface::ControllerType::MOUSE); |
| 850 | if (const auto viewport = findViewportByIdLocked(displayId); viewport) { |
| 851 | pc->setDisplayViewport(*viewport); |
| 852 | } |
| 853 | return pc; |
| 854 | }; |
| 855 | return ConstructorDelegate(std::move(ctor)); |
| 856 | } |
| 857 | |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 858 | PointerChoreographer::ControllerConstructor PointerChoreographer::getStylusControllerConstructor( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 859 | ui::LogicalDisplayId displayId) { |
Byoungho Jung | d6fe27b | 2023-10-27 20:49:38 +0900 | [diff] [blame] | 860 | std::function<std::shared_ptr<PointerControllerInterface>()> ctor = |
| 861 | [this, displayId]() REQUIRES(mLock) { |
| 862 | auto pc = mPolicy.createPointerController( |
| 863 | PointerControllerInterface::ControllerType::STYLUS); |
| 864 | if (const auto viewport = findViewportByIdLocked(displayId); viewport) { |
| 865 | pc->setDisplayViewport(*viewport); |
| 866 | } |
| 867 | return pc; |
| 868 | }; |
| 869 | return ConstructorDelegate(std::move(ctor)); |
| 870 | } |
| 871 | |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 872 | void PointerChoreographer::PointerChoreographerDisplayInfoListener::onWindowInfosChanged( |
| 873 | const gui::WindowInfosUpdate& windowInfosUpdate) { |
| 874 | std::scoped_lock _l(mListenerLock); |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 875 | if (mPointerChoreographer == nullptr) { |
| 876 | return; |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 877 | } |
Arpit Singh | 420d074 | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 878 | auto newPrivacySensitiveDisplays = |
| 879 | getPrivacySensitiveDisplaysFromWindowInfos(windowInfosUpdate.windowInfos); |
| 880 | if (newPrivacySensitiveDisplays != mPrivacySensitiveDisplays) { |
| 881 | mPrivacySensitiveDisplays = std::move(newPrivacySensitiveDisplays); |
| 882 | mPointerChoreographer->onPrivacySensitiveDisplaysChanged(mPrivacySensitiveDisplays); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | void PointerChoreographer::PointerChoreographerDisplayInfoListener::setInitialDisplayInfos( |
| 887 | const std::vector<gui::WindowInfo>& windowInfos) { |
| 888 | std::scoped_lock _l(mListenerLock); |
| 889 | mPrivacySensitiveDisplays = getPrivacySensitiveDisplaysFromWindowInfos(windowInfos); |
| 890 | } |
| 891 | |
| 892 | std::unordered_set<ui::LogicalDisplayId /*displayId*/> |
| 893 | PointerChoreographer::PointerChoreographerDisplayInfoListener::getPrivacySensitiveDisplays() { |
| 894 | std::scoped_lock _l(mListenerLock); |
| 895 | return mPrivacySensitiveDisplays; |
Arpit Singh | 4b6ad2d | 2024-04-04 11:54:20 +0000 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | void PointerChoreographer::PointerChoreographerDisplayInfoListener:: |
| 899 | onPointerChoreographerDestroyed() { |
| 900 | std::scoped_lock _l(mListenerLock); |
| 901 | mPointerChoreographer = nullptr; |
| 902 | } |
| 903 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 904 | } // namespace android |