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