1 /* 2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef INPUT_WINDOWS_MANAGER_H 17 #define INPUT_WINDOWS_MANAGER_H 18 19 #include <shared_mutex> 20 #include "mmi_transform.h" 21 #include "window_manager_lite.h" 22 23 #include "i_input_windows_manager.h" 24 #include "input_display_bind_helper.h" 25 26 namespace OHOS { 27 namespace MMI { 28 constexpr uint32_t SCREEN_CONTROL_WINDOW_TYPE = 2138; 29 struct WindowInfoEX { 30 WindowInfo window; 31 bool flag { false }; 32 }; 33 34 struct SwitchFocusKey { 35 int32_t keyCode { -1 }; 36 int32_t pressedKey { -1 }; 37 }; 38 39 enum AcrossDirection : int32_t { 40 ACROSS_ERROR = 0, 41 UPWARDS = 1, 42 DOWNWARDS = 2, 43 LEFTWARDS = 3, 44 RIGHTWARDS = 4, 45 }; 46 47 class InputWindowsManager final : public IInputWindowsManager { 48 public: 49 InputWindowsManager(); 50 ~InputWindowsManager(); 51 DISALLOW_COPY_AND_MOVE(InputWindowsManager); 52 53 void Init(UDSServer& udsServer); 54 void SetMouseFlag(bool state); 55 bool GetMouseFlag(); 56 bool JudgeCameraInFore(); 57 #ifdef OHOS_BUILD_ENABLE_POINTER 58 void JudgMouseIsDownOrUp(bool dragState); 59 #endif // OHOS_BUILD_ENABLE_POINTER 60 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 61 int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent); 62 int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent, int32_t windowId); 63 bool AdjustFingerFlag(std::shared_ptr<PointerEvent> pointerEvent); 64 void PrintEnterEventInfo(std::shared_ptr<PointerEvent> pointerEvent); 65 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 66 bool HandleWindowInputType(const WindowInfo &window, std::shared_ptr<PointerEvent> pointerEvent); 67 void UpdateCaptureMode(const OLD::DisplayGroupInfo &displayGroupInfo); 68 bool IsFocusedSession(int32_t session) const; 69 void UpdateDisplayInfo(OLD::DisplayGroupInfo &displayGroupInfo); 70 void UpdateDisplayInfoExtIfNeed(OLD::DisplayGroupInfo &displayGroupInfo, bool needUpdateDisplayExt); 71 void UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo); 72 void ProcessInjectEventGlobalXY(std::shared_ptr<PointerEvent> pointerEvent, int32_t useCoordinate); 73 int32_t ClearWindowPointerStyle(int32_t pid, int32_t windowId); 74 void Dump(int32_t fd, const std::vector<std::string> &args); 75 void DumpDisplayInfo(int32_t fd, const std::vector<OLD::DisplayInfo>& displaysInfo); 76 int32_t GetWindowPid(int32_t windowId, const std::vector<WindowInfo> &windowsInfo) const; 77 int32_t GetWindowPid(int32_t windowId) const; 78 int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode); 79 bool GetMouseIsCaptureMode() const; 80 void DeviceStatusChanged(int32_t deviceId, const std::string &name, const std::string &sysUid, 81 const std::string devStatus); 82 int32_t GetDisplayBindInfo(DisplayBindInfos &infos); 83 int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); 84 int32_t AppendExtraData(const ExtraData& extraData); 85 bool IsWindowVisible(int32_t pid); 86 void ClearExtraData(); 87 ExtraData GetExtraData() const; 88 const std::vector<WindowInfo> GetWindowGroupInfoByDisplayIdCopy(int32_t displayId) const; 89 std::pair<double, double> TransformWindowXY(const WindowInfo &window, double logicX, double logicY) const; 90 std::pair<double, double> TransformDisplayXY(const OLD::DisplayInfo &info, double logicX, double logicY) const; 91 int32_t GetCurrentUserId(); 92 bool GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent); 93 void SetFoldState (); 94 bool CheckAppFocused(int32_t pid); 95 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 96 std::vector<std::pair<int32_t, TargetInfo>> GetPidAndUpdateTarget(std::shared_ptr<KeyEvent> keyEvent); 97 void ReissueEvent(std::shared_ptr<KeyEvent> keyEvent, int32_t focusWindowId); 98 std::vector<std::pair<int32_t, TargetInfo>> UpdateTarget(std::shared_ptr<KeyEvent> keyEvent); 99 bool IsKeyPressed(int32_t pressedKey, std::vector<KeyEvent::KeyItem> &keyItems); 100 bool IsOnTheWhitelist(std::shared_ptr<KeyEvent> keyEvent); 101 void HandleKeyEventWindowId(std::shared_ptr<KeyEvent> keyEvent); 102 int32_t focusWindowId_ { -1 }; 103 #endif // OHOS_BUILD_ENABLE_KEYBOARD 104 int32_t CheckWindowIdPermissionByPid(int32_t windowId, int32_t pid); 105 int32_t ClearMouseHideFlag(int32_t eventId); 106 107 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 108 MouseLocation GetMouseInfo(); 109 CursorPosition GetCursorPos(); 110 CursorPosition ResetCursorPos(); 111 void SetGlobalDefaultPointerStyle(); 112 void UpdateAndAdjustMouseLocation(int32_t& displayId, double& x, double& y, bool isRealData = true); 113 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 114 #ifdef OHOS_BUILD_ENABLE_POINTER 115 const OLD::DisplayGroupInfo GetDisplayGroupInfo(int32_t groupId = DEFAULT_GROUP_ID); 116 int32_t SetHoverScrollState(bool state); 117 bool GetHoverScrollState() const; 118 bool SelectPointerChangeArea(int32_t windowId, int32_t logicalX, int32_t logicalY); 119 #endif // OHOS_BUILD_ENABLE_POINTER 120 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 121 int32_t SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle, bool isUiExtension = false); 122 int32_t GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle, 123 bool isUiExtension = false) const; 124 void SetUiExtensionInfo(bool isUiExtension, int32_t uiExtensionPid, int32_t uiExtensionWindoId); 125 void DispatchPointer(int32_t pointerAction, int32_t windowId = -1); 126 void SendPointerEvent(int32_t pointerAction); 127 bool IsMouseSimulate(); 128 bool HasMouseHideFlag(); 129 void UpdatePointerDrawingManagerWindowInfo(); 130 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 131 #ifdef OHOS_BUILD_ENABLE_POINTER 132 PointerStyle GetLastPointerStyle() const; 133 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING 134 bool IsNeedRefreshLayer(int32_t windowId); 135 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING 136 #endif // OHOS_BUILD_ENABLE_POINTER 137 138 #ifdef OHOS_BUILD_ENABLE_TOUCH 139 void AdjustDisplayCoordinate(const OLD::DisplayInfo& displayInfo, double& physicalX, double& physicalY) const; 140 bool TouchPointToDisplayPoint(int32_t deviceId, struct libinput_event_touch* touch, 141 EventTouch& touchInfo, int32_t& targetDisplayId, bool isNeedClear = false); 142 #endif // OHOS_BUILD_ENABLE_TOUCH 143 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 144 void ReverseRotateScreen(const OLD::DisplayInfo& info, const double x, const double y, 145 Coordinate2D& cursorPos) const; 146 void ReverseRotateDisplayScreen(const OLD::DisplayInfo& info, const double x, const double y, 147 Coordinate2D& cursorPos) const; 148 void ScreenRotateAdjustDisplayXY(const OLD::DisplayInfo& info, PhysicalCoordinate& coord) const; 149 void RotateScreen(const OLD::DisplayInfo& info, PhysicalCoordinate& coord) const; 150 void RotateDisplayScreen(const OLD::DisplayInfo& info, PhysicalCoordinate& coord); 151 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 152 #ifdef OHOS_BUILD_ENABLE_TOUCH 153 bool TransformTipPoint(struct libinput_event_tablet_tool* tip, PhysicalCoordinate& coord, int32_t& displayId); 154 bool CalculateTipPoint(struct libinput_event_tablet_tool* tip, 155 int32_t& targetDisplayId, PhysicalCoordinate& coord); 156 const OLD::DisplayInfo *GetDefaultDisplayInfo() const; 157 void ReverseXY(int32_t &x, int32_t &y); 158 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 159 void FoldScreenRotation(std::shared_ptr<PointerEvent> pointerEvent); 160 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 161 void SendCancelEventWhenLock(); 162 #endif // OHOS_BUILD_ENABLE_TOUCH 163 164 #ifdef OHOS_BUILD_ENABLE_ANCO 165 void UpdateWindowInfoExt(const WindowGroupInfo &windowGroupInfo, const OLD::DisplayGroupInfo &displayGroupInfo); 166 void UpdateOneHandDataExt(const OLD::DisplayInfo &displayInfo); 167 void UpdateShellWindow(const WindowInfo &window); 168 void UpdateDisplayInfoExt(const OLD::DisplayGroupInfo &displayGroupInfo); 169 bool IsInAncoWindow(const WindowInfo &window, int32_t x, int32_t y) const; 170 bool IsAncoWindow(const WindowInfo &window) const; 171 bool IsAncoWindowFocus(const WindowInfo &window) const; 172 void SimulatePointerExt(std::shared_ptr<PointerEvent> pointerEvent); 173 void DumpAncoWindows(std::string& out) const; 174 void CleanShellWindowIds(); 175 bool IsKnuckleOnAncoWindow(std::shared_ptr<PointerEvent> pointerEvent); 176 void SendOneHandData(const OLD::DisplayInfo &displayInfo, std::shared_ptr<PointerEvent> &pointerEvent); 177 bool IsAncoGameActive(); 178 #endif // OHOS_BUILD_ENABLE_ANCO 179 180 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 181 bool UpdateDisplayId(int32_t& displayId); 182 void DrawTouchGraphic(std::shared_ptr<PointerEvent> pointerEvent); 183 int32_t UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent); 184 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 185 const OLD::DisplayInfo *GetPhysicalDisplay(int32_t id) const; 186 const OLD::DisplayInfo *GetPhysicalDisplay(int32_t id, 187 const OLD::DisplayGroupInfo &displayGroupInfo) const; 188 189 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 190 void UpdatePointerChangeAreas(); 191 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 192 std::optional<WindowInfo> GetWindowAndDisplayInfo(int32_t windowId, int32_t displayId); 193 void GetTargetWindowIds(int32_t pointerItemId, int32_t sourceType, std::vector<int32_t> &windowIds); 194 void AddTargetWindowIds(int32_t pointerItemId, int32_t sourceType, int32_t windowId); 195 void ClearTargetWindowId(int32_t pointerId); 196 bool IsTransparentWin(std::unique_ptr<Media::PixelMap> &pixelMap, int32_t logicalX, int32_t logicalY); 197 int32_t SetCurrentUser(int32_t userId); 198 DisplayMode GetDisplayMode() const; 199 void SetWindowStateNotifyPid(int32_t pid); 200 int32_t GetWindowStateNotifyPid(); 201 int32_t GetPidByWindowId(int32_t pid); 202 #ifdef OHOS_BUILD_ENABLE_ANCO 203 void InitializeAnco(); 204 int32_t AncoAddChannel(sptr<IAncoChannel> channel); 205 int32_t AncoRemoveChannel(sptr<IAncoChannel> channel); 206 int32_t SyncKnuckleStatus(bool isKnuckleEnable); 207 #endif // OHOS_BUILD_ENABLE_ANCO 208 209 int32_t SetPixelMapData(int32_t infoId, void *pixelMap); 210 211 void CleanInvalidPiexMap(int32_t groupId = DEFAULT_GROUP_ID); 212 void HandleWindowPositionChange(const OLD::DisplayGroupInfo &displayGroupInfo); 213 void SendCancelEventWhenWindowChange(int32_t pointerId, int32_t groupId = DEFAULT_GROUP_ID); 214 bool GetHardCursorEnabled(); 215 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 216 int32_t ShiftAppPointerEvent(const ShiftWindowParam ¶m, bool autoGenDown); 217 Direction GetDisplayDirection(const OLD::DisplayInfo *displayInfo); 218 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 219 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) 220 void AttachTouchGestureMgr(std::shared_ptr<TouchGestureManager> touchGestureMgr); 221 void CancelAllTouches(std::shared_ptr<PointerEvent> event, bool isDisplayChanged = false); 222 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) 223 #ifdef OHOS_BUILD_ENABLE_TOUCH GetLastPointerEventForGesture()224 std::shared_ptr<PointerEvent> GetLastPointerEventForGesture() { return lastPointerEventforGesture_; }; 225 std::pair<int32_t, int32_t> CalcDrawCoordinate(const OLD::DisplayInfo& displayInfo, 226 PointerEvent::PointerItem pointerItem); 227 #endif // OHOS_BUILD_ENABLE_TOUCH 228 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD 229 bool IsPointInsideWindowArea(int x, int y, const WindowInfo& windowItem) const; 230 bool IsPointInsideSpecialWindow(double x, double y); 231 bool IsMouseInCastWindow(); 232 bool IsCaptureMode(); 233 #endif // OHOS_BUILD_ENABLE_VKEYBOARD 234 #ifdef OHOS_BUILD_ENABLE_POINTER 235 bool IsMouseDragging() const; 236 void EnsureMouseEventCycle(std::shared_ptr<PointerEvent> event); 237 void CleanMouseEventCycle(std::shared_ptr<PointerEvent> event); 238 #endif // OHOS_BUILD_ENABLE_POINTER 239 240 private: 241 bool NeedTouchTracking(PointerEvent &event) const; 242 void ProcessTouchTracking(std::shared_ptr<PointerEvent> event, const WindowInfo &targetWindow); 243 bool IgnoreTouchEvent(std::shared_ptr<PointerEvent> pointerEvent); 244 void ReissueCancelTouchEvent(std::shared_ptr<PointerEvent> pointerEvent); 245 int32_t GetDisplayId(std::shared_ptr<InputEvent> inputEvent) const; 246 void PrintHighZorder(const std::vector<WindowInfo> &windowsInfo, int32_t pointerAction, 247 int32_t targetWindowId, int32_t logicalX, int32_t logicalY); 248 void PrintZorderInfo(const WindowInfo &windowInfo, std::string &window); 249 void PrintWindowInfo(const std::vector<WindowInfo> &windowsInfo); 250 void PrintDisplayGroupInfo(const OLD::DisplayGroupInfo displayGroupInfo); 251 void PrintDisplayInfo(const OLD::DisplayInfo displayInfo); 252 void PrintWindowGroupInfo(const WindowGroupInfo &windowGroupInfo); 253 void PrintWindowNavbar(int32_t groupId = DEFAULT_GROUP_ID); 254 void CheckFocusWindowChange(const OLD::DisplayGroupInfo &displayGroupInfo); 255 void CheckZorderWindowChange(const std::vector<WindowInfo> &oldWindowsInfo, 256 const std::vector<WindowInfo> &newWindowsInfo); 257 void UpdateDisplayIdAndName(); 258 void UpdateCustomStyle(int32_t windowId, PointerStyle pointerStyle); 259 void UpdatePointerAction(std::shared_ptr<PointerEvent> pointerEvent); 260 bool IsNeedDrawPointer(PointerEvent::PointerItem &pointerItem) const; 261 void UpdateDisplayInfoByIncrementalInfo(const WindowInfo &window, OLD::DisplayGroupInfo &displayGroupInfo); 262 void UpdateWindowsInfoPerDisplay(const OLD::DisplayGroupInfo &displayGroupInfo); 263 std::pair<int32_t, int32_t> TransformSampleWindowXY(int32_t logicX, int32_t logicY) const; 264 bool IsValidZorderWindow(const WindowInfo &window, const std::shared_ptr<PointerEvent>& pointerEvent); 265 bool SkipPrivacyProtectionWindow(const std::shared_ptr<PointerEvent>& pointerEvent, const bool &isSkip); 266 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 267 void UpdateTopBottomArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas, 268 std::vector<Rect> &windowHotAreas); 269 void UpdateLeftRightArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas, 270 std::vector<Rect> &windowHotAreas); 271 void UpdateInnerAngleArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas, 272 std::vector<Rect> &windowHotAreas); 273 void CoordinateCorrection(int32_t width, int32_t height, int32_t &integerX, int32_t &integerY); 274 void GetWidthAndHeight(const OLD::DisplayInfo* displayInfo, int32_t &width, int32_t &height, 275 bool isRealData = true); 276 void UpdateCurrentDisplay(int32_t displayId) const; 277 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 278 void SetPrivacyModeFlag(SecureFlag privacyMode, std::shared_ptr<InputEvent> event); 279 void PrintChangedWindowByEvent(int32_t eventType, const WindowInfo &newWindowInfo); 280 void PrintChangedWindowBySync(const OLD::DisplayGroupInfo &newDisplayInfo); 281 bool IsMouseDrawing(int32_t currentAction); 282 bool ParseConfig(); 283 bool ParseJson(const std::string &configFile); 284 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 285 void SendUIExtentionPointerEvent(double logicalX, double logicalY, 286 const WindowInfo& windowInfo, std::shared_ptr<PointerEvent> pointerEvent); 287 void DispatchUIExtentionPointerEvent(double logicalX, double logicalY, 288 std::shared_ptr<PointerEvent> pointerEvent); 289 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 290 #ifdef OHOS_BUILD_ENABLE_POINTER 291 std::vector<int32_t> HandleHardwareCursor(const OLD::DisplayInfo *physicalDisplayInfo, 292 int32_t physicalX, int32_t physicalY); 293 int32_t UpdateMouseTarget(std::shared_ptr<PointerEvent> pointerEvent); 294 void UpdatePointerEvent(int32_t logicalX, int32_t logicalY, 295 const std::shared_ptr<PointerEvent>& pointerEvent, const WindowInfo& touchWindow); 296 void NotifyPointerToWindow(int32_t groupId = DEFAULT_GROUP_ID); 297 void OnSessionLost(SessionPtr session); 298 void InitPointerStyle(int32_t groupId = DEFAULT_GROUP_ID); 299 const std::vector<WindowInfo>& GetWindowGroupInfoByDisplayId(int32_t displayId) const; 300 const std::vector<OLD::DisplayInfo>& GetDisplayInfoVector(int32_t groupId = DEFAULT_GROUP_ID) const; 301 const std::vector<WindowInfo>& GetWindowInfoVector(int32_t groupId = DEFAULT_GROUP_ID) const; 302 int32_t GetFocusWindowId(int32_t groupId = DEFAULT_GROUP_ID) const; 303 int32_t GetLogicalPositionX(int32_t id); 304 int32_t GetLogicalPositionY(int32_t id); 305 Direction GetLogicalPositionDirection(int32_t id); 306 Direction GetPositionDisplayDirection(int32_t id); 307 #endif // OHOS_BUILD_ENABLE_POINTER 308 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 309 int32_t UpdatePoinerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle); 310 int32_t UpdateSceneBoardPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle, 311 bool isUiExtension = false); 312 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 313 #ifdef OHOS_BUILD_ENABLE_POINTER 314 int32_t UpdateTouchPadTarget(std::shared_ptr<PointerEvent> pointerEvent); 315 #endif // OHOS_BUILD_ENABLE_POINTER 316 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 317 std::optional<WindowInfo> SelectWindowInfo(int32_t logicalX, int32_t logicalY, 318 const std::shared_ptr<PointerEvent>& pointerEvent); 319 void CheckUIExtentionWindowPointerHotArea(int32_t logicalX, int32_t logicalY, 320 const std::vector<WindowInfo>& windowInfos, int32_t& windowId); 321 std::optional<WindowInfo> GetWindowInfo(int32_t logicalX, int32_t logicalY, int32_t groupId = DEFAULT_GROUP_ID); 322 bool IsInsideDisplay(const OLD::DisplayInfo& displayInfo, double physicalX, double physicalY); 323 bool CalculateLayout(const OLD::DisplayInfo& displayInfo, const Vector2D<double> &physical, 324 Vector2D<double>& layout); 325 void FindPhysicalDisplay(const OLD::DisplayInfo& displayInfo, double& physicalX, 326 double& physicalY, int32_t& displayId); 327 bool AcrossDisplay(const OLD::DisplayInfo &displayInfoDes, const OLD::DisplayInfo &displayInfoOri, 328 Vector2D<double> &logical, Vector2D<double> &layout, const AcrossDirection &acrossDirection); 329 AcrossDirection CalculateAcrossDirection(const OLD::DisplayInfo &displayInfo, const Vector2D<double> &layout); 330 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 331 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 332 void InitMouseDownInfo(); 333 bool SelectPointerChangeArea(const WindowInfo &windowInfo, PointerStyle &pointerStyle, 334 int32_t logicalX, int32_t logicalY); 335 void UpdatePointerChangeAreas(const OLD::DisplayGroupInfo &displayGroupInfo); 336 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING 337 void AdjustDisplayRotation(int32_t groupId = DEFAULT_GROUP_ID); 338 void SetPointerEvent(int32_t pointerAction, std::shared_ptr<PointerEvent> pointerEvent); 339 void DispatchPointerCancel(int32_t displayId); 340 void AdjustDragPosition(int32_t groupId = DEFAULT_GROUP_ID); 341 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING 342 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 343 344 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) 345 void PointerDrawingManagerOnDisplayInfo(const OLD::DisplayGroupInfo &displayGroupInfo, 346 bool isDisplayRemoved = false); 347 void DrawPointer(bool isDisplayRemoved); 348 bool NeedUpdatePointDrawFlag(const std::vector<WindowInfo> &windows); 349 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING 350 351 void UpdateFixedXY(const OLD::DisplayInfo& displayInfo, std::shared_ptr<PointerEvent> &pointerEvent); 352 #ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE 353 void UpdatePointerItemInOneHandMode(const OLD::DisplayInfo &displayInfo, std::shared_ptr<PointerEvent> &pointerEvent); 354 void UpdateDisplayXYInOneHandMode(double& physicalX, double& physicalY, const OLD::DisplayInfo &displayInfo, 355 float oneHandScale); 356 void HandleOneHandMode(const OLD::DisplayInfo &displayInfo, std::shared_ptr<PointerEvent> &pointerEvent, 357 PointerEvent::PointerItem &pointerItem); 358 #endif // OHOS_BUILD_ENABLE_ONE_HAND_MODE 359 360 #ifdef OHOS_BUILD_ENABLE_TOUCH 361 bool SkipAnnotationWindow(uint32_t flag, int32_t toolType); 362 bool SkipNavigationWindow(WindowInputType windowType, int32_t toolType); 363 void HandleGestureInjection(bool gestureInject); 364 int32_t UpdateTouchScreenTarget(std::shared_ptr<PointerEvent> pointerEvent); 365 void UpdateTargetTouchWinIds(const WindowInfo &item, PointerEvent::PointerItem &pointerItem, 366 std::shared_ptr<PointerEvent> pointerEvent, int32_t pointerId, int32_t displayId); 367 void ClearMismatchTypeWinIds(int32_t pointerId, int32_t displayId); 368 #endif // OHOS_BUILD_ENABLE_TOUCH 369 370 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 371 bool IsValidNavigationWindow(const WindowInfo& touchWindow, double physicalX, double physicalY); 372 bool IsNavigationWindowInjectEvent(std::shared_ptr<PointerEvent> pointerEvent); 373 void UpdateTransformDisplayXY(std::shared_ptr<PointerEvent> pointerEvent, 374 const std::vector<WindowInfo>& windowsInfo, const OLD::DisplayInfo& displayInfo); 375 void HandlePullEvent(std::shared_ptr<PointerEvent> pointerEvent); 376 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 377 #ifdef OHOS_BUILD_ENABLE_TOUCH 378 void PullEnterLeaveEvent(int32_t logicalX, int32_t logicalY, 379 const std::shared_ptr<PointerEvent> pointerEvent, const WindowInfo* touchWindow); 380 void DispatchTouch(int32_t pointerAction, int32_t groupId = DEFAULT_GROUP_ID); 381 const OLD::DisplayInfo *FindPhysicalDisplayInfo(const std::string& uniq) const; 382 bool GetPhysicalDisplayCoord(struct libinput_event_touch* touch, 383 const OLD::DisplayInfo& info, EventTouch& touchInfo, bool isNeedClear = false); 384 void TriggerTouchUpOnInvalidAreaEntry(int32_t pointerId); 385 void SetAntiMisTake(bool state); 386 void SetAntiMisTakeStatus(bool state); 387 void CheckUIExtentionWindowDefaultHotArea(std::pair<int32_t, int32_t> logicalXY, bool isHotArea, 388 const std::shared_ptr<PointerEvent> pointerEvent, const std::vector<WindowInfo>& windowInfos, 389 const WindowInfo** touchWindow); 390 void GetUIExtentionWindowInfo(std::vector<WindowInfo> &uiExtentionWindowInfo, int32_t windowId, 391 WindowInfo **touchWindow, bool &isUiExtentionWindow); 392 #endif // OHOS_BUILD_ENABLE_TOUCH 393 394 #ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE 395 void TouchEnterLeaveEvent(int32_t logicalX, int32_t logicalY, 396 const std::shared_ptr<PointerEvent> pointerEvent, const WindowInfo* touchWindow); 397 #endif // OHOS_BUILD_ENABLE_ONE_HAND_MODE 398 399 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 400 bool IsInHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects, const WindowInfo &window) const; 401 bool InWhichHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects, PointerStyle &pointerStyle) const; 402 bool InWhichHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects) const; 403 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 404 template <class T> 405 void CreateAntiMisTakeObserver(T& item); 406 template <class T> 407 void CreatePrivacyProtectionObserver(T& item); 408 409 #ifdef OHOS_BUILD_ENABLE_JOYSTICK 410 int32_t UpdateJoystickTarget(std::shared_ptr<PointerEvent> pointerEvent); 411 #endif // OHOS_BUILD_ENABLE_JOYSTICK 412 413 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_CROWN) 414 int32_t UpdateCrownTarget(std::shared_ptr<PointerEvent> pointerEvent); 415 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_CROWN 416 void UpdateDisplayMode(int32_t groupId = DEFAULT_GROUP_ID); 417 void HandleValidDisplayChange(const OLD::DisplayGroupInfo &displayGroupInfo); 418 void ResetPointerPositionIfOutValidDisplay(const OLD::DisplayGroupInfo &displayGroupInfo); 419 void CancelMouseEvent(); 420 bool IsPositionOutValidDisplay( 421 Coordinate2D &position, const OLD::DisplayInfo ¤tDisplay, bool isPhysicalPos = false); 422 void CancelTouchScreenEventIfValidDisplayChange(const OLD::DisplayGroupInfo &displayGroupInfo); 423 bool IsValidDisplayChange(const OLD::DisplayInfo &displayInfo); 424 void UpdateKeyEventDisplayId(std::shared_ptr<KeyEvent> keyEvent, int32_t focusWindowId, int32_t groupId = DEFAULT_GROUP_ID); 425 bool OnDisplayRemovedOrCombinationChanged(const OLD::DisplayGroupInfo &displayGroupInfo); 426 void ChangeWindowArea(int32_t x, int32_t y, WindowInfo &windowInfo); 427 void ResetPointerPosition(const OLD::DisplayGroupInfo &displayGroupInfo); 428 int32_t GetMainScreenDisplayInfo(const std::vector<OLD::DisplayInfo> &displaysInfo, 429 OLD::DisplayInfo &mainScreenDisplayInfo) const; 430 bool IsPointerOnCenter(const CursorPosition ¤tPos, const OLD::DisplayInfo ¤tDisplay); 431 void SendBackCenterPointerEevent(const CursorPosition &cursorPos); 432 WINDOW_UPDATE_ACTION UpdateWindowInfo(OLD::DisplayGroupInfo &displayGroupInfo); 433 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 434 std::optional<WindowInfo> GetWindowInfoById(int32_t windowId) const; 435 int32_t ShiftAppMousePointerEvent(const ShiftWindowInfo &shiftWindowInfo, bool autoGenDown); 436 int32_t ShiftAppTouchPointerEvent(const ShiftWindowInfo &shiftWindowInfo); 437 int32_t ShiftAppSimulateTouchPointerEvent(const ShiftWindowInfo &shiftWindowInfo); 438 CursorPosition GetCursorPos(const OLD::DisplayGroupInfo &displayGroupInfo); 439 CursorPosition ResetCursorPos(const OLD::DisplayGroupInfo &displayGroupInfo); 440 GlobalCoords DisplayCoords2GlobalCoords(const Coordinate2D &displayCoords, int32_t displayId); 441 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 442 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) 443 bool CancelTouch(int32_t touch); 444 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) 445 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD 446 bool IsPointerActiveRectValid(const OLD::DisplayInfo ¤tDisplay); 447 #endif // OHOS_BUILD_ENABLE_VKEYBOARD 448 bool IsAccessibilityFocusEvent(std::shared_ptr<PointerEvent> pointerEvent); 449 bool IsAccessibilityEventWithZorderInjected(std::shared_ptr<PointerEvent> pointerEvent); 450 void GetActiveWindowTypeById(int32_t windowId, WindowInputType &windowTypeTemp); 451 void AddActiveWindow(int32_t windowId, int32_t pointerId); 452 void RemoveActiveWindow(std::shared_ptr<PointerEvent> pointerEvent); 453 void ClearActiveWindow(); 454 private: 455 OLD::DisplayGroupInfo& FindTargetDisplayGroupInfo(int32_t displayId); 456 int32_t FindDisplayGroupId(int32_t displayId) const; 457 const OLD::DisplayGroupInfo& FindDisplayGroupInfo(int32_t displayId) const; 458 OLD::DisplayGroupInfo& GetDefaultDisplayGroupInfo(); 459 const OLD::DisplayGroupInfo& GetConstMainDisplayGroupInfo() const; 460 void RotateScreen90(const OLD::DisplayInfo& info, PhysicalCoordinate& coord) const; 461 void RotateScreen0(const OLD::DisplayInfo& info, PhysicalCoordinate& coord) const; 462 void InitDisplayGroupInfo(OLD::DisplayGroupInfo &displayGroupInfo); 463 private: 464 UDSServer* udsServer_ { nullptr }; 465 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 466 bool isUiExtension_ { false }; 467 int32_t uiExtensionPid_ { -1 }; 468 int32_t uiExtensionWindowId_ { -1 }; 469 std::pair<int32_t, int32_t> firstBtnDownWindowInfo_ {-1, -1}; 470 std::optional<WindowInfo> axisBeginWindowInfo_ { std::nullopt }; 471 int32_t lastLogicX_ { -1 }; 472 int32_t lastLogicY_ { -1 }; 473 WindowInfo lastWindowInfo_; 474 std::shared_ptr<PointerEvent> lastPointerEvent_ { nullptr }; 475 std::map<int32_t, std::map<int32_t, PointerStyle>> pointerStyle_; 476 std::map<int32_t, std::map<int32_t, PointerStyle>> uiExtensionPointerStyle_; 477 WindowInfo mouseDownInfo_; 478 PointerStyle globalStyle_; 479 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 480 #ifdef OHOS_BUILD_ENABLE_TOUCH 481 int32_t lastTouchLogicX_ { -1 }; 482 int32_t lastTouchLogicY_ { -1 }; 483 WindowInfo lastTouchWindowInfo_; 484 std::shared_ptr<PointerEvent> lastTouchEvent_ { nullptr }; 485 std::shared_ptr<PointerEvent> lastTouchEventOnBackGesture_ { nullptr }; 486 #endif // OHOS_BUILD_ENABLE_TOUCH 487 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) 488 std::weak_ptr<TouchGestureManager> touchGestureMgr_; 489 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) 490 std::map<int32_t, OLD::DisplayGroupInfo> displayGroupInfoMap_; 491 std::map<int32_t, OLD::DisplayGroupInfo> displayGroupInfoMapTmp_; 492 bool mainGroupExisted_; 493 DisplayGroupInfo displayGroupInfoTmp_; 494 std::mutex tmpInfoMutex_; 495 OLD::DisplayGroupInfo displayGroupInfo_; 496 DisplayGroupInfo displayGroupInfoCurr_; 497 std::map<int32_t, WindowGroupInfo> windowsPerDisplay_; 498 std::map<int32_t, std::map<int32_t, WindowGroupInfo>> windowsPerDisplayMap_; 499 PointerStyle lastPointerStyle_; 500 PointerStyle dragPointerStyle_; 501 MouseLocation mouseLocation_ = { -1, 0, 0 }; 502 WindowInfo lockWindowInfo_; 503 504 std::map<int32_t, MouseLocation> mouseLocationMap_; 505 CursorPosition cursorPos_ {}; 506 std::map<int32_t, CursorPosition> cursorPosMap_; 507 508 509 std::map<int32_t, WindowInfoEX> touchItemDownInfos_; 510 std::map<int32_t, std::map<int32_t, WindowInfoEX>> touchItemDownInfosMap_; 511 std::map<int32_t, std::vector<Rect>> windowsHotAreas_; 512 std::map<int32_t, std::map<int32_t, std::vector<Rect>>> windowsHotAreasMap_; 513 514 InputDisplayBindHelper bindInfo_; 515 struct CaptureModeInfo { 516 int32_t windowId { -1 }; 517 bool isCaptureMode { false }; 518 } captureModeInfo_; 519 std::map<int32_t, CaptureModeInfo> captureModeInfoMap_; 520 ExtraData extraData_; 521 int32_t mouseDownEventId_ { -1 }; 522 bool haveSetObserver_ { false }; 523 bool dragFlag_ { false }; 524 bool isDragBorder_ { false }; 525 bool pointerDrawFlag_ { false }; 526 std::map<int32_t, bool> pointerDrawFlagMap_; 527 DisplayMode displayMode_ { DisplayMode::UNKNOWN }; 528 std::map<int32_t, DisplayMode> displayModeMap_; 529 struct AntiMisTake { 530 std::string switchName; 531 bool isOpen { false }; 532 } antiMistake_; 533 bool isOpenAntiMisTakeObserver_ { false }; 534 struct PrivacyProtection { 535 std::string switchName; 536 bool isOpen { false }; 537 } privacyProtection_; 538 bool isOpenPrivacyProtectionserver_ { false }; 539 bool mouseFlag_ {false}; 540 struct ActiveTouchWin { 541 WindowInputType windowInputType{ WindowInputType::NORMAL }; 542 std::set<int32_t> pointerSet; 543 explicit ActiveTouchWin(WindowInputType windowInputType, std::set<int32_t> pointerSet = {}) windowInputTypeActiveTouchWin544 : windowInputType(windowInputType), pointerSet(pointerSet) 545 {} 546 }; 547 std::map<int32_t, ActiveTouchWin> activeTouchWinTypes_; 548 std::map<int32_t, std::vector<int32_t>> targetTouchWinIds_; 549 std::map<int32_t, std::vector<int32_t>> targetMouseWinIds_; 550 int32_t pointerActionFlag_ { -1 }; 551 int32_t currentUserId_ { -1 }; 552 std::shared_ptr<PointerEvent> lastPointerEventforWindowChange_ { nullptr }; 553 std::map<int32_t, std::shared_ptr<PointerEvent>> lastPointerEventforWindowChangeMap_; 554 bool cancelTouchStatus_ { false }; 555 std::pair<int32_t, Direction> lastDirection_ { -1, static_cast<Direction>(-1) }; 556 std::map<int32_t, WindowInfo> lastMatchedWindow_; 557 std::vector<SwitchFocusKey> vecWhiteList_; 558 bool isParseConfig_ { false }; 559 int32_t windowStateNotifyPid_ { -1 }; 560 std::map<int32_t, std::unique_ptr<Media::PixelMap>> transparentWins_; 561 #ifdef OHOS_BUILD_ENABLE_TOUCH 562 std::shared_ptr<PointerEvent> lastPointerEventforGesture_ { nullptr }; 563 #endif // OHOS_BUILD_ENABLE_TOUCH 564 bool IsFoldable_ { false }; 565 int32_t timerId_ { -1 }; 566 int32_t lastDpi_ { 0 }; 567 std::map<int32_t, int32_t> lastDpiMap_; 568 std::shared_ptr<PointerEvent> GetlastPointerEvent(); 569 void SetDragFlagByPointer(std::shared_ptr<PointerEvent> lastPointerEvent); 570 std::mutex mtx_; 571 std::atomic_bool isFoldPC_ { false }; 572 std::mutex oneHandMtx_; 573 int32_t scalePercent_ = 100; 574 mutable int32_t lastWinX_ { 0 }; 575 mutable int32_t lastWinY_ { 0 }; 576 mutable std::pair<int32_t, int32_t> currentDisplayXY_ { 0, 0 }; 577 }; 578 } // namespace MMI 579 } // namespace OHOS 580 #endif // INPUT_WINDOWS_MANAGER_H 581