• 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 #include "singleton.h"
20 #include "uds_server.h"
21 #include "display_info.h"
22 #include "input_event.h"
23 #include "pointer_event.h"
24 #include "libinput.h"
25 
26 namespace OHOS {
27 namespace MMI {
28 struct SurfaceInfo {
29     int32_t surfaceId;
30     int32_t dstX;
31     int32_t dstY;
32     int32_t dstW;
33     int32_t dstH;
34     int32_t srcX;
35     int32_t srcY;
36     int32_t srcW;
37     int32_t srcH;
38     double opacity;
39     int32_t visibility; // 0 or 1
40     int32_t onLayerId;
41 };
42 struct LayerInfo {
43     int32_t layerId;
44     int32_t dstX;
45     int32_t dstY;
46     int32_t dstW;
47     int32_t dstH;
48     int32_t srcX;
49     int32_t srcY;
50     int32_t srcW;
51     int32_t srcH;
52     double opacity;
53     int32_t visibility; // 0 or 1
54     int32_t onScreenId;
55     int32_t nSurfaces;
56     SurfaceInfo** surfaces;
57 };
58 struct ScreenInfo {
59     int32_t screenId;
60     char* connectorName;
61     int32_t width;
62     int32_t height;
63     int32_t nLayers;
64     LayerInfo** layers;
65 };
66 struct SeatInfo {
67     char* seatName;
68     int32_t deviceFlags;
69     int32_t focusWindowId;
70 };
71 struct multimodal_libinput_event {
72     struct libinput_event *event;
73     void *userdata;
74 };
75 struct MouseLocation {
76     int32_t globalX;
77     int32_t globalY;
78 };
79 
80 class InputWindowsManager : public DelayedSingleton<InputWindowsManager> {
81 public:
82     InputWindowsManager();
83     virtual ~InputWindowsManager();
84 
85     bool Init(UDSServer& udsServer);
86     void UpdateSeatsInfo();
87     void UpdateScreensInfo();
88 
89 
90     void PrintAllNormalSurface();
91 
92     void Clear();
93     void Dump(int32_t fd);
94 
95     /*********************************新框架接口添加*************************** */
96     int32_t GetPidAndUpdateTarget(std::shared_ptr<InputEvent> inputEvent);
97     int32_t UpdateTarget(std::shared_ptr<InputEvent> inputEvent);
98     void UpdateDisplayInfo(const std::vector<PhysicalDisplayInfo> &physicalDisplays,
99         const std::vector<LogicalDisplayInfo> &logicalDisplays);
100     bool TouchPadPointToDisplayPoint_2(struct libinput_event_touch* touch,
101         int32_t& logicalX, int32_t& logicalY, int32_t& logicalDisplayId);
102     const std::vector<LogicalDisplayInfo>& GetLogicalDisplayInfo() const;
103     const std::map<int32_t, WindowInfo>& GetWindowInfo() const;
104     MouseLocation GetMouseInfo();
105     void UpdateAndAdjustMouseLoction(double& x, double& y);
106     void AdjustGlobalCoordinate(int32_t& globalX, int32_t& globalY, int32_t width, int32_t height);
107     bool UpdataDisplayId(int32_t& displayId);
108     LogicalDisplayInfo* GetLogicalDisplayId(int32_t displayId);
109     int32_t UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent);
110     bool TouchDownPointToDisplayPoint(struct libinput_event_touch* touch, Direction& direction,
111         int32_t& logicalX, int32_t& logicalY, int32_t& logicalDisplayId);
112     bool TouchMotionPointToDisplayPoint(struct libinput_event_touch* touch, Direction& direction,
113         int32_t targetDisplayId, int32_t& displayX, int32_t& displayY);
114     bool TransformOfDisplayPoint(struct libinput_event_touch* touch, Direction& direction, int32_t &globalLogicalX,
115         int32_t &globalLogicalY);
116     void TurnTouchScreen(PhysicalDisplayInfo* info, Direction direction,
117         int32_t& logicalX, int32_t& logicalY);
118     void AdjustCoordinate(double &coordinateX, double &coordinateY);
119 
120 private:
121     void SetFocusId(int32_t id);
122     void PrintDebugInfo();
123     int32_t UpdateMouseTargetOld(std::shared_ptr<PointerEvent> pointerEvent);
124     int32_t UpdateTouchScreenTargetOld(std::shared_ptr<PointerEvent> pointerEvent);
125     int32_t UpdateTouchPadTargetOld(std::shared_ptr<PointerEvent> pointerEvent);
126 
127     /*********************************新框架接口添加*************************** */
128     bool IsInsideWindow(int32_t x, int32_t y, const WindowInfo &info) const;
129     void PrintDisplayDebugInfo();
130     int32_t UpdateMouseTarget(std::shared_ptr<PointerEvent> pointerEvent);
131     int32_t UpdateTouchScreenTarget(std::shared_ptr<PointerEvent> pointerEvent);
132     int32_t UpdateTouchPadTarget(std::shared_ptr<PointerEvent> pointerEvent);
133     PhysicalDisplayInfo* GetPhysicalDisplay(int32_t id);
134     PhysicalDisplayInfo* FindPhysicalDisplayInfo(const std::string seatId, const std::string seatName);
135     int32_t GetDisplayId(std::shared_ptr<InputEvent> inputEvent);
136     void SelectWindowInfo(const int32_t& globalX, const int32_t& globalY,
137         const std::shared_ptr<PointerEvent>& pointerEvent, LogicalDisplayInfo * const logicalDisplayInfo,
138         WindowInfo*& touchWindow);
139 
140 private:
141     std::mutex mu_;
142     SeatInfo** seatsInfo_ = nullptr;
143     ScreenInfo **screensInfo_ = nullptr;
144     int32_t focusInfoID_ = 0;
145     int32_t touchFocusId_ = 0;
146     UDSServer* udsServer_ = nullptr;
147     int32_t firstBtnDownWindowId_ = -1;
148     /* *********************************新框架接口添加*************************** */
149     std::vector<PhysicalDisplayInfo> physicalDisplays_ = {};
150     std::vector<LogicalDisplayInfo> logicalDisplays_ = {};
151     std::map<int32_t, WindowInfo> windowInfos_ = {};
152     MouseLocation mouseLoction_ = {};
153 };
154 } // namespace MMI
155 } // namespace OHOS
156 
157 #define WinMgr OHOS::MMI::InputWindowsManager::GetInstance()
158 #endif // INPUT_WINDOWS_MANAGER_H
159