• 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 "libinput.h"
21 #include "nocopyable.h"
22 #include "singleton.h"
23 
24 #include "display_info.h"
25 #include "input_event.h"
26 #include "input_event_data_transformation.h"
27 #include "pointer_event.h"
28 #include "uds_server.h"
29 
30 namespace OHOS {
31 namespace MMI {
32 struct MouseLocation {
33     int32_t physicalX { 0 };
34     int32_t physicalY { 0 };
35 };
36 
37 class InputWindowsManager final {
38     DECLARE_DELAYED_SINGLETON(InputWindowsManager);
39 public:
40     DISALLOW_COPY_AND_MOVE(InputWindowsManager);
41     void Init(UDSServer& udsServer);
42     int32_t GetClientFd(std::shared_ptr<PointerEvent> pointerEvent);
43 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
44     int32_t GetPidAndUpdateTarget(std::shared_ptr<InputEvent> inputEvent);
45 #endif // OHOS_BUILD_ENABLE_KEYBOARD
46 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
47     int32_t UpdateTarget(std::shared_ptr<InputEvent> inputEvent);
48 #endif // OHOS_BUILD_ENABLE_KEYBOARD
49     void UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo);
50 #ifdef OHOS_BUILD_ENABLE_POINTER
51     MouseLocation GetMouseInfo();
52     void UpdateAndAdjustMouseLocation(int32_t& displayId, double& x, double& y);
53 #endif //OHOS_BUILD_ENABLE_POINTER
54 #ifdef OHOS_BUILD_ENABLE_TOUCH
55     void AdjustDisplayCoordinate(const DisplayInfo& displayInfo, int32_t& physicalX, int32_t& physicalY) const;
56 #endif // OHOS_BUILD_ENABLE_TOUCH
57 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
58     bool UpdateDisplayId(int32_t& displayId);
59 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
60 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
61     int32_t UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent);
62 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
63 #ifdef OHOS_BUILD_ENABLE_TOUCH
64     bool TouchPointToDisplayPoint(int32_t deviceId, struct libinput_event_touch* touch,
65         EventTouch& touchInfo, int32_t& targetDisplayId);
66     void RotateTouchScreen(DisplayInfo info, LogicalCoordinate& coord) const;
67     bool TransformTipPoint(struct libinput_event_tablet_tool* tip, LogicalCoordinate& coord, int32_t& displayId) const;
68     bool CalculateTipPoint(struct libinput_event_tablet_tool* tip,
69         int32_t& targetDisplayId, LogicalCoordinate& coord) const;
70 #endif // OHOS_BUILD_ENABLE_TOUCH
71 #ifdef OHOS_BUILD_ENABLE_POINTER
72     const DisplayGroupInfo& GetDisplayGroupInfo();
73     int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle);
74     int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) const;
75 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
76     bool IsNeedRefreshLayer(int32_t windowId);
77 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
78 #endif // OHOS_BUILD_ENABLE_POINTER
79     void Dump(int32_t fd, const std::vector<std::string> &args);
80     int32_t GetWindowPid(int32_t windowId, const DisplayGroupInfo& displayGroupInfo) const;
81     int32_t GetWindowPid(int32_t windowId) const;
82 #ifdef OHOS_BUILD_ENABLE_POINTER
83     void DispatchPointer(int32_t pointerAction);
84     void SendPointerEvent(int32_t pointerAction);
85 #endif // OHOS_BUILD_ENABLE_POINTER
86 
87 private:
88 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
89     bool IsInHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects) const;
90 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
91     void PrintDisplayInfo();
92 #ifdef OHOS_BUILD_ENABLE_POINTER
93     int32_t UpdateMouseTarget(std::shared_ptr<PointerEvent> pointerEvent);
94     void UpdatePointerEvent(int32_t logicalX, int32_t logicalY,
95         const std::shared_ptr<PointerEvent>& pointerEvent, const WindowInfo& touchWindow);
96     void NotifyPointerToWindow();
97     void OnSessionLost(SessionPtr session);
98     void UpdatePointerStyle();
99 #endif // OHOS_BUILD_ENABLE_POINTER
100 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
101     int32_t UpdateJoystickTarget(std::shared_ptr<PointerEvent> pointerEvent);
102 #endif // OHOS_BUILD_ENABLE_JOYSTICK
103 #ifdef OHOS_BUILD_ENABLE_TOUCH
104     int32_t UpdateTouchScreenTarget(std::shared_ptr<PointerEvent> pointerEvent);
105 #endif // OHOS_BUILD_ENABLE_TOUCH
106 #ifdef OHOS_BUILD_ENABLE_POINTER
107     int32_t UpdateTouchPadTarget(std::shared_ptr<PointerEvent> pointerEvent);
108 #endif // OHOS_BUILD_ENABLE_POINTER
109 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
110     const DisplayInfo* GetPhysicalDisplay(int32_t id) const;
111 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
112 #ifdef OHOS_BUILD_ENABLE_TOUCH
113     const DisplayInfo* FindPhysicalDisplayInfo(const std::string& uniq) const;
114 #endif // OHOS_BUILD_ENABLE_TOUCH
115     int32_t GetDisplayId(std::shared_ptr<InputEvent> inputEvent) const;
116 #ifdef OHOS_BUILD_ENABLE_POINTER
117     std::optional<WindowInfo> SelectWindowInfo(int32_t logicalX, int32_t logicalY,
118         const std::shared_ptr<PointerEvent>& pointerEvent);
119     std::optional<WindowInfo> GetWindowInfo(int32_t logicalX, int32_t logicalY);
120 #endif // OHOS_BUILD_ENABLE_POINTER
121 #ifdef OHOS_BUILD_ENABLE_TOUCH
122     void GetPhysicalDisplayCoord(struct libinput_event_touch* touch,
123         const DisplayInfo& info, EventTouch& touchInfo);
124 #endif // OHOS_BUILD_ENABLE_TOUCH
125 #ifdef OHOS_BUILD_ENABLE_POINTER
126     bool IsInsideDisplay(const DisplayInfo& displayInfo, int32_t physicalX, int32_t physicalY);
127     void FindPhysicalDisplay(const DisplayInfo& displayInfo, int32_t& physicalX,
128         int32_t& physicalY, int32_t& displayId);
129     void InitMouseDownInfo();
130 #endif // OHOS_BUILD_ENABLE_POINTER
131     void CheckFocusWindowChange(const DisplayGroupInfo &displayGroupInfo);
132     void CheckZorderWindowChange(const DisplayGroupInfo &displayGroupInfo);
133 private:
134     UDSServer* udsServer_ { nullptr };
135 #ifdef OHOS_BUILD_ENABLE_POINTER
136     int32_t firstBtnDownWindowId_ { -1 };
137     int32_t lastLogicX_ { -1 };
138     int32_t lastLogicY_ { -1 };
139     WindowInfo lastWindowInfo_;
140     std::shared_ptr<PointerEvent> lastPointerEvent_ { nullptr };
141     std::map<int32_t, std::map<int32_t, int32_t>> pointerStyle_;
142     WindowInfo mouseDownInfo_;
143 #endif // OHOS_BUILD_ENABLE_POINTER
144     DisplayGroupInfo displayGroupInfo_;
145     MouseLocation mouseLocation_ = { -1, -1 }; // physical coord
146     std::map<int32_t, WindowInfo> touchItemDownInfos_;
147 };
148 
149 #define WinMgr ::OHOS::DelayedSingleton<InputWindowsManager>::GetInstance()
150 } // namespace MMI
151 } // namespace OHOS
152 #endif // INPUT_WINDOWS_MANAGER_H