• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 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 "i_anco_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 #include "uds_server.h"
32 #include "window_info.h"
33 #include "shift_info.h"
34 
35 namespace OHOS {
36 namespace MMI {
37 struct MouseLocation {
38     int32_t displayId { -1 };
39     int32_t physicalX { 0 };
40     int32_t physicalY { 0 };
41 };
42 
43 struct Coordinate2D {
44     double x;
45     double y;
46 };
47 
48 struct CursorPosition {
49     int32_t displayId { -1 };
50     Direction direction { Direction::DIRECTION0 };
51     Coordinate2D cursorPos {};
52 };
53 
54 struct TargetInfo {
55     SecureFlag privacyMode { SecureFlag::DEFAULT_MODE };
56     int32_t id { -1 };
57     int32_t agentWindowId { -1 };
58 };
59 
60 class IInputWindowsManager {
61 public:
62     IInputWindowsManager() = default;
63     virtual ~IInputWindowsManager() = default;
64 
65     virtual void Init(UDSServer& udsServer) = 0;
66     virtual bool JudgeCaramaInFore() = 0;
67 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
68     virtual int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent) = 0;
69     virtual int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent, int32_t windowId) = 0;
70     virtual bool AdjustFingerFlag(std::shared_ptr<PointerEvent> pointerEvent) = 0;
71 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
72     virtual void UpdateDisplayInfo(DisplayGroupInfo &displayGroupInfo) = 0;
73     virtual void UpdateDisplayInfoExtIfNeed(DisplayGroupInfo &displayGroupInfo, bool needUpdateDisplayExt) = 0;
74     virtual void UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo) = 0;
75 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
76     virtual void SetWindowPointerStyle(WindowArea area, int32_t pid, int32_t windowId) = 0;
77 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
78     virtual int32_t ClearWindowPointerStyle(int32_t pid, int32_t windowId) = 0;
79     virtual void Dump(int32_t fd, const std::vector<std::string> &args) = 0;
80     virtual int32_t GetWindowPid(int32_t windowId) const = 0;
81     virtual int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) = 0;
82     virtual bool GetMouseIsCaptureMode() const = 0;
83     virtual int32_t GetDisplayBindInfo(DisplayBindInfos &infos) = 0;
84     virtual int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) = 0;
85     virtual int32_t AppendExtraData(const ExtraData& extraData) = 0;
86     virtual bool IsWindowVisible(int32_t pid) = 0;
87     virtual ExtraData GetExtraData() const = 0;
88     virtual const std::vector<WindowInfo>& GetWindowGroupInfoByDisplayId(int32_t displayId) const = 0;
89     virtual std::pair<double, double> TransformWindowXY(const WindowInfo &, double, double) const = 0;
90     virtual void ClearTargetWindowId(int32_t pointerId) = 0;
91     virtual bool CheckPidInSession(int32_t pid) = 0;
92     virtual std::pair<double, double> TransformDisplayXY(const DisplayInfo &info,
93         double logicX, double logicY) const = 0;
94     virtual int32_t SetPixelMapData(int32_t infoId, void *pixelMap) = 0;
95     virtual int32_t GetCurrentUserId() = 0;
96     virtual bool GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent) = 0;
97     virtual void SetFoldState () = 0;
98 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
99     virtual std::vector<std::pair<int32_t, TargetInfo>> UpdateTarget(std::shared_ptr<KeyEvent> keyEvent) = 0;
100     virtual void HandleKeyEventWindowId(std::shared_ptr<KeyEvent> keyEvent) = 0;
101 #endif // OHOS_BUILD_ENABLE_KEYBOARD
102 
103     virtual int32_t CheckWindowIdPermissionByPid(int32_t windowId, int32_t pid) = 0;
104 
105 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
106     virtual MouseLocation GetMouseInfo() = 0;
107     virtual CursorPosition GetCursorPos() = 0;
108     virtual CursorPosition ResetCursorPos() = 0;
109     virtual void UpdateAndAdjustMouseLocation(int32_t& displayId, double& x, double& y, bool isRealData = true) = 0;
110 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
111 #ifdef OHOS_BUILD_ENABLE_POINTER
112     virtual int32_t SetHoverScrollState(bool state) = 0;
113     virtual bool GetHoverScrollState() const = 0;
114 #endif // OHOS_BUILD_ENABLE_POINTER
115 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
116     virtual int32_t SetPointerStyle(int32_t pid, int32_t windowId,
117         PointerStyle pointerStyle, bool isUiExtension = false) = 0;
118     virtual int32_t GetPointerStyle(int32_t pid, int32_t windowId,
119         PointerStyle &pointerStyle, bool isUiExtension = false) const = 0;
120     virtual void DispatchPointer(int32_t pointerAction, int32_t windowId = -1) = 0;
121     virtual void SendPointerEvent(int32_t pointerAction) = 0;
122     virtual bool IsMouseSimulate() const = 0;
123     virtual bool HasMouseHideFlag() const = 0;
124 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
125 #ifdef OHOS_BUILD_ENABLE_POINTER
126 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
127     virtual bool IsNeedRefreshLayer(int32_t windowId) = 0;
128 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
129 #endif //OHOS_BUILD_ENABLE_POINTER
130 
131 #ifdef OHOS_BUILD_ENABLE_TOUCH
132     virtual bool TouchPointToDisplayPoint(int32_t deviceId, struct libinput_event_touch* touch,
133         EventTouch& touchInfo, int32_t& targetDisplayId) = 0;
134     virtual bool CalculateTipPoint(struct libinput_event_tablet_tool* tip,
135         int32_t& targetDisplayId, PhysicalCoordinate& coord) const = 0;
136     virtual const DisplayInfo *GetDefaultDisplayInfo() const = 0;
137     virtual void ReverseXY(int32_t &x, int32_t &y) = 0;
138     virtual void FoldScreenRotation(std::shared_ptr<PointerEvent> pointerEvent) = 0;
139     virtual void SendCancelEventWhenLock() = 0;
140 #endif // OHOS_BUILD_ENABLE_TOUCH
141 
142 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
143     virtual void DrawTouchGraphic(std::shared_ptr<PointerEvent> pointerEvent) = 0;
144     virtual int32_t UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent) = 0;
145     virtual const DisplayInfo* GetPhysicalDisplay(int32_t id) const = 0;
146 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
147 
148 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
149     virtual void UpdatePointerChangeAreas() = 0;
150 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
151     virtual std::optional<WindowInfo> GetWindowAndDisplayInfo(int32_t windowId, int32_t displayId) = 0;
152     virtual void GetTargetWindowIds(int32_t pointerItemId, int32_t sourceType, std::vector<int32_t> &windowIds) = 0;
153     virtual int32_t SetCurrentUser(int32_t userId) = 0;
154     virtual DisplayMode GetDisplayMode() const = 0;
155     virtual void SetWindowStateNotifyPid(int32_t pid) = 0;
156     virtual int32_t GetWindowStateNotifyPid() = 0;
157     virtual int32_t GetPidByWindowId(int32_t pid) = 0;
158 #ifdef OHOS_BUILD_ENABLE_ANCO
159     virtual int32_t AncoAddChannel(sptr<IAncoChannel> channel) = 0;
160     virtual int32_t AncoRemoveChannel(sptr<IAncoChannel> channel) = 0;
161     virtual void CleanShellWindowIds() = 0;
162     virtual bool IsKnuckleOnAncoWindow(std::shared_ptr<PointerEvent> pointerEvent) = 0;
163 #endif // OHOS_BUILD_ENABLE_ANCO
164 
165 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
166     virtual int32_t ShiftAppPointerEvent(const ShiftWindowParam &param, bool autoGenDown) = 0;
167 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
168 
169     static std::shared_ptr<IInputWindowsManager> GetInstance();
170     static void DestroyInstance();
171 
172 private:
173     static std::mutex mutex_;
174     static std::shared_ptr<IInputWindowsManager> instance_;
175 };
176 
177 #define WIN_MGR ::OHOS::MMI::IInputWindowsManager::GetInstance()
178 } // namespace MMI
179 } // namespace OHOS
180 #endif // I_INPUT_WINDOWS_MANAGER_H
181