• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 I_INPUT_WINDOWS_MANAGER_H
17 #define I_INPUT_WINDOWS_MANAGER_H
18 
19 #include <memory>
20 #include <mutex>
21 
22 #include "libinput.h"
23 #include "extra_data.h"
24 #ifdef OHOS_BUILD_ENABLE_ANCO
25 #include "ianco_channel.h"
26 #endif
27 #include "key_event.h"
28 #include "pointer_event.h"
29 #include "pointer_style.h"
30 #include "struct_multimodal.h"
31 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
32 #include "touch_gesture_manager.h"
33 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
34 #include "uds_server.h"
35 #include "old_display_info.h"
36 #include "shift_info.h"
37 
38 namespace OHOS {
39 namespace MMI {
40 struct MouseLocation {
41     int32_t displayId { -1 };
42     int32_t physicalX { 0 };
43     int32_t physicalY { 0 };
44 };
45 
46 struct Coordinate2D {
47     double x;
48     double y;
49 };
50 
51 struct CursorPosition {
52     int32_t displayId { -1 };
53     Direction direction { Direction::DIRECTION0 };
54     Direction displayDirection { Direction::DIRECTION0 };
55     Coordinate2D cursorPos {};
56 };
57 
58 struct TargetInfo {
59     SecureFlag privacyMode { SecureFlag::DEFAULT_MODE };
60     int32_t id { -1 };
61     int32_t agentWindowId { -1 };
62 };
63 
64 class IInputWindowsManager {
65 public:
66     IInputWindowsManager() = default;
67     virtual ~IInputWindowsManager() = default;
68 
69     virtual void Init(UDSServer& udsServer) = 0;
70     virtual bool JudgeCameraInFore() = 0;
71 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
72     virtual int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent) = 0;
73     virtual int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent, int32_t windowId) = 0;
74     virtual bool AdjustFingerFlag(std::shared_ptr<PointerEvent> pointerEvent) = 0;
75     virtual void PrintEnterEventInfo(std::shared_ptr<PointerEvent> pointerEvent) = 0;
76 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
77     virtual bool IsFocusedSession(int32_t session) const = 0;
78     virtual void UpdateDisplayInfo(OLD::DisplayGroupInfo &displayGroupInfo) = 0;
79     virtual void UpdateDisplayInfoExtIfNeed(OLD::DisplayGroupInfo &displayGroupInfo, bool needUpdateDisplayExt) = 0;
80     virtual void ProcessInjectEventGlobalXY(std::shared_ptr<PointerEvent> pointerEvent, int32_t useCoordinate) = 0;
81     virtual void UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo) = 0;
82     virtual int32_t ClearWindowPointerStyle(int32_t pid, int32_t windowId) = 0;
83     virtual void Dump(int32_t fd, const std::vector<std::string> &args) = 0;
84     virtual int32_t GetWindowPid(int32_t windowId) const = 0;
85     virtual int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) = 0;
86     virtual bool GetMouseIsCaptureMode() const = 0;
87     virtual int32_t GetDisplayBindInfo(DisplayBindInfos &infos) = 0;
88     virtual int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) = 0;
89     virtual int32_t AppendExtraData(const ExtraData& extraData) = 0;
90     virtual bool IsWindowVisible(int32_t pid) = 0;
91     virtual ExtraData GetExtraData() const = 0;
92     virtual const std::vector<WindowInfo> GetWindowGroupInfoByDisplayIdCopy(int32_t displayId) const = 0;
93     virtual std::pair<double, double> TransformWindowXY(const WindowInfo &, double, double) const = 0;
94     virtual void ClearTargetWindowId(int32_t pointerId) = 0;
95     virtual std::pair<double, double> TransformDisplayXY(const OLD::DisplayInfo &info,
96         double logicX, double logicY) const = 0;
97     virtual int32_t SetPixelMapData(int32_t infoId, void *pixelMap) = 0;
98     virtual int32_t GetCurrentUserId() = 0;
99     virtual void SetFoldState () = 0;
100     virtual bool CheckAppFocused(int32_t pid) = 0;
101     virtual bool GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent) = 0;
102 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
103     virtual std::vector<std::pair<int32_t, TargetInfo>> UpdateTarget(std::shared_ptr<KeyEvent> keyEvent) = 0;
104     virtual void HandleKeyEventWindowId(std::shared_ptr<KeyEvent> keyEvent) = 0;
105 #endif // OHOS_BUILD_ENABLE_KEYBOARD
106 
107     virtual int32_t CheckWindowIdPermissionByPid(int32_t windowId, int32_t pid) = 0;
108     virtual int32_t ClearMouseHideFlag(int32_t eventId) = 0;
109 
110 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
111     virtual MouseLocation GetMouseInfo() = 0;
112     virtual CursorPosition GetCursorPos() = 0;
113     virtual CursorPosition ResetCursorPos() = 0;
114     virtual void UpdateAndAdjustMouseLocation(int32_t& displayId, double& x, double& y, bool isRealData = true) = 0;
115 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
116 #ifdef OHOS_BUILD_ENABLE_POINTER
117     virtual int32_t SetHoverScrollState(bool state) = 0;
118     virtual int32_t GetFocusWindowId(int32_t groupId = DEFAULT_GROUP_ID) const = 0;
119     virtual bool GetHoverScrollState() const = 0;
120 #endif // OHOS_BUILD_ENABLE_POINTER
121 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
122     virtual int32_t SetPointerStyle(int32_t pid, int32_t windowId,
123         PointerStyle pointerStyle, bool isUiExtension = false) = 0;
124     virtual int32_t GetPointerStyle(int32_t pid, int32_t windowId,
125         PointerStyle &pointerStyle, bool isUiExtension = false) const = 0;
126     virtual void DispatchPointer(int32_t pointerAction, int32_t windowId = -1) = 0;
127     virtual void SendPointerEvent(int32_t pointerAction) = 0;
128     virtual bool IsMouseSimulate() = 0;
129     virtual bool HasMouseHideFlag() = 0;
130     virtual void UpdatePointerDrawingManagerWindowInfo() = 0;
131 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
132 #ifdef OHOS_BUILD_ENABLE_POINTER
133 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
134     virtual bool IsNeedRefreshLayer(int32_t windowId) = 0;
135 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
136 #endif //OHOS_BUILD_ENABLE_POINTER
137 
138 #ifdef OHOS_BUILD_ENABLE_TOUCH
139     virtual bool TouchPointToDisplayPoint(int32_t deviceId, struct libinput_event_touch* touch,
140         EventTouch& touchInfo, int32_t& targetDisplayId, bool isNeedClear = false) = 0;
141     virtual bool CalculateTipPoint(struct libinput_event_tablet_tool* tip,
142         int32_t& targetDisplayId, PhysicalCoordinate& coord) = 0;
143     virtual const OLD::DisplayInfo *GetDefaultDisplayInfo() const = 0;
144     virtual void ReverseXY(int32_t &x, int32_t &y) = 0;
145     virtual void FoldScreenRotation(std::shared_ptr<PointerEvent> pointerEvent) = 0;
146     virtual void SendCancelEventWhenLock() = 0;
147 #endif // OHOS_BUILD_ENABLE_TOUCH
148 
149 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
150     virtual void DrawTouchGraphic(std::shared_ptr<PointerEvent> pointerEvent) = 0;
151     virtual int32_t UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent) = 0;
152     virtual const OLD::DisplayInfo *GetPhysicalDisplay(int32_t id) const = 0;
153 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
154 
155 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
156     virtual void UpdatePointerChangeAreas() = 0;
157     virtual bool SelectPointerChangeArea(int32_t windowId, int32_t logicalX, int32_t logicalY);
158 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
159     virtual std::optional<WindowInfo> GetWindowAndDisplayInfo(int32_t windowId, int32_t displayId) = 0;
160     virtual void GetTargetWindowIds(int32_t pointerItemId, int32_t sourceType, std::vector<int32_t> &windowIds) = 0;
161     virtual int32_t SetCurrentUser(int32_t userId) = 0;
162     virtual DisplayMode GetDisplayMode() const = 0;
163     virtual void SetWindowStateNotifyPid(int32_t pid) = 0;
164     virtual int32_t GetWindowStateNotifyPid() = 0;
165     virtual int32_t GetPidByWindowId(int32_t pid) = 0;
166 #ifdef OHOS_BUILD_ENABLE_ANCO
167     virtual void InitializeAnco() = 0;
168     virtual int32_t AncoAddChannel(sptr<IAncoChannel> channel) = 0;
169     virtual int32_t AncoRemoveChannel(sptr<IAncoChannel> channel) = 0;
170     virtual void CleanShellWindowIds() = 0;
171     virtual bool IsKnuckleOnAncoWindow(std::shared_ptr<PointerEvent> pointerEvent) = 0;
172     virtual int32_t SyncKnuckleStatus(bool isKnuckleEnable) = 0;
173 #endif // OHOS_BUILD_ENABLE_ANCO
174 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
175     virtual int32_t ShiftAppPointerEvent(const ShiftWindowParam &param, bool autoGenDown) = 0;
176     virtual Direction GetDisplayDirection(const OLD::DisplayInfo *displayInfo) = 0;
177 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
178 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
179     virtual void AttachTouchGestureMgr(std::shared_ptr<TouchGestureManager> touchGestureMgr) = 0;
180     virtual void CancelAllTouches(std::shared_ptr<PointerEvent> event, bool isDisplayChanged = false) = 0;
181 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
182 #ifdef OHOS_BUILD_ENABLE_TOUCH
183     virtual std::shared_ptr<PointerEvent> GetLastPointerEventForGesture() = 0;
184 #endif // OHOS_BUILD_ENABLE_TOUCH
185     virtual std::pair<int32_t, int32_t> CalcDrawCoordinate(const OLD::DisplayInfo& displayInfo,
186         PointerEvent::PointerItem pointerItem) = 0;
187 #ifdef OHOS_BUILD_ENABLE_POINTER
188     virtual bool IsMouseDragging() const = 0;
189     virtual void EnsureMouseEventCycle(std::shared_ptr<PointerEvent> event) = 0;
190     virtual void CleanMouseEventCycle(std::shared_ptr<PointerEvent> event) = 0;
191 #endif // OHOS_BUILD_ENABLE_POINTER
192 
193     static std::shared_ptr<IInputWindowsManager> GetInstance();
194     static void DestroyInstance();
195     virtual bool GetHardCursorEnabled() = 0;
196 
197 private:
198     static std::mutex mutex_;
199     static std::shared_ptr<IInputWindowsManager> instance_;
200 };
201 
202 #define WIN_MGR ::OHOS::MMI::IInputWindowsManager::GetInstance()
203 } // namespace MMI
204 } // namespace OHOS
205 #endif // I_INPUT_WINDOWS_MANAGER_H