1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#ifndef INPUT_WINDOWS_MANAGER_H
17c29fa5a6Sopenharmony_ci#define INPUT_WINDOWS_MANAGER_H
18c29fa5a6Sopenharmony_ci
19c29fa5a6Sopenharmony_ci#include <vector>
20c29fa5a6Sopenharmony_ci
21c29fa5a6Sopenharmony_ci#include "nocopyable.h"
22c29fa5a6Sopenharmony_ci#include "pixel_map.h"
23c29fa5a6Sopenharmony_ci#include "window_manager_lite.h"
24c29fa5a6Sopenharmony_ci
25c29fa5a6Sopenharmony_ci#include "i_input_windows_manager.h"
26c29fa5a6Sopenharmony_ci#include "input_display_bind_helper.h"
27c29fa5a6Sopenharmony_ci#include "input_event_data_transformation.h"
28c29fa5a6Sopenharmony_ci#include "knuckle_drawing_manager.h"
29c29fa5a6Sopenharmony_ci#include "knuckle_dynamic_drawing_manager.h"
30c29fa5a6Sopenharmony_ci
31c29fa5a6Sopenharmony_cinamespace OHOS {
32c29fa5a6Sopenharmony_cinamespace MMI {
33c29fa5a6Sopenharmony_cistruct WindowInfoEX {
34c29fa5a6Sopenharmony_ci    WindowInfo window;
35c29fa5a6Sopenharmony_ci    bool flag { false };
36c29fa5a6Sopenharmony_ci};
37c29fa5a6Sopenharmony_ci
38c29fa5a6Sopenharmony_cistruct SwitchFocusKey {
39c29fa5a6Sopenharmony_ci    int32_t keyCode { -1 };
40c29fa5a6Sopenharmony_ci    int32_t pressedKey { -1 };
41c29fa5a6Sopenharmony_ci};
42c29fa5a6Sopenharmony_ci
43c29fa5a6Sopenharmony_ciclass InputWindowsManager final : public IInputWindowsManager {
44c29fa5a6Sopenharmony_cipublic:
45c29fa5a6Sopenharmony_ci    InputWindowsManager();
46c29fa5a6Sopenharmony_ci    ~InputWindowsManager();
47c29fa5a6Sopenharmony_ci    DISALLOW_COPY_AND_MOVE(InputWindowsManager);
48c29fa5a6Sopenharmony_ci
49c29fa5a6Sopenharmony_ci    void Init(UDSServer& udsServer);
50c29fa5a6Sopenharmony_ci    void SetMouseFlag(bool state);
51c29fa5a6Sopenharmony_ci    bool GetMouseFlag();
52c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER
53c29fa5a6Sopenharmony_ci    void JudgMouseIsDownOrUp(bool dragState);
54c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER
55c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
56c29fa5a6Sopenharmony_ci    int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent);
57c29fa5a6Sopenharmony_ci    int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent, int32_t windowId);
58c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
59c29fa5a6Sopenharmony_ci    bool HandleWindowInputType(const WindowInfo &window, std::shared_ptr<PointerEvent> pointerEvent);
60c29fa5a6Sopenharmony_ci    void UpdateCaptureMode(const DisplayGroupInfo &displayGroupInfo);
61c29fa5a6Sopenharmony_ci    void UpdateDisplayInfo(DisplayGroupInfo &displayGroupInfo);
62c29fa5a6Sopenharmony_ci    void UpdateDisplayInfoExtIfNeed(DisplayGroupInfo &displayGroupInfo, bool needUpdateDisplayExt);
63c29fa5a6Sopenharmony_ci    void UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo);
64c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
65c29fa5a6Sopenharmony_ci    void SetWindowPointerStyle(WindowArea area, int32_t pid, int32_t windowId);
66c29fa5a6Sopenharmony_ci    void UpdateWindowPointerVisible(int32_t pid);
67c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
68c29fa5a6Sopenharmony_ci    int32_t ClearWindowPointerStyle(int32_t pid, int32_t windowId);
69c29fa5a6Sopenharmony_ci    void Dump(int32_t fd, const std::vector<std::string> &args);
70c29fa5a6Sopenharmony_ci    void DumpDisplayInfo(int32_t fd);
71c29fa5a6Sopenharmony_ci    int32_t GetWindowPid(int32_t windowId, const std::vector<WindowInfo> &windowsInfo) const;
72c29fa5a6Sopenharmony_ci    int32_t GetWindowPid(int32_t windowId) const;
73c29fa5a6Sopenharmony_ci    int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode);
74c29fa5a6Sopenharmony_ci    bool GetMouseIsCaptureMode() const;
75c29fa5a6Sopenharmony_ci    void DeviceStatusChanged(int32_t deviceId, const std::string &sysUid, const std::string devStatus);
76c29fa5a6Sopenharmony_ci    int32_t GetDisplayBindInfo(DisplayBindInfos &infos);
77c29fa5a6Sopenharmony_ci    int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg);
78c29fa5a6Sopenharmony_ci    int32_t AppendExtraData(const ExtraData& extraData);
79c29fa5a6Sopenharmony_ci    bool IsWindowVisible(int32_t pid);
80c29fa5a6Sopenharmony_ci    void ClearExtraData();
81c29fa5a6Sopenharmony_ci    ExtraData GetExtraData() const;
82c29fa5a6Sopenharmony_ci    const std::vector<WindowInfo>& GetWindowGroupInfoByDisplayId(int32_t displayId) const;
83c29fa5a6Sopenharmony_ci    std::pair<double, double> TransformWindowXY(const WindowInfo &window, double logicX, double logicY) const;
84c29fa5a6Sopenharmony_ci    std::pair<double, double> TransformDisplayXY(const DisplayInfo &info, double logicX, double logicY) const;
85c29fa5a6Sopenharmony_ci    int32_t GetCurrentUserId();
86c29fa5a6Sopenharmony_ci    bool GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent);
87c29fa5a6Sopenharmony_ci    void SetFoldState ();
88c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_KEYBOARD
89c29fa5a6Sopenharmony_ci    std::vector<std::pair<int32_t, TargetInfo>> GetPidAndUpdateTarget(std::shared_ptr<KeyEvent> keyEvent);
90c29fa5a6Sopenharmony_ci    void ReissueEvent(std::shared_ptr<KeyEvent> keyEvent, int32_t focusWindowId);
91c29fa5a6Sopenharmony_ci    std::vector<std::pair<int32_t, TargetInfo>> UpdateTarget(std::shared_ptr<KeyEvent> keyEvent);
92c29fa5a6Sopenharmony_ci    bool IsKeyPressed(int32_t pressedKey, std::vector<KeyEvent::KeyItem> &keyItems);
93c29fa5a6Sopenharmony_ci    bool IsOnTheWhitelist(std::shared_ptr<KeyEvent> keyEvent);
94c29fa5a6Sopenharmony_ci    void HandleKeyEventWindowId(std::shared_ptr<KeyEvent> keyEvent);
95c29fa5a6Sopenharmony_ci    int32_t focusWindowId_ { -1 };
96c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_KEYBOARD
97c29fa5a6Sopenharmony_ci    int32_t CheckWindowIdPermissionByPid(int32_t windowId, int32_t pid);
98c29fa5a6Sopenharmony_ci
99c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
100c29fa5a6Sopenharmony_ci    MouseLocation GetMouseInfo();
101c29fa5a6Sopenharmony_ci    CursorPosition GetCursorPos();
102c29fa5a6Sopenharmony_ci    CursorPosition ResetCursorPos();
103c29fa5a6Sopenharmony_ci    void SetGlobalDefaultPointerStyle();
104c29fa5a6Sopenharmony_ci    void UpdateAndAdjustMouseLocation(int32_t& displayId, double& x, double& y, bool isRealData = true);
105c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
106c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER
107c29fa5a6Sopenharmony_ci    const DisplayGroupInfo& GetDisplayGroupInfo();
108c29fa5a6Sopenharmony_ci    int32_t SetHoverScrollState(bool state);
109c29fa5a6Sopenharmony_ci    bool GetHoverScrollState() const;
110c29fa5a6Sopenharmony_ci    bool SelectPointerChangeArea(int32_t windowId, int32_t logicalX, int32_t logicalY);
111c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER
112c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
113c29fa5a6Sopenharmony_ci    int32_t SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle, bool isUiExtension = false);
114c29fa5a6Sopenharmony_ci    int32_t GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle,
115c29fa5a6Sopenharmony_ci        bool isUiExtension = false) const;
116c29fa5a6Sopenharmony_ci    void SetUiExtensionInfo(bool isUiExtension, int32_t uiExtensionPid, int32_t uiExtensionWindoId);
117c29fa5a6Sopenharmony_ci    void DispatchPointer(int32_t pointerAction, int32_t windowId = -1);
118c29fa5a6Sopenharmony_ci    void SendPointerEvent(int32_t pointerAction);
119c29fa5a6Sopenharmony_ci    bool IsMouseSimulate() const;
120c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
121c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER
122c29fa5a6Sopenharmony_ci    PointerStyle GetLastPointerStyle() const;
123c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
124c29fa5a6Sopenharmony_ci    bool IsNeedRefreshLayer(int32_t windowId);
125c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
126c29fa5a6Sopenharmony_ci#endif //OHOS_BUILD_ENABLE_POINTER
127c29fa5a6Sopenharmony_ci
128c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_TOUCH
129c29fa5a6Sopenharmony_ci    void AdjustDisplayCoordinate(const DisplayInfo& displayInfo, double& physicalX, double& physicalY) const;
130c29fa5a6Sopenharmony_ci    bool TouchPointToDisplayPoint(int32_t deviceId, struct libinput_event_touch* touch,
131c29fa5a6Sopenharmony_ci        EventTouch& touchInfo, int32_t& targetDisplayId);
132c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_TOUCH
133c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
134c29fa5a6Sopenharmony_ci    void ReverseRotateScreen(const DisplayInfo& info, const double x, const double y, Coordinate2D& cursorPos) const;
135c29fa5a6Sopenharmony_ci    void RotateScreen(const DisplayInfo& info, PhysicalCoordinate& coord) const;
136c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
137c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_TOUCH
138c29fa5a6Sopenharmony_ci    bool TransformTipPoint(struct libinput_event_tablet_tool* tip, PhysicalCoordinate& coord, int32_t& displayId) const;
139c29fa5a6Sopenharmony_ci    bool CalculateTipPoint(struct libinput_event_tablet_tool* tip,
140c29fa5a6Sopenharmony_ci        int32_t& targetDisplayId, PhysicalCoordinate& coord) const;
141c29fa5a6Sopenharmony_ci    const DisplayInfo *GetDefaultDisplayInfo() const;
142c29fa5a6Sopenharmony_ci    void ReverseXY(int32_t &x, int32_t &y);
143c29fa5a6Sopenharmony_ci    void SendCancelEventWhenLock();
144c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_TOUCH
145c29fa5a6Sopenharmony_ci
146c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_ANCO
147c29fa5a6Sopenharmony_ci    void UpdateWindowInfoExt(const WindowGroupInfo &windowGroupInfo, const DisplayGroupInfo &displayGroupInfo);
148c29fa5a6Sopenharmony_ci    void UpdateShellWindow(const WindowInfo &window);
149c29fa5a6Sopenharmony_ci    void UpdateDisplayInfoExt(const DisplayGroupInfo &displayGroupInfo);
150c29fa5a6Sopenharmony_ci    bool IsInAncoWindow(const WindowInfo &window, int32_t x, int32_t y) const;
151c29fa5a6Sopenharmony_ci    bool IsAncoWindow(const WindowInfo &window) const;
152c29fa5a6Sopenharmony_ci    bool IsAncoWindowFocus(const WindowInfo &window) const;
153c29fa5a6Sopenharmony_ci    void SimulatePointerExt(std::shared_ptr<PointerEvent> pointerEvent);
154c29fa5a6Sopenharmony_ci    void DumpAncoWindows(std::string& out) const;
155c29fa5a6Sopenharmony_ci    void CleanShellWindowIds();
156c29fa5a6Sopenharmony_ci    bool IsKnuckleOnAncoWindow(std::shared_ptr<PointerEvent> pointerEvent);
157c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_ANCO
158c29fa5a6Sopenharmony_ci
159c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
160c29fa5a6Sopenharmony_ci    bool UpdateDisplayId(int32_t& displayId);
161c29fa5a6Sopenharmony_ci    void DrawTouchGraphic(std::shared_ptr<PointerEvent> pointerEvent);
162c29fa5a6Sopenharmony_ci    int32_t UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent);
163c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
164c29fa5a6Sopenharmony_ci    const DisplayInfo* GetPhysicalDisplay(int32_t id) const;
165c29fa5a6Sopenharmony_ci    const DisplayInfo* GetPhysicalDisplay(int32_t id, const DisplayGroupInfo &displayGroupInfo) const;
166c29fa5a6Sopenharmony_ci
167c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
168c29fa5a6Sopenharmony_ci    void UpdatePointerChangeAreas();
169c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
170c29fa5a6Sopenharmony_ci    std::optional<WindowInfo> GetWindowAndDisplayInfo(int32_t windowId, int32_t displayId);
171c29fa5a6Sopenharmony_ci    void GetTargetWindowIds(int32_t pointerItemId, int32_t sourceType, std::vector<int32_t> &windowIds);
172c29fa5a6Sopenharmony_ci    void AddTargetWindowIds(int32_t pointerItemId, int32_t sourceType, int32_t windowId);
173c29fa5a6Sopenharmony_ci    void ClearTargetWindowId(int32_t pointerId);
174c29fa5a6Sopenharmony_ci    bool IsTransparentWin(std::unique_ptr<Media::PixelMap> &pixelMap, int32_t logicalX, int32_t logicalY);
175c29fa5a6Sopenharmony_ci    int32_t SetCurrentUser(int32_t userId);
176c29fa5a6Sopenharmony_ci    DisplayMode GetDisplayMode() const;
177c29fa5a6Sopenharmony_ci    void SetWindowStateNotifyPid(int32_t pid);
178c29fa5a6Sopenharmony_ci    int32_t GetWindowStateNotifyPid();
179c29fa5a6Sopenharmony_ci    int32_t GetPidByWindowId(int32_t pid);
180c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_ANCO
181c29fa5a6Sopenharmony_ci    int32_t AncoAddChannel(sptr<IAncoChannel> channel);
182c29fa5a6Sopenharmony_ci    int32_t AncoRemoveChannel(sptr<IAncoChannel> channel);
183c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_ANCO
184c29fa5a6Sopenharmony_ci
185c29fa5a6Sopenharmony_ci    int32_t SetPixelMapData(int32_t infoId, void *pixelMap);
186c29fa5a6Sopenharmony_ci    void CleanInvalidPiexMap();
187c29fa5a6Sopenharmony_ci    void HandleWindowPositionChange();
188c29fa5a6Sopenharmony_ci
189c29fa5a6Sopenharmony_ciprivate:
190c29fa5a6Sopenharmony_ci    bool IgnoreTouchEvent(std::shared_ptr<PointerEvent> pointerEvent);
191c29fa5a6Sopenharmony_ci    void ReissueCancelTouchEvent(std::shared_ptr<PointerEvent> pointerEvent);
192c29fa5a6Sopenharmony_ci    int32_t GetDisplayId(std::shared_ptr<InputEvent> inputEvent) const;
193c29fa5a6Sopenharmony_ci    void PrintWindowInfo(const std::vector<WindowInfo> &windowsInfo);
194c29fa5a6Sopenharmony_ci    void PrintDisplayInfo();
195c29fa5a6Sopenharmony_ci    void PrintWindowGroupInfo(const WindowGroupInfo &windowGroupInfo);
196c29fa5a6Sopenharmony_ci    void CheckFocusWindowChange(const DisplayGroupInfo &displayGroupInfo);
197c29fa5a6Sopenharmony_ci    void CheckZorderWindowChange(const std::vector<WindowInfo> &oldWindowsInfo,
198c29fa5a6Sopenharmony_ci        const std::vector<WindowInfo> &newWindowsInfo);
199c29fa5a6Sopenharmony_ci    void UpdateDisplayIdAndName();
200c29fa5a6Sopenharmony_ci    void UpdatePointerAction(std::shared_ptr<PointerEvent> pointerEvent);
201c29fa5a6Sopenharmony_ci    bool IsNeedDrawPointer(PointerEvent::PointerItem &pointerItem) const;
202c29fa5a6Sopenharmony_ci    void UpdateDisplayInfoByIncrementalInfo(const WindowInfo &window, DisplayGroupInfo &displayGroupInfo);
203c29fa5a6Sopenharmony_ci    void UpdateWindowsInfoPerDisplay(const DisplayGroupInfo &displayGroupInfo);
204c29fa5a6Sopenharmony_ci    std::pair<int32_t, int32_t> TransformSampleWindowXY(int32_t logicX, int32_t logicY) const;
205c29fa5a6Sopenharmony_ci    bool IsValidZorderWindow(const WindowInfo &window, const std::shared_ptr<PointerEvent>& pointerEvent);
206c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
207c29fa5a6Sopenharmony_ci    void UpdateTopBottomArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas,
208c29fa5a6Sopenharmony_ci        std::vector<Rect> &windowHotAreas);
209c29fa5a6Sopenharmony_ci    void UpdateLeftRightArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas,
210c29fa5a6Sopenharmony_ci        std::vector<Rect> &windowHotAreas);
211c29fa5a6Sopenharmony_ci    void UpdateInnerAngleArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas,
212c29fa5a6Sopenharmony_ci        std::vector<Rect> &windowHotAreas);
213c29fa5a6Sopenharmony_ci    void CoordinateCorrection(int32_t width, int32_t height, int32_t &integerX, int32_t &integerY);
214c29fa5a6Sopenharmony_ci    void GetWidthAndHeight(const DisplayInfo* displayInfo, int32_t &width, int32_t &height);
215c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
216c29fa5a6Sopenharmony_ci    void SetPrivacyModeFlag(SecureFlag privacyMode, std::shared_ptr<InputEvent> event);
217c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
218c29fa5a6Sopenharmony_ci    void FoldScreenRotation(std::shared_ptr<PointerEvent> pointerEvent);
219c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
220c29fa5a6Sopenharmony_ci    void PrintChangedWindowByEvent(int32_t eventType, const WindowInfo &newWindowInfo);
221c29fa5a6Sopenharmony_ci    void PrintChangedWindowBySync(const DisplayGroupInfo &newDisplayInfo);
222c29fa5a6Sopenharmony_ci    bool IsMouseDrawing(int32_t currentAction);
223c29fa5a6Sopenharmony_ci    bool ParseConfig();
224c29fa5a6Sopenharmony_ci    bool ParseJson(const std::string &configFile);
225c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
226c29fa5a6Sopenharmony_ci    void SendUIExtentionPointerEvent(int32_t logicalX, int32_t logicalY,
227c29fa5a6Sopenharmony_ci        const WindowInfo& windowInfo, std::shared_ptr<PointerEvent> pointerEvent);
228c29fa5a6Sopenharmony_ci    void DispatchUIExtentionPointerEvent(int32_t logicalX, int32_t logicalY,
229c29fa5a6Sopenharmony_ci        std::shared_ptr<PointerEvent> pointerEvent);
230c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
231c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER
232c29fa5a6Sopenharmony_ci    void GetPointerStyleByArea(WindowArea area, int32_t pid, int32_t winId, PointerStyle& pointerStyle);
233c29fa5a6Sopenharmony_ci    int32_t UpdateMouseTarget(std::shared_ptr<PointerEvent> pointerEvent);
234c29fa5a6Sopenharmony_ci    void UpdatePointerEvent(int32_t logicalX, int32_t logicalY,
235c29fa5a6Sopenharmony_ci        const std::shared_ptr<PointerEvent>& pointerEvent, const WindowInfo& touchWindow);
236c29fa5a6Sopenharmony_ci    void NotifyPointerToWindow();
237c29fa5a6Sopenharmony_ci    void OnSessionLost(SessionPtr session);
238c29fa5a6Sopenharmony_ci    void InitPointerStyle();
239c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER
240c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
241c29fa5a6Sopenharmony_ci    int32_t UpdatePoinerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle);
242c29fa5a6Sopenharmony_ci    int32_t UpdateSceneBoardPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle,
243c29fa5a6Sopenharmony_ci        bool isUiExtension = false);
244c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
245c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER
246c29fa5a6Sopenharmony_ci    int32_t UpdateTouchPadTarget(std::shared_ptr<PointerEvent> pointerEvent);
247c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER
248c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
249c29fa5a6Sopenharmony_ci    std::optional<WindowInfo> SelectWindowInfo(int32_t logicalX, int32_t logicalY,
250c29fa5a6Sopenharmony_ci        const std::shared_ptr<PointerEvent>& pointerEvent);
251c29fa5a6Sopenharmony_ci    void CheckUIExtentionWindowPointerHotArea(int32_t logicalX, int32_t logicalY,
252c29fa5a6Sopenharmony_ci        const std::vector<WindowInfo>& windowInfos, int32_t& windowId);
253c29fa5a6Sopenharmony_ci    std::optional<WindowInfo> GetWindowInfo(int32_t logicalX, int32_t logicalY);
254c29fa5a6Sopenharmony_ci    bool IsInsideDisplay(const DisplayInfo& displayInfo, int32_t physicalX, int32_t physicalY);
255c29fa5a6Sopenharmony_ci    void FindPhysicalDisplay(const DisplayInfo& displayInfo, int32_t& physicalX,
256c29fa5a6Sopenharmony_ci        int32_t& physicalY, int32_t& displayId);
257c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
258c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
259c29fa5a6Sopenharmony_ci    void InitMouseDownInfo();
260c29fa5a6Sopenharmony_ci    bool SelectPointerChangeArea(const WindowInfo &windowInfo, PointerStyle &pointerStyle,
261c29fa5a6Sopenharmony_ci        int32_t logicalX, int32_t logicalY);
262c29fa5a6Sopenharmony_ci    void UpdatePointerChangeAreas(const DisplayGroupInfo &displayGroupInfo);
263c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
264c29fa5a6Sopenharmony_ci    void AdjustDisplayRotation();
265c29fa5a6Sopenharmony_ci    void SetPointerEvent(int32_t pointerAction, std::shared_ptr<PointerEvent> pointerEvent);
266c29fa5a6Sopenharmony_ci    void DispatchPointerCancel(int32_t displayId);
267c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
268c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
269c29fa5a6Sopenharmony_ci
270c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
271c29fa5a6Sopenharmony_civoid PointerDrawingManagerOnDisplayInfo(const DisplayGroupInfo &displayGroupInfo, bool isDisplayRemoved = false);
272c29fa5a6Sopenharmony_civoid DrawPointer(bool isDisplayRemoved);
273c29fa5a6Sopenharmony_cibool NeedUpdatePointDrawFlag(const std::vector<WindowInfo> &windows);
274c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
275c29fa5a6Sopenharmony_ci
276c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_TOUCH
277c29fa5a6Sopenharmony_ci    bool SkipAnnotationWindow(uint32_t flag, int32_t toolType);
278c29fa5a6Sopenharmony_ci    bool SkipNavigationWindow(WindowInputType windowType, int32_t toolType);
279c29fa5a6Sopenharmony_ci    void HandleGestureInjection(bool gestureInject);
280c29fa5a6Sopenharmony_ci    int32_t UpdateTouchScreenTarget(std::shared_ptr<PointerEvent> pointerEvent);
281c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_TOUCH
282c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
283c29fa5a6Sopenharmony_ci    bool IsValidNavigationWindow(const WindowInfo& touchWindow, double physicalX, double physicalY);
284c29fa5a6Sopenharmony_ci    bool IsNavigationWindowInjectEvent(std::shared_ptr<PointerEvent> pointerEvent);
285c29fa5a6Sopenharmony_ci    void UpdateTransformDisplayXY(std::shared_ptr<PointerEvent> pointerEvent,
286c29fa5a6Sopenharmony_ci        const std::vector<WindowInfo>& windowsInfo, const DisplayInfo& displayInfo);
287c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
288c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_TOUCH
289c29fa5a6Sopenharmony_ci    void PullEnterLeaveEvent(int32_t logicalX, int32_t logicalY,
290c29fa5a6Sopenharmony_ci        const std::shared_ptr<PointerEvent> pointerEvent, const WindowInfo* touchWindow);
291c29fa5a6Sopenharmony_ci    void DispatchTouch(int32_t pointerAction);
292c29fa5a6Sopenharmony_ci    const DisplayInfo* FindPhysicalDisplayInfo(const std::string& uniq) const;
293c29fa5a6Sopenharmony_ci    void GetPhysicalDisplayCoord(struct libinput_event_touch* touch,
294c29fa5a6Sopenharmony_ci        const DisplayInfo& info, EventTouch& touchInfo);
295c29fa5a6Sopenharmony_ci    void SetAntiMisTake(bool state);
296c29fa5a6Sopenharmony_ci    void SetAntiMisTakeStatus(bool state);
297c29fa5a6Sopenharmony_ci    void CheckUIExtentionWindowDefaultHotArea(std::pair<int32_t, int32_t> logicalXY, bool isHotArea,
298c29fa5a6Sopenharmony_ci        const std::shared_ptr<PointerEvent> pointerEvent, const std::vector<WindowInfo>& windowInfos,
299c29fa5a6Sopenharmony_ci        const WindowInfo* touchWindow);
300c29fa5a6Sopenharmony_ci    void GetUIExtentionWindowInfo(std::vector<WindowInfo> &uiExtentionWindowInfo, int32_t windowId,
301c29fa5a6Sopenharmony_ci        WindowInfo **touchWindow, bool &isUiExtentionWindow);
302c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_TOUCH
303c29fa5a6Sopenharmony_ci
304c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
305c29fa5a6Sopenharmony_ci    bool IsInHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects, const WindowInfo &window) const;
306c29fa5a6Sopenharmony_ci    bool InWhichHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects, PointerStyle &pointerStyle) const;
307c29fa5a6Sopenharmony_ci    bool InWhichHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects) const;
308c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
309c29fa5a6Sopenharmony_ci    template <class T>
310c29fa5a6Sopenharmony_ci    void CreateAntiMisTakeObserver(T& item);
311c29fa5a6Sopenharmony_ci
312c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_JOYSTICK
313c29fa5a6Sopenharmony_ci    int32_t UpdateJoystickTarget(std::shared_ptr<PointerEvent> pointerEvent);
314c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_JOYSTICK
315c29fa5a6Sopenharmony_ci
316c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_CROWN)
317c29fa5a6Sopenharmony_ci    int32_t UpdateCrownTarget(std::shared_ptr<PointerEvent> pointerEvent);
318c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_CROWN
319c29fa5a6Sopenharmony_ci
320c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
321c29fa5a6Sopenharmony_ci    void UpdateDisplayMode();
322c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
323c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_HARDWARE_CURSOR
324c29fa5a6Sopenharmony_ci    void UpdateKeyEventDisplayId(std::shared_ptr<KeyEvent> keyEvent, int32_t focusWindowId);
325c29fa5a6Sopenharmony_ci    bool OnDisplayRemoved(const DisplayGroupInfo &displayGroupInfo);
326c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_HARDWARE_CURSOR
327c29fa5a6Sopenharmony_ci    WINDOW_UPDATE_ACTION UpdateWindowInfo(DisplayGroupInfo &displayGroupInfo);
328c29fa5a6Sopenharmony_ci    void OnGestureSendEvent(std::shared_ptr<PointerEvent> event);
329c29fa5a6Sopenharmony_ci
330c29fa5a6Sopenharmony_ciprivate:
331c29fa5a6Sopenharmony_ci    UDSServer* udsServer_ { nullptr };
332c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
333c29fa5a6Sopenharmony_ci    bool isUiExtension_ { false };
334c29fa5a6Sopenharmony_ci    int32_t uiExtensionPid_ { -1 };
335c29fa5a6Sopenharmony_ci    int32_t uiExtensionWindowId_ { -1 };
336c29fa5a6Sopenharmony_ci    std::pair<int32_t, int32_t> firstBtnDownWindowInfo_ {-1, -1};
337c29fa5a6Sopenharmony_ci    int32_t lastLogicX_ { -1 };
338c29fa5a6Sopenharmony_ci    int32_t lastLogicY_ { -1 };
339c29fa5a6Sopenharmony_ci    WindowInfo lastWindowInfo_;
340c29fa5a6Sopenharmony_ci    std::shared_ptr<PointerEvent> lastPointerEvent_ { nullptr };
341c29fa5a6Sopenharmony_ci    std::map<int32_t, std::map<int32_t, PointerStyle>> pointerStyle_;
342c29fa5a6Sopenharmony_ci    std::map<int32_t, std::map<int32_t, PointerStyle>> uiExtensionPointerStyle_;
343c29fa5a6Sopenharmony_ci    WindowInfo mouseDownInfo_;
344c29fa5a6Sopenharmony_ci    PointerStyle globalStyle_;
345c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
346c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_TOUCH
347c29fa5a6Sopenharmony_ci    int32_t lastTouchLogicX_ { -1 };
348c29fa5a6Sopenharmony_ci    int32_t lastTouchLogicY_ { -1 };
349c29fa5a6Sopenharmony_ci    WindowInfo lastTouchWindowInfo_;
350c29fa5a6Sopenharmony_ci    std::shared_ptr<PointerEvent> lastTouchEvent_ { nullptr };
351c29fa5a6Sopenharmony_ci    std::shared_ptr<PointerEvent> lastTouchEventOnBackGesture_ { nullptr };
352c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_TOUCH
353c29fa5a6Sopenharmony_ci    DisplayGroupInfo displayGroupInfoTmp_;
354c29fa5a6Sopenharmony_ci    DisplayGroupInfo displayGroupInfo_;
355c29fa5a6Sopenharmony_ci    std::map<int32_t, WindowGroupInfo> windowsPerDisplay_;
356c29fa5a6Sopenharmony_ci    PointerStyle lastPointerStyle_ {.id = -1};
357c29fa5a6Sopenharmony_ci    PointerStyle dragPointerStyle_ {.id = -1};
358c29fa5a6Sopenharmony_ci    MouseLocation mouseLocation_ = { -1, -1 };
359c29fa5a6Sopenharmony_ci    CursorPosition cursorPos_ {};
360c29fa5a6Sopenharmony_ci    std::map<int32_t, WindowInfoEX> touchItemDownInfos_;
361c29fa5a6Sopenharmony_ci    std::map<int32_t, std::vector<Rect>> windowsHotAreas_;
362c29fa5a6Sopenharmony_ci    InputDisplayBindHelper bindInfo_;
363c29fa5a6Sopenharmony_ci    struct CaptureModeInfo {
364c29fa5a6Sopenharmony_ci        int32_t windowId { -1 };
365c29fa5a6Sopenharmony_ci        bool isCaptureMode { false };
366c29fa5a6Sopenharmony_ci    } captureModeInfo_;
367c29fa5a6Sopenharmony_ci    ExtraData extraData_;
368c29fa5a6Sopenharmony_ci    bool haveSetObserver_ { false };
369c29fa5a6Sopenharmony_ci    bool dragFlag_ { false };
370c29fa5a6Sopenharmony_ci    bool isDragBorder_ { false };
371c29fa5a6Sopenharmony_ci    bool pointerDrawFlag_ { false };
372c29fa5a6Sopenharmony_ci    DisplayMode displayMode_ { DisplayMode::UNKNOWN };
373c29fa5a6Sopenharmony_ci    struct AntiMisTake {
374c29fa5a6Sopenharmony_ci        std::string switchName;
375c29fa5a6Sopenharmony_ci        bool isOpen { false };
376c29fa5a6Sopenharmony_ci    } antiMistake_;
377c29fa5a6Sopenharmony_ci    bool isOpenAntiMisTakeObserver_ { false };
378c29fa5a6Sopenharmony_ci    std::shared_ptr<KnuckleDrawingManager> knuckleDrawMgr_ { nullptr };
379c29fa5a6Sopenharmony_ci    bool mouseFlag_ {false};
380c29fa5a6Sopenharmony_ci    std::map<int32_t, std::vector<int32_t>> targetTouchWinIds_;
381c29fa5a6Sopenharmony_ci    std::map<int32_t, std::vector<int32_t>> targetMouseWinIds_;
382c29fa5a6Sopenharmony_ci    int32_t pointerActionFlag_ { -1 };
383c29fa5a6Sopenharmony_ci    int32_t currentUserId_ { -1 };
384c29fa5a6Sopenharmony_ci    std::shared_ptr<KnuckleDynamicDrawingManager> knuckleDynamicDrawingManager_ { nullptr };
385c29fa5a6Sopenharmony_ci    std::shared_ptr<PointerEvent> lastPointerEventforWindowChange_ { nullptr };
386c29fa5a6Sopenharmony_ci    bool cancelTouchStatus_ { false };
387c29fa5a6Sopenharmony_ci    Direction lastDirection_ = static_cast<Direction>(-1);
388c29fa5a6Sopenharmony_ci    std::map<int32_t, WindowInfo> lastMatchedWindow_;
389c29fa5a6Sopenharmony_ci    std::vector<SwitchFocusKey> vecWhiteList_;
390c29fa5a6Sopenharmony_ci    bool isParseConfig_ { false };
391c29fa5a6Sopenharmony_ci    int32_t windowStateNotifyPid_ { -1 };
392c29fa5a6Sopenharmony_ci    std::map<int32_t, std::unique_ptr<Media::PixelMap>> transparentWins_;
393c29fa5a6Sopenharmony_ci    std::shared_ptr<PointerEvent> lastPointerEventforGesture_ { nullptr };
394c29fa5a6Sopenharmony_ci    bool isSendGestureDown_ { false };
395c29fa5a6Sopenharmony_ci    bool IsFoldable_ { false };
396c29fa5a6Sopenharmony_ci    int32_t timerId_ { -1 };
397c29fa5a6Sopenharmony_ci};
398c29fa5a6Sopenharmony_ci} // namespace MMI
399c29fa5a6Sopenharmony_ci} // namespace OHOS
400c29fa5a6Sopenharmony_ci#endif // INPUT_WINDOWS_MANAGER_H
401