• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 "mmi_transform.h"
20 #include "window_manager_lite.h"
21 
22 #include "i_input_windows_manager.h"
23 #include "input_display_bind_helper.h"
24 #ifndef OHOS_BUILD_ENABLE_WATCH
25 #include "knuckle_drawing_manager.h"
26 #include "knuckle_dynamic_drawing_manager.h"
27 #endif // OHOS_BUILD_ENABLE_WATCH
28 
29 namespace OHOS {
30 namespace MMI {
31 constexpr uint32_t SCREEN_CONTROL_WINDOW_TYPE = 2137;
32 struct WindowInfoEX {
33     WindowInfo window;
34     bool flag { false };
35 };
36 
37 struct SwitchFocusKey {
38     int32_t keyCode { -1 };
39     int32_t pressedKey { -1 };
40 };
41 
42 enum AcrossDirection : int32_t {
43     ACROSS_ERROR = 0,
44     UPWARDS = 1,
45     DOWNWARDS = 2,
46     LEFTWARDS = 3,
47     RIGHTWARDS = 4,
48 };
49 
50 class InputWindowsManager final : public IInputWindowsManager {
51 public:
52     InputWindowsManager();
53     ~InputWindowsManager();
54     DISALLOW_COPY_AND_MOVE(InputWindowsManager);
55 
56     void Init(UDSServer& udsServer);
57     void SetMouseFlag(bool state);
58     bool GetMouseFlag();
59     bool JudgeCaramaInFore();
60 #ifdef OHOS_BUILD_ENABLE_POINTER
61     void JudgMouseIsDownOrUp(bool dragState);
62 #endif // OHOS_BUILD_ENABLE_POINTER
63 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
64     int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent);
65     int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent, int32_t windowId);
66     bool AdjustFingerFlag(std::shared_ptr<PointerEvent> pointerEvent);
67     void PrintEnterEventInfo(std::shared_ptr<PointerEvent> pointerEvent);
68 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
69     bool HandleWindowInputType(const WindowInfo &window, std::shared_ptr<PointerEvent> pointerEvent);
70     void UpdateCaptureMode(const DisplayGroupInfo &displayGroupInfo);
71     bool IsFocusedSession(int32_t session) const;
72     void UpdateDisplayInfo(DisplayGroupInfo &displayGroupInfo);
73     void UpdateDisplayInfoExtIfNeed(DisplayGroupInfo &displayGroupInfo, bool needUpdateDisplayExt);
74     void UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo);
75     int32_t ClearWindowPointerStyle(int32_t pid, int32_t windowId);
76     void Dump(int32_t fd, const std::vector<std::string> &args);
77     void DumpDisplayInfo(int32_t fd);
78     int32_t GetWindowPid(int32_t windowId, const std::vector<WindowInfo> &windowsInfo) const;
79     int32_t GetWindowPid(int32_t windowId) const;
80     int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode);
81     bool GetMouseIsCaptureMode() const;
82     void DeviceStatusChanged(int32_t deviceId, const std::string &sysUid, const std::string devStatus);
83     int32_t GetDisplayBindInfo(DisplayBindInfos &infos);
84     int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg);
85     int32_t AppendExtraData(const ExtraData& extraData);
86     bool IsWindowVisible(int32_t pid);
87     void ClearExtraData();
88     ExtraData GetExtraData() const;
89     const std::vector<WindowInfo>& GetWindowGroupInfoByDisplayId(int32_t displayId) const;
90     std::pair<double, double> TransformWindowXY(const WindowInfo &window, double logicX, double logicY) const;
91     std::pair<double, double> TransformDisplayXY(const DisplayInfo &info, double logicX, double logicY) const;
92     int32_t GetCurrentUserId();
93     bool GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent);
94     void SetFoldState ();
95     bool CheckAppFocused(int32_t pid);
96 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
97     std::vector<std::pair<int32_t, TargetInfo>> GetPidAndUpdateTarget(std::shared_ptr<KeyEvent> keyEvent);
98     void ReissueEvent(std::shared_ptr<KeyEvent> keyEvent, int32_t focusWindowId);
99     std::vector<std::pair<int32_t, TargetInfo>> UpdateTarget(std::shared_ptr<KeyEvent> keyEvent);
100     bool IsKeyPressed(int32_t pressedKey, std::vector<KeyEvent::KeyItem> &keyItems);
101     bool IsOnTheWhitelist(std::shared_ptr<KeyEvent> keyEvent);
102     void HandleKeyEventWindowId(std::shared_ptr<KeyEvent> keyEvent);
103     int32_t focusWindowId_ { -1 };
104 #endif // OHOS_BUILD_ENABLE_KEYBOARD
105     int32_t CheckWindowIdPermissionByPid(int32_t windowId, int32_t pid);
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 DisplayGroupInfo& GetDisplayGroupInfo();
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 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 DisplayInfo& info, const double x, const double y, Coordinate2D& cursorPos) const;
145     void ReverseRotateDisplayScreen(const DisplayInfo& info, const double x, const double y,
146         Coordinate2D& cursorPos) const;
147     void ScreenRotateAdjustDisplayXY(const DisplayInfo& info, PhysicalCoordinate& coord) const;
148     void RotateScreen(const DisplayInfo& info, PhysicalCoordinate& coord) const;
149     void RotateDisplayScreen(const DisplayInfo& info, PhysicalCoordinate& coord);
150 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
151 #ifdef OHOS_BUILD_ENABLE_TOUCH
152     bool TransformTipPoint(struct libinput_event_tablet_tool* tip, PhysicalCoordinate& coord, int32_t& displayId) const;
153     bool CalculateTipPoint(struct libinput_event_tablet_tool* tip,
154         int32_t& targetDisplayId, PhysicalCoordinate& coord) const;
155     const DisplayInfo *GetDefaultDisplayInfo() const;
156     void ReverseXY(int32_t &x, int32_t &y);
157 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
158     void FoldScreenRotation(std::shared_ptr<PointerEvent> pointerEvent);
159 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
160     void SendCancelEventWhenLock();
161 #endif // OHOS_BUILD_ENABLE_TOUCH
162 
163 #ifdef OHOS_BUILD_ENABLE_ANCO
164     void UpdateWindowInfoExt(const WindowGroupInfo &windowGroupInfo, const DisplayGroupInfo &displayGroupInfo);
165     void UpdateShellWindow(const WindowInfo &window);
166     void UpdateDisplayInfoExt(const DisplayGroupInfo &displayGroupInfo);
167     bool IsInAncoWindow(const WindowInfo &window, int32_t x, int32_t y) const;
168     bool IsAncoWindow(const WindowInfo &window) const;
169     bool IsAncoWindowFocus(const WindowInfo &window) const;
170     void SimulatePointerExt(std::shared_ptr<PointerEvent> pointerEvent);
171     void DumpAncoWindows(std::string& out) const;
172     void CleanShellWindowIds();
173     bool IsKnuckleOnAncoWindow(std::shared_ptr<PointerEvent> pointerEvent);
174 #endif // OHOS_BUILD_ENABLE_ANCO
175 
176 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
177     bool UpdateDisplayId(int32_t& displayId);
178     void DrawTouchGraphic(std::shared_ptr<PointerEvent> pointerEvent);
179     int32_t UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent);
180 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
181     const DisplayInfo* GetPhysicalDisplay(int32_t id) const;
182     const DisplayInfo* GetPhysicalDisplay(int32_t id, const DisplayGroupInfo &displayGroupInfo) const;
183 
184 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
185     void UpdatePointerChangeAreas();
186 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
187     std::optional<WindowInfo> GetWindowAndDisplayInfo(int32_t windowId, int32_t displayId);
188     void GetTargetWindowIds(int32_t pointerItemId, int32_t sourceType, std::vector<int32_t> &windowIds);
189     void AddTargetWindowIds(int32_t pointerItemId, int32_t sourceType, int32_t windowId);
190     void ClearTargetWindowId(int32_t pointerId);
191     bool IsTransparentWin(std::unique_ptr<Media::PixelMap> &pixelMap, int32_t logicalX, int32_t logicalY);
192     int32_t SetCurrentUser(int32_t userId);
193     DisplayMode GetDisplayMode() const;
194     void SetWindowStateNotifyPid(int32_t pid);
195     int32_t GetWindowStateNotifyPid();
196     int32_t GetPidByWindowId(int32_t pid);
197 #ifdef OHOS_BUILD_ENABLE_ANCO
198     int32_t AncoAddChannel(sptr<IAncoChannel> channel);
199     int32_t AncoRemoveChannel(sptr<IAncoChannel> channel);
200     int32_t SyncKnuckleStatus(bool isKnuckleEnable);
201 #endif // OHOS_BUILD_ENABLE_ANCO
202 
203     int32_t SetPixelMapData(int32_t infoId, void *pixelMap);
204     void CleanInvalidPiexMap();
205     void HandleWindowPositionChange();
206 #ifdef OHOS_BUILD_ENABLE_HARDWARE_CURSOR
207     bool IsSupported();
208 #endif // OHOS_BUILD_ENABLE_HARDWARE_CURSOR
209 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
210     int32_t ShiftAppPointerEvent(const ShiftWindowParam &param, bool autoGenDown);
211 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
212 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
213     void AttachTouchGestureMgr(std::shared_ptr<TouchGestureManager> touchGestureMgr);
214     void CancelAllTouches(std::shared_ptr<PointerEvent> event);
215 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
216 #ifdef OHOS_BUILD_ENABLE_TOUCH
GetLastPointerEventForGesture()217     std::shared_ptr<PointerEvent> GetLastPointerEventForGesture() { return lastPointerEventforGesture_; };
218 #endif // OHOS_BUILD_ENABLE_TOUCH
219 
220 private:
221     bool IgnoreTouchEvent(std::shared_ptr<PointerEvent> pointerEvent);
222     void ReissueCancelTouchEvent(std::shared_ptr<PointerEvent> pointerEvent);
223     int32_t GetDisplayId(std::shared_ptr<InputEvent> inputEvent) const;
224     void PrintHighZorder(const std::vector<WindowInfo> &windowsInfo, int32_t pointerAction,
225         int32_t targetWindowId, int32_t logicalX, int32_t logicalY);
226     void PrintZorderInfo(const WindowInfo &windowInfo, std::string &window);
227     void PrintWindowInfo(const std::vector<WindowInfo> &windowsInfo);
228     void PrintDisplayGroupInfo(const DisplayGroupInfo displayGroupInfo);
229     void PrintDisplayInfo(const DisplayInfo displayInfo);
230     int32_t ConvertToolType(int32_t toolType);
231     void PrintWindowGroupInfo(const WindowGroupInfo &windowGroupInfo);
232     void PrintWindowNavbar();
233     void CheckFocusWindowChange(const DisplayGroupInfo &displayGroupInfo);
234     void CheckZorderWindowChange(const std::vector<WindowInfo> &oldWindowsInfo,
235         const std::vector<WindowInfo> &newWindowsInfo);
236     void UpdateDisplayIdAndName();
237     void UpdateCustomStyle(int32_t windowId, PointerStyle pointerStyle);
238     void UpdatePointerAction(std::shared_ptr<PointerEvent> pointerEvent);
239     bool IsNeedDrawPointer(PointerEvent::PointerItem &pointerItem) const;
240     void UpdateDisplayInfoByIncrementalInfo(const WindowInfo &window, DisplayGroupInfo &displayGroupInfo);
241     void UpdateWindowsInfoPerDisplay(const DisplayGroupInfo &displayGroupInfo);
242     std::pair<int32_t, int32_t> TransformSampleWindowXY(int32_t logicX, int32_t logicY) const;
243     bool IsValidZorderWindow(const WindowInfo &window, const std::shared_ptr<PointerEvent>& pointerEvent);
244 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
245     void UpdateTopBottomArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas,
246         std::vector<Rect> &windowHotAreas);
247     void UpdateLeftRightArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas,
248         std::vector<Rect> &windowHotAreas);
249     void UpdateInnerAngleArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas,
250         std::vector<Rect> &windowHotAreas);
251     void CoordinateCorrection(int32_t width, int32_t height, int32_t &integerX, int32_t &integerY);
252     Direction GetDisplayDirection(const DisplayInfo *displayInfo);
253     void GetWidthAndHeight(const DisplayInfo* displayInfo, int32_t &width, int32_t &height, bool isRealData = true);
254 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
255     void SetPrivacyModeFlag(SecureFlag privacyMode, std::shared_ptr<InputEvent> event);
256     void PrintChangedWindowByEvent(int32_t eventType, const WindowInfo &newWindowInfo);
257     void PrintChangedWindowBySync(const DisplayGroupInfo &newDisplayInfo);
258     bool IsMouseDrawing(int32_t currentAction);
259     bool ParseConfig();
260     bool ParseJson(const std::string &configFile);
261 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
262     void SendUIExtentionPointerEvent(int32_t logicalX, int32_t logicalY,
263         const WindowInfo& windowInfo, std::shared_ptr<PointerEvent> pointerEvent);
264     void DispatchUIExtentionPointerEvent(int32_t logicalX, int32_t logicalY,
265         std::shared_ptr<PointerEvent> pointerEvent);
266 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
267 #ifdef OHOS_BUILD_ENABLE_POINTER
268     int32_t UpdateMouseTarget(std::shared_ptr<PointerEvent> pointerEvent);
269     void UpdatePointerEvent(int32_t logicalX, int32_t logicalY,
270         const std::shared_ptr<PointerEvent>& pointerEvent, const WindowInfo& touchWindow);
271     void NotifyPointerToWindow();
272     void OnSessionLost(SessionPtr session);
273     void InitPointerStyle();
274 #endif // OHOS_BUILD_ENABLE_POINTER
275 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
276     int32_t UpdatePoinerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle);
277     int32_t UpdateSceneBoardPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle,
278         bool isUiExtension = false);
279 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
280 #ifdef OHOS_BUILD_ENABLE_POINTER
281     int32_t UpdateTouchPadTarget(std::shared_ptr<PointerEvent> pointerEvent);
282 #endif // OHOS_BUILD_ENABLE_POINTER
283 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
284     std::optional<WindowInfo> SelectWindowInfo(int32_t logicalX, int32_t logicalY,
285         const std::shared_ptr<PointerEvent>& pointerEvent);
286     void CheckUIExtentionWindowPointerHotArea(int32_t logicalX, int32_t logicalY,
287         const std::vector<WindowInfo>& windowInfos, int32_t& windowId);
288     std::optional<WindowInfo> GetWindowInfo(int32_t logicalX, int32_t logicalY);
289     bool IsInsideDisplay(const DisplayInfo& displayInfo, double physicalX, double physicalY);
290     bool CalculateLayout(const DisplayInfo& displayInfo, const Vector2D<double> &physical, Vector2D<double>& layout);
291     void FindPhysicalDisplay(const DisplayInfo& displayInfo, double& physicalX,
292         double& physicalY, int32_t& displayId);
293     bool AcrossDisplay(const DisplayInfo &displayInfoDes, const DisplayInfo &displayInfoOri, Vector2D<double> &logical,
294         Vector2D<double> &layout, const AcrossDirection &acrossDirection);
295     AcrossDirection CalculateAcrossDirection(const DisplayInfo &displayInfo, const Vector2D<double> &layout);
296 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
297 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
298     void InitMouseDownInfo();
299     bool SelectPointerChangeArea(const WindowInfo &windowInfo, PointerStyle &pointerStyle,
300         int32_t logicalX, int32_t logicalY);
301     void UpdatePointerChangeAreas(const DisplayGroupInfo &displayGroupInfo);
302 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
303     void AdjustDisplayRotation();
304     void SetPointerEvent(int32_t pointerAction, std::shared_ptr<PointerEvent> pointerEvent);
305     void DispatchPointerCancel(int32_t displayId);
306     void AdjustDragPosition();
307 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
308 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
309 
310 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
311 void PointerDrawingManagerOnDisplayInfo(const DisplayGroupInfo &displayGroupInfo, bool isDisplayRemoved = false);
312 void DrawPointer(bool isDisplayRemoved);
313 bool NeedUpdatePointDrawFlag(const std::vector<WindowInfo> &windows);
314 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
315 
316     void UpdateFixedXY(const DisplayInfo& displayInfo, std::shared_ptr<PointerEvent> &pointerEvent);
317 #ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE
318 void UpdatePointerItemInOneHandMode(const DisplayInfo &displayInfo, std::shared_ptr<PointerEvent> &pointerEvent);
319 void UpdateDisplayXYInOneHandMode(double& physicalX, double& physicalY, const DisplayInfo &displayInfo,
320     float oneHandScale);
321 #endif // OHOS_BUILD_ENABLE_ONE_HAND_MODE
322 
323 #ifdef OHOS_BUILD_ENABLE_TOUCH
324     bool SkipAnnotationWindow(uint32_t flag, int32_t toolType);
325     bool SkipNavigationWindow(WindowInputType windowType, int32_t toolType);
326     void HandleGestureInjection(bool gestureInject);
327     int32_t UpdateTouchScreenTarget(std::shared_ptr<PointerEvent> pointerEvent);
328     void UpdateTargetTouchWinIds(const WindowInfo &item, PointerEvent::PointerItem &pointerItem,
329         std::shared_ptr<PointerEvent> pointerEvent, int32_t pointerId, int32_t displayId);
330     void ClearMismatchTypeWinIds(int32_t pointerId, int32_t displayId);
331 #endif // OHOS_BUILD_ENABLE_TOUCH
332 
333 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
334     bool IsValidNavigationWindow(const WindowInfo& touchWindow, double physicalX, double physicalY);
335     bool IsNavigationWindowInjectEvent(std::shared_ptr<PointerEvent> pointerEvent);
336     void UpdateTransformDisplayXY(std::shared_ptr<PointerEvent> pointerEvent,
337         const std::vector<WindowInfo>& windowsInfo, const DisplayInfo& displayInfo);
338 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
339 #ifdef OHOS_BUILD_ENABLE_TOUCH
340     void PullEnterLeaveEvent(int32_t logicalX, int32_t logicalY,
341         const std::shared_ptr<PointerEvent> pointerEvent, const WindowInfo* touchWindow);
342     void DispatchTouch(int32_t pointerAction);
343     const DisplayInfo* FindPhysicalDisplayInfo(const std::string& uniq) const;
344     bool GetPhysicalDisplayCoord(struct libinput_event_touch* touch,
345         const DisplayInfo& info, EventTouch& touchInfo, bool isNeedClear = false);
346     void TriggerTouchUpOnInvalidAreaEntry(int32_t pointerId);
347     void SetAntiMisTake(bool state);
348     void SetAntiMisTakeStatus(bool state);
349     void CheckUIExtentionWindowDefaultHotArea(std::pair<int32_t, int32_t> logicalXY, bool isHotArea,
350         const std::shared_ptr<PointerEvent> pointerEvent, const std::vector<WindowInfo>& windowInfos,
351         const WindowInfo** touchWindow);
352     void GetUIExtentionWindowInfo(std::vector<WindowInfo> &uiExtentionWindowInfo, int32_t windowId,
353         WindowInfo **touchWindow, bool &isUiExtentionWindow);
354 #endif // OHOS_BUILD_ENABLE_TOUCH
355 
356 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
357     bool IsInHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects, const WindowInfo &window) const;
358     bool InWhichHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects, PointerStyle &pointerStyle) const;
359     bool InWhichHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects) const;
360 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
361     template <class T>
362     void CreateAntiMisTakeObserver(T& item);
363 
364 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
365     int32_t UpdateJoystickTarget(std::shared_ptr<PointerEvent> pointerEvent);
366 #endif // OHOS_BUILD_ENABLE_JOYSTICK
367 
368 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_CROWN)
369     int32_t UpdateCrownTarget(std::shared_ptr<PointerEvent> pointerEvent);
370 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_CROWN
371     void UpdateDisplayMode();
372     void HandleValidDisplayChange(const DisplayGroupInfo &displayGroupInfo);
373     void ResetPointerPositionIfOutValidDisplay(const DisplayGroupInfo &displayGroupInfo);
374     void CancelMouseEvent();
375     bool IsPositionOutValidDisplay(
376         Coordinate2D &position, const DisplayInfo &currentDisplay, bool isPhysicalPos = false);
377     void CancelTouchScreenEventIfValidDisplayChange(const DisplayGroupInfo &displayGroupInfo);
378     bool IsValidDisplayChange(const DisplayInfo &displayInfo);
379 #ifdef OHOS_BUILD_ENABLE_HARDWARE_CURSOR
380     void UpdateKeyEventDisplayId(std::shared_ptr<KeyEvent> keyEvent, int32_t focusWindowId);
381     bool OnDisplayRemovedOrCombiantionChanged(const DisplayGroupInfo &displayGroupInfo);
382     void ChangeWindowArea(int32_t x, int32_t y, WindowInfo &windowInfo);
383     void ResetPointerPosition(const DisplayGroupInfo &displayGroupInfo);
384     int32_t GetMainScreenDisplayInfo(const DisplayGroupInfo &displayGroupInfo,
385         DisplayInfo &mainScreenDisplayInfo) const;
386     bool IsPointerOnCenter(const CursorPosition &currentPos, const DisplayInfo &currentDisplay);
387     void SendBackCenterPointerEevent(const CursorPosition &cursorPos);
388 #endif // OHOS_BUILD_ENABLE_HARDWARE_CURSOR
389     WINDOW_UPDATE_ACTION UpdateWindowInfo(DisplayGroupInfo &displayGroupInfo);
390 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
391     std::optional<WindowInfo> GetWindowInfoById(int32_t windowId) const;
392     int32_t ShiftAppMousePointerEvent(const ShiftWindowInfo &shiftWindowInfo, bool autoGenDown);
393 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
394 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
395     bool CancelTouch(int32_t touch);
396 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
397 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
398     bool IsPointerActiveRectValid(const DisplayInfo &currentDisplay);
399 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
400 
401 private:
402     UDSServer* udsServer_ { nullptr };
403 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
404     bool isUiExtension_ { false };
405     int32_t uiExtensionPid_ { -1 };
406     int32_t uiExtensionWindowId_ { -1 };
407     std::pair<int32_t, int32_t> firstBtnDownWindowInfo_ {-1, -1};
408     std::optional<WindowInfo> axisBeginWindowInfo_ { std::nullopt };
409     int32_t lastLogicX_ { -1 };
410     int32_t lastLogicY_ { -1 };
411     WindowInfo lastWindowInfo_;
412     std::shared_ptr<PointerEvent> lastPointerEvent_ { nullptr };
413     std::map<int32_t, std::map<int32_t, PointerStyle>> pointerStyle_;
414     std::map<int32_t, std::map<int32_t, PointerStyle>> uiExtensionPointerStyle_;
415     WindowInfo mouseDownInfo_;
416     PointerStyle globalStyle_;
417 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
418 #ifdef OHOS_BUILD_ENABLE_TOUCH
419     int32_t lastTouchLogicX_ { -1 };
420     int32_t lastTouchLogicY_ { -1 };
421     WindowInfo lastTouchWindowInfo_;
422     std::shared_ptr<PointerEvent> lastTouchEvent_ { nullptr };
423     std::shared_ptr<PointerEvent> lastTouchEventOnBackGesture_ { nullptr };
424 #endif // OHOS_BUILD_ENABLE_TOUCH
425 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
426     std::weak_ptr<TouchGestureManager> touchGestureMgr_;
427 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
428     DisplayGroupInfo displayGroupInfoTmp_;
429     std::mutex tmpInfoMutex_;
430     DisplayGroupInfo displayGroupInfo_;
431     std::map<int32_t, WindowGroupInfo> windowsPerDisplay_;
432     PointerStyle lastPointerStyle_ {.id = -1};
433     PointerStyle dragPointerStyle_ {.id = -1};
434     MouseLocation mouseLocation_ = { -1, -1 };
435     CursorPosition cursorPos_ {};
436     std::map<int32_t, WindowInfoEX> touchItemDownInfos_;
437     std::map<int32_t, std::vector<Rect>> windowsHotAreas_;
438     InputDisplayBindHelper bindInfo_;
439     struct CaptureModeInfo {
440         int32_t windowId { -1 };
441         bool isCaptureMode { false };
442     } captureModeInfo_;
443     ExtraData extraData_;
444     int32_t mouseDownEventId_ { -1 };
445     bool haveSetObserver_ { false };
446     bool dragFlag_ { false };
447     bool isDragBorder_ { false };
448     bool pointerDrawFlag_ { false };
449     DisplayMode displayMode_ { DisplayMode::UNKNOWN };
450     struct AntiMisTake {
451         std::string switchName;
452         bool isOpen { false };
453     } antiMistake_;
454     bool isOpenAntiMisTakeObserver_ { false };
455 #ifndef OHOS_BUILD_ENABLE_WATCH
456     std::shared_ptr<KnuckleDrawingManager> knuckleDrawMgr_ { nullptr };
457 #endif // OHOS_BUILD_ENABLE_WATCH
458     bool mouseFlag_ {false};
459     std::map<int32_t, std::vector<int32_t>> targetTouchWinIds_;
460     std::map<int32_t, std::vector<int32_t>> targetMouseWinIds_;
461     int32_t pointerActionFlag_ { -1 };
462     int32_t currentUserId_ { -1 };
463 #ifndef OHOS_BUILD_ENABLE_WATCH
464     std::shared_ptr<KnuckleDynamicDrawingManager> knuckleDynamicDrawingManager_ { nullptr };
465 #endif // OHOS_BUILD_ENABLE_WATCH
466     std::shared_ptr<PointerEvent> lastPointerEventforWindowChange_ { nullptr };
467     bool cancelTouchStatus_ { false };
468     std::pair<int32_t, Direction> lastDirection_ { -1, static_cast<Direction>(-1) };
469     std::map<int32_t, WindowInfo> lastMatchedWindow_;
470     std::vector<SwitchFocusKey> vecWhiteList_;
471     bool isParseConfig_ { false };
472     int32_t windowStateNotifyPid_ { -1 };
473     std::map<int32_t, std::unique_ptr<Media::PixelMap>> transparentWins_;
474 #ifdef OHOS_BUILD_ENABLE_TOUCH
475     std::shared_ptr<PointerEvent> lastPointerEventforGesture_ { nullptr };
476 #endif // OHOS_BUILD_ENABLE_TOUCH
477     static std::unordered_map<int32_t, int32_t> convertToolTypeMap_;
478     bool IsFoldable_ { false };
479     int32_t timerId_ { -1 };
480     int32_t lastDpi_ { 0 };
481     std::shared_ptr<PointerEvent> GetlastPointerEvent();
482     std::mutex mtx_;
483 };
484 } // namespace MMI
485 } // namespace OHOS
486 #endif // INPUT_WINDOWS_MANAGER_H
487