• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef INPUT_WINDOWS_MANAGER_H
16 #define INPUT_WINDOWS_MANAGER_H
17 
18 #include <vector>
19 
20 #include "extra_data.h"
21 #include "libinput.h"
22 #include "nocopyable.h"
23 #include "singleton.h"
24 
25 #include "window_info.h"
26 #include "window_manager.h"
27 #include "input_display_bind_helper.h"
28 #include "input_event_data_transformation.h"
29 #include "input_event.h"
30 #include "pixel_map.h"
31 #include "pointer_event.h"
32 #include "pointer_style.h"
33 #include "uds_server.h"
34 
35 namespace OHOS {
36 namespace MMI {
37 struct MouseLocation {
38     int32_t physicalX { 0 };
39     int32_t physicalY { 0 };
40 };
41 
42 class InputWindowsManager final {
43     DECLARE_DELAYED_SINGLETON(InputWindowsManager);
44 public:
45     DISALLOW_COPY_AND_MOVE(InputWindowsManager);
46     void Init(UDSServer& udsServer);
47     int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent);
48 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
49     int32_t GetPidAndUpdateTarget(std::shared_ptr<InputEvent> inputEvent);
50 #endif // OHOS_BUILD_ENABLE_KEYBOARD
51 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
52     int32_t UpdateTarget(std::shared_ptr<InputEvent> inputEvent);
53 #endif // OHOS_BUILD_ENABLE_KEYBOARD
54     void UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo);
55 #ifdef OHOS_BUILD_ENABLE_POINTER
56     MouseLocation GetMouseInfo();
57     void UpdateAndAdjustMouseLocation(int32_t& displayId, double& x, double& y);
58 #endif //OHOS_BUILD_ENABLE_POINTER
59 #ifdef OHOS_BUILD_ENABLE_TOUCH
60     void AdjustDisplayCoordinate(const DisplayInfo& displayInfo, int32_t& physicalX, int32_t& physicalY) const;
61 #endif // OHOS_BUILD_ENABLE_TOUCH
62 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
63     bool UpdateDisplayId(int32_t& displayId);
64 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
65 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
66     int32_t UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent);
67 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
68 #ifdef OHOS_BUILD_ENABLE_TOUCH
69     bool TouchPointToDisplayPoint(int32_t deviceId, struct libinput_event_touch* touch,
70         EventTouch& touchInfo, int32_t& targetDisplayId);
71     void RotateTouchScreen(DisplayInfo info, LogicalCoordinate& coord) const;
72     bool TransformTipPoint(struct libinput_event_tablet_tool* tip, LogicalCoordinate& coord, int32_t& displayId) const;
73     bool CalculateTipPoint(struct libinput_event_tablet_tool* tip,
74         int32_t& targetDisplayId, LogicalCoordinate& coord) const;
75 #endif // OHOS_BUILD_ENABLE_TOUCH
76 #ifdef OHOS_BUILD_ENABLE_POINTER
77     const DisplayGroupInfo& GetDisplayGroupInfo();
78     int32_t SetHoverScrollState(bool state);
79     bool GetHoverScrollState() const;
80     int32_t SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle);
81     int32_t GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle) const;
82 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
83     bool IsNeedRefreshLayer(int32_t windowId);
84 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
85 #endif // OHOS_BUILD_ENABLE_POINTER
86     void Dump(int32_t fd, const std::vector<std::string> &args);
87     int32_t GetWindowPid(int32_t windowId, const DisplayGroupInfo& displayGroupInfo) const;
88     int32_t GetWindowPid(int32_t windowId) const;
89 #ifdef OHOS_BUILD_ENABLE_POINTER
90     void DispatchPointer(int32_t pointerAction);
91     void SendPointerEvent(int32_t pointerAction);
92 #endif // OHOS_BUILD_ENABLE_POINTER
93     int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode);
94     bool GetMouseIsCaptureMode() const;
95     void DeviceStatusChanged(int32_t deviceId, const std::string &sysUid, const std::string devStatus);
96     int32_t GetDisplayBindInfo(DisplayBindInfos &infos);
97     int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg);
98     int32_t AppendExtraData(const ExtraData& extraData);
99     bool IsWindowVisible(int32_t pid);
100     void ClearExtraData();
101 private:
102 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
103     bool IsInHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects) const;
104 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
105     void PrintDisplayInfo();
106 #ifdef OHOS_BUILD_ENABLE_POINTER
107     int32_t UpdateMouseTarget(std::shared_ptr<PointerEvent> pointerEvent);
108     void UpdatePointerEvent(int32_t logicalX, int32_t logicalY,
109         const std::shared_ptr<PointerEvent>& pointerEvent, const WindowInfo& touchWindow);
110     void NotifyPointerToWindow();
111     void OnSessionLost(SessionPtr session);
112     void UpdatePointerStyle();
113 #endif // OHOS_BUILD_ENABLE_POINTER
114 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
115     int32_t UpdateJoystickTarget(std::shared_ptr<PointerEvent> pointerEvent);
116 #endif // OHOS_BUILD_ENABLE_JOYSTICK
117 #ifdef OHOS_BUILD_ENABLE_TOUCH
118     int32_t UpdateTouchScreenTarget(std::shared_ptr<PointerEvent> pointerEvent);
119     void PullEnterLeaveEvent(int32_t logicalX, int32_t logicalY,
120         const std::shared_ptr<PointerEvent> pointerEvent, const WindowInfo* touchWindow);
121     void DispatchTouch(int32_t pointerAction);
122 #endif // OHOS_BUILD_ENABLE_TOUCH
123 #ifdef OHOS_BUILD_ENABLE_POINTER
124     int32_t UpdateTouchPadTarget(std::shared_ptr<PointerEvent> pointerEvent);
125 #endif // OHOS_BUILD_ENABLE_POINTER
126 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
127     const DisplayInfo* GetPhysicalDisplay(int32_t id) const;
128 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
129 #ifdef OHOS_BUILD_ENABLE_TOUCH
130     const DisplayInfo* FindPhysicalDisplayInfo(const std::string& uniq) const;
131 #endif // OHOS_BUILD_ENABLE_TOUCH
132     int32_t GetDisplayId(std::shared_ptr<InputEvent> inputEvent) const;
133 #ifdef OHOS_BUILD_ENABLE_POINTER
134     std::optional<WindowInfo> SelectWindowInfo(int32_t logicalX, int32_t logicalY,
135         const std::shared_ptr<PointerEvent>& pointerEvent);
136     std::optional<WindowInfo> GetWindowInfo(int32_t logicalX, int32_t logicalY);
137 #endif // OHOS_BUILD_ENABLE_POINTER
138 #ifdef OHOS_BUILD_ENABLE_TOUCH
139     void GetPhysicalDisplayCoord(struct libinput_event_touch* touch,
140         const DisplayInfo& info, EventTouch& touchInfo);
141 #endif // OHOS_BUILD_ENABLE_TOUCH
142 #ifdef OHOS_BUILD_ENABLE_POINTER
143     bool IsInsideDisplay(const DisplayInfo& displayInfo, int32_t physicalX, int32_t physicalY);
144     void FindPhysicalDisplay(const DisplayInfo& displayInfo, int32_t& physicalX,
145         int32_t& physicalY, int32_t& displayId);
146     void InitMouseDownInfo();
147 #endif // OHOS_BUILD_ENABLE_POINTER
148     void CheckFocusWindowChange(const DisplayGroupInfo &displayGroupInfo);
149     void CheckZorderWindowChange(const DisplayGroupInfo &displayGroupInfo);
150     void UpdateDisplayIdAndName();
151     void UpdatePointerAction(std::shared_ptr<PointerEvent> pointerEvent);
152     bool IsNeedDrawPointer(PointerEvent::PointerItem &pointerItem) const;
153 private:
154     UDSServer* udsServer_ { nullptr };
155 #ifdef OHOS_BUILD_ENABLE_POINTER
156     int32_t firstBtnDownWindowId_ { -1 };
157     int32_t lastLogicX_ { -1 };
158     int32_t lastLogicY_ { -1 };
159     WindowInfo lastWindowInfo_;
160     std::shared_ptr<PointerEvent> lastPointerEvent_ { nullptr };
161     std::map<int32_t, std::map<int32_t, PointerStyle>> pointerStyle_;
162     WindowInfo mouseDownInfo_;
163     PointerStyle globalStyle_;
164 #endif // OHOS_BUILD_ENABLE_POINTER
165 #ifdef OHOS_BUILD_ENABLE_TOUCH
166     int32_t lastTouchLogicX_ { -1 };
167     int32_t lastTouchLogicY_ { -1 };
168     WindowInfo lastTouchWindowInfo_;
169     std::shared_ptr<PointerEvent> lastTouchEvent_ { nullptr };
170 #endif // OHOS_BUILD_ENABLE_POINTER
171     DisplayGroupInfo displayGroupInfo_;
172     MouseLocation mouseLocation_ = { -1, -1 };
173     std::map<int32_t, WindowInfo> touchItemDownInfos_;
174     InputDisplayBindHelper bindInfo_;
175     struct CaptureModeInfo {
176         int32_t windowId { -1 };
177         bool isCaptureMode { false };
178     } captureModeInfo_;
179     ExtraData extraData_;
180 };
181 
182 #define WinMgr ::OHOS::DelayedSingleton<InputWindowsManager>::GetInstance()
183 } // namespace MMI
184 } // namespace OHOS
185 #endif // INPUT_WINDOWS_MANAGER_H