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