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 <vector> 20 21 #include "extra_data.h" 22 #include "libinput.h" 23 #include "nocopyable.h" 24 #include "singleton.h" 25 26 #include "window_info.h" 27 #include "window_manager.h" 28 #include "input_display_bind_helper.h" 29 #include "input_event_data_transformation.h" 30 #include "input_event.h" 31 #include "pixel_map.h" 32 #include "pointer_event.h" 33 #include "pointer_style.h" 34 #include "uds_server.h" 35 36 namespace OHOS { 37 namespace MMI { 38 struct MouseLocation { 39 int32_t physicalX { 0 }; 40 int32_t physicalY { 0 }; 41 }; 42 43 struct DevMode { 44 std::string SwitchName; 45 bool isShow { false }; 46 }; 47 48 class InputWindowsManager final { 49 DECLARE_DELAYED_SINGLETON(InputWindowsManager); 50 public: 51 DISALLOW_COPY_AND_MOVE(InputWindowsManager); 52 void Init(UDSServer& udsServer); 53 int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent); 54 void UpdateCaptureMode(const DisplayGroupInfo &displayGroupInfo); 55 void UpdateDisplayInfo(DisplayGroupInfo &displayGroupInfo); 56 void UpdateDisplayInfoExtIfNeed(DisplayGroupInfo &displayGroupInfo, bool needUpdateDisplayExt); 57 void UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo); 58 void SetWindowPointerStyle(WindowArea area, int32_t pid, int32_t windowId); 59 void UpdateWindowPointerVisible(int32_t pid); 60 int32_t ClearWindowPointerStyle(int32_t pid, int32_t windowId); 61 void Dump(int32_t fd, const std::vector<std::string> &args); 62 int32_t GetWindowPid(int32_t windowId, const std::vector<WindowInfo> &windowsInfo) const; 63 int32_t GetWindowPid(int32_t windowId) const; 64 int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode); 65 bool GetMouseIsCaptureMode() const; 66 void DeviceStatusChanged(int32_t deviceId, const std::string &sysUid, const std::string devStatus); 67 int32_t GetDisplayBindInfo(DisplayBindInfos &infos); 68 int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); 69 int32_t AppendExtraData(const ExtraData& extraData); 70 bool IsWindowVisible(int32_t pid); 71 void ClearExtraData(); 72 const std::vector<WindowInfo>& GetWindowGroupInfoByDisplayId(int32_t displayId) const; 73 std::pair<int32_t, int32_t> TransformWindowXY(const WindowInfo &window, int32_t logicX, int32_t logicY) const; 74 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 75 int32_t GetPidAndUpdateTarget(std::shared_ptr<KeyEvent> keyEvent); 76 int32_t UpdateTarget(std::shared_ptr<KeyEvent> keyEvent); 77 #endif // OHOS_BUILD_ENABLE_KEYBOARD 78 79 #ifdef OHOS_BUILD_ENABLE_POINTER 80 MouseLocation GetMouseInfo(); 81 void UpdateAndAdjustMouseLocation(int32_t& displayId, double& x, double& y); 82 const DisplayGroupInfo& GetDisplayGroupInfo(); 83 int32_t SetHoverScrollState(bool state); 84 bool GetHoverScrollState() const; 85 int32_t SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle); 86 int32_t GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle) const; 87 void DispatchPointer(int32_t pointerAction); 88 void SendPointerEvent(int32_t pointerAction); 89 PointerStyle GetLastPointerStyle() const; 90 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING 91 bool IsNeedRefreshLayer(int32_t windowId); 92 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING 93 #endif //OHOS_BUILD_ENABLE_POINTER 94 95 #ifdef OHOS_BUILD_ENABLE_TOUCH 96 void AdjustDisplayCoordinate(const DisplayInfo& displayInfo, int32_t& physicalX, int32_t& physicalY) const; 97 bool TouchPointToDisplayPoint(int32_t deviceId, struct libinput_event_touch* touch, 98 EventTouch& touchInfo, int32_t& targetDisplayId); 99 void RotateScreen(const DisplayInfo& info, LogicalCoordinate& coord) const; 100 bool TransformTipPoint(struct libinput_event_tablet_tool* tip, LogicalCoordinate& coord, int32_t& displayId) const; 101 bool CalculateTipPoint(struct libinput_event_tablet_tool* tip, 102 int32_t& targetDisplayId, LogicalCoordinate& coord) const; 103 #endif // OHOS_BUILD_ENABLE_TOUCH 104 105 #ifdef OHOS_BUILD_ENABLE_ANCO 106 void UpdateWindowInfoExt(const WindowGroupInfo &windowGroupInfo, const DisplayGroupInfo &displayGroupInfo); 107 void UpdateShellWindow(const WindowInfo &window); 108 void UpdateDisplayInfoExt(const DisplayGroupInfo &displayGroupInfo); 109 bool IsInAncoWindow(const WindowInfo &window, int32_t x, int32_t y) const; 110 bool IsAncoWindow(const WindowInfo &window) const; 111 bool IsAncoWindowFocus(const WindowInfo &window) const; 112 void SimulatePointerExt(std::shared_ptr<PointerEvent> pointerEvent); 113 void SimulateKeyExt(std::shared_ptr<KeyEvent> keyEvent); 114 void DumpAncoWindows(std::string& out) const; 115 #endif // OHOS_BUILD_ENABLE_ANCO 116 117 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 118 bool UpdateDisplayId(int32_t& displayId); 119 void DrawTouchGraphic(std::shared_ptr<PointerEvent> pointerEvent); 120 int32_t UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent); 121 const DisplayInfo* GetPhysicalDisplay(int32_t id) const; 122 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 123 124 private: 125 int32_t GetDisplayId(std::shared_ptr<InputEvent> inputEvent) const; 126 void PrintWindowInfo(const std::vector<WindowInfo> &windowsInfo); 127 void PrintDisplayInfo(); 128 void PrintWindowGroupInfo(const WindowGroupInfo &windowGroupInfo); 129 void CheckFocusWindowChange(const DisplayGroupInfo &displayGroupInfo); 130 void CheckZorderWindowChange(const std::vector<WindowInfo> &oldWindowsInfo, 131 const std::vector<WindowInfo> &newWindowsInfo); 132 void UpdateDisplayIdAndName(); 133 void UpdatePointerAction(std::shared_ptr<PointerEvent> pointerEvent); 134 bool IsNeedDrawPointer(PointerEvent::PointerItem &pointerItem) const; 135 void UpdateDisplayInfoByIncrementalInfo(const WindowInfo &window, DisplayGroupInfo &displayGroupInfo); 136 void UpdateWindowsInfoPerDisplay(const DisplayGroupInfo &displayGroupInfo); 137 std::pair<int32_t, int32_t> TransformSampleWindowXY(int32_t logicX, int32_t logicY) const; 138 bool IsValidZorderWindow(const WindowInfo &window, const std::shared_ptr<PointerEvent>& pointerEvent); 139 void UpdateTopBottomArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas, 140 std::vector<Rect> &windowHotAreas); 141 void UpdateLeftRightArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas, 142 std::vector<Rect> &windowHotAreas); 143 void UpdateInnerAngleArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas, 144 std::vector<Rect> &windowHotAreas); 145 void CoordinateCorrection(int32_t width, int32_t height, int32_t &integerX, int32_t &integerY); 146 void GetWidthAndHeight(const DisplayInfo* displayInfo, int32_t &width, int32_t &height); 147 148 #ifdef OHOS_BUILD_ENABLE_POINTER 149 void GetPointerStyleByArea(WindowArea area, int32_t pid, int32_t winId, PointerStyle& pointerStyle); 150 int32_t UpdateMouseTarget(std::shared_ptr<PointerEvent> pointerEvent); 151 void UpdatePointerEvent(int32_t logicalX, int32_t logicalY, 152 const std::shared_ptr<PointerEvent>& pointerEvent, const WindowInfo& touchWindow); 153 void NotifyPointerToWindow(); 154 void OnSessionLost(SessionPtr session); 155 void InitPointerStyle(); 156 int32_t UpdatePoinerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle); 157 int32_t UpdateSceneBoardPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle); 158 int32_t UpdateTouchPadTarget(std::shared_ptr<PointerEvent> pointerEvent); 159 std::optional<WindowInfo> SelectWindowInfo(int32_t logicalX, int32_t logicalY, 160 const std::shared_ptr<PointerEvent>& pointerEvent); 161 std::optional<WindowInfo> GetWindowInfo(int32_t logicalX, int32_t logicalY); 162 bool IsInsideDisplay(const DisplayInfo& displayInfo, int32_t physicalX, int32_t physicalY); 163 void FindPhysicalDisplay(const DisplayInfo& displayInfo, int32_t& physicalX, 164 int32_t& physicalY, int32_t& displayId); 165 void InitMouseDownInfo(); 166 void SelectPointerChangeArea(const WindowInfo &windowInfo, PointerStyle &pointerStyle, 167 int32_t logicalX, int32_t logicalY); 168 void UpdatePointerChangeAreas(const DisplayGroupInfo &displayGroupInfo); 169 #endif // OHOS_BUILD_ENABLE_POINTER 170 171 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) 172 void PointerDrawingManagerOnDisplayInfo(const DisplayGroupInfo &displayGroupInfo); 173 bool NeedUpdatePointDrawFlag(const std::vector<WindowInfo> &windows); 174 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING 175 176 #ifdef OHOS_BUILD_ENABLE_TOUCH 177 int32_t UpdateTouchScreenTarget(std::shared_ptr<PointerEvent> pointerEvent); 178 void PullEnterLeaveEvent(int32_t logicalX, int32_t logicalY, 179 const std::shared_ptr<PointerEvent> pointerEvent, const WindowInfo* touchWindow); 180 void DispatchTouch(int32_t pointerAction); 181 const DisplayInfo* FindPhysicalDisplayInfo(const std::string& uniq) const; 182 void GetPhysicalDisplayCoord(struct libinput_event_touch* touch, 183 const DisplayInfo& info, EventTouch& touchInfo); 184 #endif // OHOS_BUILD_ENABLE_TOUCH 185 186 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 187 bool IsInHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects, const WindowInfo &window) const; 188 void InWhichHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects, PointerStyle &pointerStyle) const; 189 template <class T> 190 void CreateStatusConfigObserver(T& item); 191 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 192 193 #ifdef OHOS_BUILD_ENABLE_JOYSTICK 194 int32_t UpdateJoystickTarget(std::shared_ptr<PointerEvent> pointerEvent); 195 #endif // OHOS_BUILD_ENABLE_JOYSTICK 196 197 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER 198 void UpdateDisplayMode(); 199 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER 200 201 private: 202 UDSServer* udsServer_ { nullptr }; 203 #ifdef OHOS_BUILD_ENABLE_POINTER 204 int32_t firstBtnDownWindowId_ { -1 }; 205 int32_t lastLogicX_ { -1 }; 206 int32_t lastLogicY_ { -1 }; 207 WindowInfo lastWindowInfo_; 208 std::shared_ptr<PointerEvent> lastPointerEvent_ { nullptr }; 209 std::map<int32_t, std::map<int32_t, PointerStyle>> pointerStyle_; 210 WindowInfo mouseDownInfo_; 211 PointerStyle globalStyle_; 212 #endif // OHOS_BUILD_ENABLE_POINTER 213 #ifdef OHOS_BUILD_ENABLE_TOUCH 214 int32_t lastTouchLogicX_ { -1 }; 215 int32_t lastTouchLogicY_ { -1 }; 216 WindowInfo lastTouchWindowInfo_; 217 std::shared_ptr<PointerEvent> lastTouchEvent_ { nullptr }; 218 #endif // OHOS_BUILD_ENABLE_POINTER 219 DisplayGroupInfo displayGroupInfo_; 220 std::map<int32_t, WindowGroupInfo> windowsPerDisplay_; 221 PointerStyle lastPointerStyle_ {.id = -1}; 222 PointerStyle dragPointerStyle_ {.id = -1}; 223 MouseLocation mouseLocation_ = { -1, -1 }; 224 double absolutionX_ {}; 225 double absolutionY_ {}; 226 std::map<int32_t, WindowInfo> touchItemDownInfos_; 227 std::map<int32_t, std::vector<Rect>> windowsHotAreas_; 228 InputDisplayBindHelper bindInfo_; 229 struct CaptureModeInfo { 230 int32_t windowId { -1 }; 231 bool isCaptureMode { false }; 232 } captureModeInfo_; 233 ExtraData extraData_; 234 bool haveSetObserver_ { false }; 235 bool dragFlag_ { false }; 236 bool pointerDrawFlag_ { false }; 237 DevMode showCursor_; 238 DisplayMode displayMode_ { DisplayMode::UNKNOWN }; 239 }; 240 241 #define WinMgr ::OHOS::DelayedSingleton<InputWindowsManager>::GetInstance() 242 } // namespace MMI 243 } // namespace OHOS 244 #endif // INPUT_WINDOWS_MANAGER_H