• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 #include "input_windows_manager.h"
17 #include <linux/input.h>
18 
19 #include "display_manager_lite.h"
20 #include "event_log_helper.h"
21 #include "json_parser.h"
22 #include "pixel_map.h"
23 #ifndef OHOS_BUILD_ENABLE_WATCH
24 #include "knuckle_drawing_component.h"
25 #endif // OHOS_BUILD_ENABLE_WATCH
26 #include "key_command_handler_util.h"
27 #include "mmi_matrix3.h"
28 #include "cursor_drawing_component.h"
29 #include "scene_board_judgement.h"
30 #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING
31 #include "touch_drawing_manager.h"
32 #endif // #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING
33 #ifdef OHOS_BUILD_ENABLE_ANCO
34 #endif // OHOS_BUILD_ENABLE_ANCO
35 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
36 #include "magic_pointer_velocity_tracker.h"
37 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR
38 #include "hitrace_meter.h"
39 #include "pull_throw_subscriber_handler.h"
40 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
41 #include "dfx_hisysevent_device.h"
42 #endif // OHOS_BUILD_ENABLE_DFX_RADAR
43 #include "product_name_definition.h"
44 #include "product_type_parser.h"
45 #include "bundle_name_parser.h"
46 
47 #undef MMI_LOG_DOMAIN
48 #define MMI_LOG_DOMAIN MMI_LOG_WINDOW
49 #undef MMI_LOG_TAG
50 #define MMI_LOG_TAG "InputWindowsManager"
51 
52 namespace OHOS {
53 namespace MMI {
54 namespace {
55 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
56 constexpr int32_t DEFAULT_POINTER_STYLE { 0 };
57 constexpr int32_t CURSOR_CIRCLE_STYLE { 41 };
58 constexpr int32_t AECH_DEVELOPER_DEFINED_STYLE { 47 };
59 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
60 constexpr int32_t OUTWINDOW_HOT_AREA { 20 };
61 constexpr int32_t SCALE_X { 0 };
62 constexpr int32_t SCALE_Y { 4 };
63 constexpr int32_t ANCHOR_POINT_X { 6 };
64 constexpr int32_t ANCHOR_POINT_Y { 7 };
65 constexpr int32_t TOP_LEFT_AREA { 0 };
66 constexpr int32_t TOP_AREA { 1 };
67 constexpr int32_t TOP_RIGHT_AREA { 2 };
68 constexpr int32_t RIGHT_AREA { 3 };
69 constexpr int32_t BOTTOM_RIGHT_AREA { 4 };
70 constexpr int32_t BOTTOM_AREA { 5 };
71 constexpr int32_t BOTTOM_LEFT_AREA { 6 };
72 constexpr int32_t LEFT_AREA { 7 };
73 [[ maybe_unused ]] constexpr int32_t WAIT_TIME_FOR_REGISTER { 2000 };
74 constexpr int32_t RS_PROCESS_TIMEOUT { 500 * 1000 };
75 constexpr int32_t HICAR_MIN_DISPLAY_ID { 1000 };
76 #ifdef OHOS_BUILD_ENABLE_ANCO
77 constexpr int32_t SHELL_WINDOW_COUNT { 1 };
78 #endif // OHOS_BUILD_ENABLE_ANCO
79 constexpr double HALF_RATIO { 0.5 };
80 constexpr int32_t TWOFOLD { 2 };
81 constexpr int32_t COMMON_PARAMETER_ERROR { 401 };
82 const std::string BIND_CFG_FILE_NAME { "/data/service/el1/public/multimodalinput/display_bind.cfg" };
83 const std::string MOUSE_FILE_NAME { "mouse_settings.xml" };
84 const std::string DEFAULT_ICON_PATH { "/system/etc/multimodalinput/mouse_icon/Default.svg" };
85 const std::string NAVIGATION_SWITCH_NAME { "settings.input.stylus_navigation_hint" };
86 const std::string PRODUCT_TYPE_HYM = OHOS::system::GetParameter("const.build.product", "HYM");
87 const std::string PRODUCT_TYPE = system::GetParameter("const.product.devicetype", "unknown");
88 const std::string PRODUCT_TYPE_PC = "2in1";
89 constexpr uint32_t FOLD_STATUS_MASK { 1U << 27U };
90 constexpr int32_t REPEAT_COOLING_TIME { 100 };
91 constexpr int32_t REPEAT_ONCE { 1 };
92 constexpr int32_t DEFAULT_VALUE { -1 };
93 constexpr int32_t ANGLE_90 { 90 };
94 constexpr int32_t ANGLE_360 { 360 };
95 constexpr int32_t POINTER_MOVEFLAG = { 7 };
96 constexpr size_t POINTER_STYLE_WINDOW_NUM = { 10 };
97 constexpr size_t SINGLE_TOUCH { 1 };
98 constexpr int32_t CAST_INPUT_DEVICEID { 0xAAAAAAFF };
99 constexpr int32_t CAST_SCREEN_DEVICEID { 0xAAAAAAFE };
100 constexpr int32_t DEFAULT_DPI { 0 };
101 constexpr int32_t DEFAULT_POSITION { 0 };
102 constexpr int32_t MAIN_GROUPID { 0 };
103 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
104 constexpr uint32_t WINDOW_NAME_TYPE_SCREENSHOT { 1 };
105 constexpr float SCREEN_CAPTURE_WINDOW_ZORDER { 8000.0 };
106 constexpr uint32_t CAST_WINDOW_TYPE { 2106 };
107 constexpr uint32_t GUIDE_WINDOW_TYPE { 2500 };
108 constexpr uint32_t VOICE_WINDOW_ZORDER { 4000.0 };
109 #define SCREEN_RECORD_WINDOW_WIDTH 400
110 #define SCREEN_RECORD_WINDOW_HEIGHT 200
111 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
112 constexpr uint32_t CURSOR_POSITION_EXPECTED_SIZE { 2 };
113 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
114 constexpr int64_t SIMULATE_EVENT_LATENCY { 5 };
115 #endif // OHOS_BUILD_ENABLE_DFX_RADAR
116 } // namespace
117 
118 enum PointerHotArea : int32_t {
119     TOP = 0,
120     BOTTOM = 1,
121     LEFT = 2,
122     RIGHT = 3,
123     TOP_LEFT = 4,
124     TOP_RIGHT = 5,
125     BOTTOM_LEFT = 6,
126     BOTTOM_RIGHT = 7,
127 };
128 
129 std::shared_ptr<IInputWindowsManager> IInputWindowsManager::instance_;
130 std::mutex IInputWindowsManager::mutex_;
131 
GetInstance()132 std::shared_ptr<IInputWindowsManager> IInputWindowsManager::GetInstance()
133 {
134     if (instance_ == nullptr) {
135         std::lock_guard<std::mutex> lock(mutex_);
136         if (instance_ == nullptr) {
137             instance_ = std::make_shared<InputWindowsManager>();
138         }
139     }
140     return instance_;
141 }
142 
DestroyInstance()143 void IInputWindowsManager::DestroyInstance()
144 {
145     std::lock_guard<std::mutex> lock(mutex_);
146     instance_.reset();
147 }
148 
InputWindowsManager()149 InputWindowsManager::InputWindowsManager() : bindInfo_(BIND_CFG_FILE_NAME)
150 {
151     MMI_HILOGI("Bind cfg file name:%{private}s", BIND_CFG_FILE_NAME.c_str());
152 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
153     lastWindowInfo_.id = -1;
154     lastWindowInfo_.pid = -1;
155     lastWindowInfo_.uid = -1;
156     lastWindowInfo_.agentWindowId = -1;
157     lastWindowInfo_.area = { 0, 0, 0, 0 };
158     lastWindowInfo_.flags = -1;
159     lastWindowInfo_.windowType = 0;
160     lastWindowInfo_.windowNameType = 0;
161     mouseDownInfo_.id = -1;
162     mouseDownInfo_.pid = -1;
163     mouseDownInfo_.uid = -1;
164     mouseDownInfo_.agentWindowId = -1;
165     mouseDownInfo_.area = { 0, 0, 0, 0 };
166     mouseDownInfo_.flags = -1;
167     mouseDownInfo_.windowType = 0;
168     mouseDownInfo_.windowNameType = 0;
169 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
170 #ifdef OHOS_BUILD_ENABLE_TOUCH
171     lastTouchWindowInfo_.id = -1;
172     lastTouchWindowInfo_.pid = -1;
173     lastTouchWindowInfo_.uid = -1;
174     lastTouchWindowInfo_.agentWindowId = -1;
175     lastTouchWindowInfo_.area = { 0, 0, 0, 0 };
176     lastTouchWindowInfo_.flags = -1;
177     lastTouchWindowInfo_.windowType = 0;
178     lastTouchWindowInfo_.windowNameType = 0;
179 #endif // OHOS_BUILD_ENABLE_TOUCH
180     displayGroupInfo_.groupId = MAIN_GROUPID;
181     displayGroupInfo_.type = GroupType::GROUP_DEFAULT;
182     displayGroupInfo_.focusWindowId = -1;
183     displayGroupInfoMap_[MAIN_GROUPID] = displayGroupInfo_;
184     displayGroupInfoMapTmp_[MAIN_GROUPID] = displayGroupInfo_;
185     captureModeInfoMap_[MAIN_GROUPID] = captureModeInfo_;
186     pointerDrawFlagMap_[MAIN_GROUPID] = pointerDrawFlag_;
187     mouseLocationMap_[MAIN_GROUPID] = mouseLocation_;
188     windowsPerDisplayMap_[MAIN_GROUPID] = windowsPerDisplay_;
189     lastPointerEventforWindowChangeMap_[MAIN_GROUPID] =  lastPointerEventforWindowChange_;
190     displayModeMap_[MAIN_GROUPID] = displayMode_;
191     lastDpiMap_[MAIN_GROUPID] = lastDpi_;
192     CursorPosition cursorPos = {};
193     cursorPosMap_[MAIN_GROUPID] = cursorPos;
194 }
195 
~InputWindowsManager()196 InputWindowsManager::~InputWindowsManager()
197 {
198     CALL_INFO_TRACE;
199 }
200 
DeviceStatusChanged(int32_t deviceId,const std::string & name,const std::string & sysUid,const std::string devStatus)201 void InputWindowsManager::DeviceStatusChanged(int32_t deviceId, const std::string &name, const std::string &sysUid,
202     const std::string devStatus)
203 {
204     CALL_INFO_TRACE;
205     if (devStatus == "add") {
206         bindInfo_.AddInputDevice(deviceId, name, sysUid);
207     } else {
208         bindInfo_.RemoveInputDevice(deviceId);
209     }
210 }
211 
Init(UDSServer & udsServer)212 void InputWindowsManager::Init(UDSServer& udsServer)
213 {
214     udsServer_ = &udsServer;
215     CHKPV(udsServer_);
216     bindInfo_.Load();
217 #ifdef OHOS_BUILD_ENABLE_POINTER
218     udsServer_->AddSessionDeletedCallback([this] (SessionPtr session) { return this->OnSessionLost(session); });
219     InitMouseDownInfo();
220 #endif // OHOS_BUILD_ENABLE_POINTER
221     INPUT_DEV_MGR->SetInputStatusChangeCallback(
222         [this] (int32_t deviceId, const std::string name, const std::string &sysUid, const std::string devStatus) {
223             return this->DeviceStatusChanged(deviceId, name, sysUid, devStatus);
224         }
225         );
226 }
227 
IgnoreTouchEvent(std::shared_ptr<PointerEvent> pointerEvent)228 bool InputWindowsManager::IgnoreTouchEvent(std::shared_ptr<PointerEvent> pointerEvent)
229 {
230     CHKPF(pointerEvent);
231     if (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHSCREEN ||
232         pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_CANCEL) {
233         return false;
234     }
235     PointerEvent::PointerItem pointer {};
236     if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointer)) {
237         MMI_HILOGE("Corrupted pointer event");
238         return false;
239     }
240     /* Fold status is indicated by 27th bit of long axis of touch. */
241     uint32_t longAxis = static_cast<uint32_t>(pointer.GetLongAxis());
242     if (cancelTouchStatus_) {
243         if (longAxis & FOLD_STATUS_MASK) {
244             // Screen in the process of folding, ignore this event
245             return true;
246         } else {
247             // Screen folding is complete
248             cancelTouchStatus_ = false;
249             return false;
250         }
251     } else if (longAxis & FOLD_STATUS_MASK) {
252         // The screen begins to collapse, reissues the cancel event, and ignores this event
253         MMI_HILOGI("Screen begins to collapse, reissue cancel event");
254         cancelTouchStatus_ = true;
255         ReissueCancelTouchEvent(pointerEvent);
256         return true;
257     }
258     return false;
259 }
260 
ReissueCancelTouchEvent(std::shared_ptr<PointerEvent> pointerEvent)261 void InputWindowsManager::ReissueCancelTouchEvent(std::shared_ptr<PointerEvent> pointerEvent)
262 {
263     CALL_INFO_TRACE;
264 #ifdef OHOS_BUILD_ENABLE_TOUCH
265     auto items = pointerEvent->GetAllPointerItems();
266     for (const auto &item : items) {
267         if (!item.IsPressed()) {
268             continue;
269         }
270         int32_t pointerId = item.GetPointerId();
271         auto tPointerEvent = std::make_shared<PointerEvent>(*pointerEvent);
272         tPointerEvent->SetPointerId(pointerId);
273         bool isDragging = extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN &&
274             (item.GetToolType() == PointerEvent::TOOL_TYPE_FINGER && extraData_.pointerId == pointerId);
275         if (isDragging) {
276             tPointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_CANCEL);
277         } else {
278             tPointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
279         }
280         tPointerEvent->SetActionTime(GetSysClockTime());
281         tPointerEvent->UpdateId();
282         auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler();
283         CHKPV(inputEventNormalizeHandler);
284         inputEventNormalizeHandler->HandleTouchEvent(tPointerEvent);
285         auto iter = touchItemDownInfos_.find(pointerId);
286         if (iter != touchItemDownInfos_.end()) {
287             iter->second.flag = false;
288         }
289     }
290 #endif // OHOS_BUILD_ENABLE_TOUCH
291 }
292 
293 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
InitMouseDownInfo()294 void InputWindowsManager::InitMouseDownInfo()
295 {
296     mouseDownInfo_.id = -1;
297     mouseDownInfo_.pid = -1;
298     mouseDownInfo_.defaultHotAreas.clear();
299     mouseDownInfo_.pointerHotAreas.clear();
300 }
301 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
302 
GetWindowGroupInfoByDisplayIdCopy(int32_t displayId) const303 const std::vector<WindowInfo> InputWindowsManager::GetWindowGroupInfoByDisplayIdCopy(int32_t displayId) const
304 {
305     CALL_DEBUG_ENTER;
306     int32_t groupId = FindDisplayGroupId(displayId);
307     if (displayId < 0) {
308         const auto& windoInfo = GetWindowInfoVector(groupId);
309         return windoInfo;
310     }
311     std::map<int32_t, WindowGroupInfo>& windowsPerDisplay =
312         const_cast<std::map<int32_t, WindowGroupInfo> &>(windowsPerDisplay_);
313 
314     const auto& iter = windowsPerDisplayMap_.find(groupId);
315     windowsPerDisplay = (iter != windowsPerDisplayMap_.end()) ? iter->second : windowsPerDisplay_;
316     const auto& it = windowsPerDisplay.find(displayId);
317     if (it == windowsPerDisplay.end()) {
318         MMI_HILOGD("GetWindowInfo displayId:%{public}d is null from windowGroupInfo_", displayId);
319         const auto& windoInfo = GetWindowInfoVector(groupId);
320         return windoInfo;
321     }
322     if (it->second.windowsInfo.empty()) {
323         MMI_HILOGW("GetWindowInfo displayId:%{public}d is empty", displayId);
324         const auto& windoInfo = GetWindowInfoVector(groupId);
325         return windoInfo;
326     }
327     return it->second.windowsInfo;
328 }
329 
GetWindowGroupInfoByDisplayId(int32_t displayId) const330 const std::vector<WindowInfo>& InputWindowsManager::GetWindowGroupInfoByDisplayId(int32_t displayId) const
331 {
332     CALL_DEBUG_ENTER;
333     int32_t groupId = FindDisplayGroupId(displayId);
334     if (displayId < 0) {
335         const auto& windoInfo = GetWindowInfoVector(groupId);
336         return windoInfo;
337     }
338     std::map<int32_t, WindowGroupInfo>& windowsPerDisplay =
339         const_cast<std::map<int32_t, WindowGroupInfo> &>(windowsPerDisplay_);
340 
341     const auto& iter = windowsPerDisplayMap_.find(groupId);
342     windowsPerDisplay = (iter != windowsPerDisplayMap_.end()) ? iter->second : windowsPerDisplay_;
343     const auto& it = windowsPerDisplay.find(displayId);
344     if (it == windowsPerDisplay.end()) {
345         MMI_HILOGD("GetWindowInfo displayId:%{public}d is null from windowGroupInfo_", displayId);
346         const auto& windoInfo = GetWindowInfoVector(groupId);
347         return windoInfo;
348     }
349     if (it->second.windowsInfo.empty()) {
350         MMI_HILOGW("GetWindowInfo displayId:%{public}d is empty", displayId);
351         const auto& windoInfo = GetWindowInfoVector(groupId);
352         return windoInfo;
353     }
354     return it->second.windowsInfo;
355 }
356 
CheckAppFocused(int32_t pid)357 bool InputWindowsManager::CheckAppFocused(int32_t pid)
358 {
359     int32_t focusWindowId = DEFAULT_VALUE;
360     for (const auto& item : displayGroupInfoMap_) {
361         focusWindowId = item.second.focusWindowId;
362         for (const auto& windowinfo : item.second.windowsInfo) {
363             if ((windowinfo.id == focusWindowId) && (windowinfo.pid == pid)) {
364                 return true;
365             } else if (windowinfo.id == focusWindowId) {
366                 MMI_HILOGW("CheckAppFocused focusWindowId:%{public}d, pid:%{public}d, windowinfo.pid:%{public}d",
367                     focusWindowId, pid, windowinfo.pid);
368                 break;
369             }
370         }
371     }
372     MMI_HILOGW("CheckAppFocused failed:%{public}d", focusWindowId);
373     return false;
374 }
375 
GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent)376 bool InputWindowsManager::GetCancelEventFlag(std::shared_ptr<PointerEvent> pointerEvent)
377 {
378     if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
379         auto iter = touchItemDownInfos_.find(pointerEvent->GetPointerId());
380         if (iter != touchItemDownInfos_.end()) {
381             return iter->second.flag;
382         }
383         return true;
384     } else if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE ||
385         pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHPAD) {
386         return mouseDownInfo_.pid == -1;
387     }
388     return false;
389 }
390 
391 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
AdjustFingerFlag(std::shared_ptr<PointerEvent> pointerEvent)392 bool InputWindowsManager::AdjustFingerFlag(std::shared_ptr<PointerEvent> pointerEvent)
393 {
394     CHKPF(pointerEvent);
395     if (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
396         return false;
397     }
398     auto iter = touchItemDownInfos_.find(pointerEvent->GetPointerId());
399     return (iter != touchItemDownInfos_.end() && !(iter->second.flag));
400 }
401 
GetClientFd(std::shared_ptr<PointerEvent> pointerEvent)402 int32_t InputWindowsManager::GetClientFd(std::shared_ptr<PointerEvent> pointerEvent)
403 {
404     CALL_DEBUG_ENTER;
405     CHKPR(pointerEvent, INVALID_FD);
406     const WindowInfo* windowInfo = nullptr;
407     auto iter = touchItemDownInfos_.find(pointerEvent->GetPointerId());
408     if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
409         if (iter != touchItemDownInfos_.end() && !(iter->second.flag)) {
410             MMI_HILOG_DISPATCHD("Drop event");
411             return INVALID_FD;
412         }
413     }
414     std::vector<WindowInfo> windowsInfo = GetWindowGroupInfoByDisplayId(pointerEvent->GetTargetDisplayId());
415     for (const auto &item : windowsInfo) {
416         bool checkUIExtentionWindow = false;
417         // Determine whether it is a safety sub window
418         for (auto &uiExtentionWindowInfo : item.uiExtentionWindowInfo) {
419             if (uiExtentionWindowInfo.id == pointerEvent->GetTargetWindowId()) {
420                 MMI_HILOGD("Find windowInfo by window id %{public}d", uiExtentionWindowInfo.id);
421                 windowInfo = &uiExtentionWindowInfo;
422                 checkUIExtentionWindow = true;
423                 break;
424             }
425         }
426         if (checkUIExtentionWindow) {
427             break;
428         }
429         bool checkWindow = (item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) == WindowInfo::FLAG_BIT_UNTOUCHABLE ||
430             !IsValidZorderWindow(item, pointerEvent);
431         if (checkWindow) {
432             MMI_HILOG_DISPATCHD("Skip the untouchable or invalid zOrder window to continue searching,"
433                 "window:%{public}d, flags:%{public}d", item.id, item.flags);
434             continue;
435         }
436         if (item.id == pointerEvent->GetTargetWindowId()) {
437             MMI_HILOG_DISPATCHD("find windowinfo by window id %{public}d", item.id);
438             windowInfo = &item;
439             break;
440         }
441     }
442 
443     if (windowInfo == nullptr && pointerEvent->GetTargetDisplayId() != firstBtnDownWindowInfo_.second) {
444         windowsInfo.clear();
445         windowsInfo = GetWindowGroupInfoByDisplayId(firstBtnDownWindowInfo_.second);
446         for (const auto &item : windowsInfo) {
447             bool checkUIExtentionWindow = false;
448             // Determine whether it is a safety sub window
449             for (auto &uiExtentionWindowInfo : item.uiExtentionWindowInfo) {
450                 if (uiExtentionWindowInfo.id == pointerEvent->GetTargetWindowId()) {
451                     MMI_HILOGD("Find windowInfo by window id %{public}d", uiExtentionWindowInfo.id);
452                     windowInfo = &uiExtentionWindowInfo;
453                     checkUIExtentionWindow = true;
454                     break;
455                 }
456             }
457             if (checkUIExtentionWindow) {
458                 break;
459             }
460             bool checkWindow = (item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) == WindowInfo::FLAG_BIT_UNTOUCHABLE ||
461                 !IsValidZorderWindow(item, pointerEvent);
462             if (checkWindow) {
463                 MMI_HILOG_DISPATCHD("Skip the untouchable or invalid zOrder window to continue searching,"
464                     "window:%{public}d, flags:%{public}d", item.id, item.flags);
465                 continue;
466             }
467             if (item.id == pointerEvent->GetTargetWindowId()) {
468                 MMI_HILOG_DISPATCHD("find windowinfo by window id %{public}d", item.id);
469                 windowInfo = &item;
470                 break;
471             }
472         }
473     }
474     if (windowInfo == nullptr) {
475         if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_CANCEL) {
476             dragPointerStyle_.id = DEFAULT_POINTER_STYLE;
477             CursorDrawingComponent::GetInstance().DrawPointerStyle(dragPointerStyle_);
478         }
479         MMI_HILOG_DISPATCHD("window info is null, pointerAction:%{public}d", pointerEvent->GetPointerAction());
480         if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_LEAVE_WINDOW ||
481             pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW) {
482             windowInfo = &lastWindowInfo_;
483         }
484     }
485     CHKPR(udsServer_, INVALID_FD);
486     if (windowInfo != nullptr) {
487         FoldScreenRotation(pointerEvent);
488         MMI_HILOG_DISPATCHD("get pid:%{public}d from idxPidMap", windowInfo->pid);
489         return udsServer_->GetClientFd(windowInfo->pid);
490     }
491     if (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_CANCEL &&
492         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_HOVER_CANCEL) {
493         MMI_HILOG_DISPATCHD("window info is null, so pointerEvent is dropped! return -1");
494         return udsServer_->GetClientFd(-1);
495     }
496     int32_t pid = -1;
497     if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
498         if (iter != touchItemDownInfos_.end()) {
499             MMI_HILOG_DISPATCHI("Cant not find pid");
500             pid = iter->second.window.pid;
501             iter->second.flag = false;
502             MMI_HILOG_DISPATCHD("touchscreen occurs, new pid:%{public}d", pid);
503         }
504     }
505 #ifdef OHOS_BUILD_ENABLE_POINTER
506     if ((pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) ||
507         (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_CROWN)) {
508         if (mouseDownInfo_.pid != -1) {
509             pid = GetWindowPid(mouseDownInfo_.agentWindowId);
510             if (pid < 0) {
511                 pid = mouseDownInfo_.pid;
512             }
513             MMI_HILOGD("mouseevent occurs, update the pid:%{public}d", pid);
514             InitMouseDownInfo();
515         } else if (axisBeginWindowInfo_ && axisBeginWindowInfo_->pid != -1) {
516             pid = GetWindowPid(axisBeginWindowInfo_->agentWindowId);
517             if (pid < 0) {
518                 pid = axisBeginWindowInfo_->pid;
519             }
520             MMI_HILOGD("The axisBeginEvent occurs, update the pid:%{public}d", pid);
521             axisBeginWindowInfo_ = std::nullopt;
522         }
523     }
524 #endif // OHOS_BUILD_ENABLE_POINTER
525     MMI_HILOGD("Get clientFd by %{public}d", pid);
526     return udsServer_->GetClientFd(pid);
527 }
528 
FoldScreenRotation(std::shared_ptr<PointerEvent> pointerEvent)529 void InputWindowsManager::FoldScreenRotation(std::shared_ptr<PointerEvent> pointerEvent)
530 {
531     CALL_DEBUG_ENTER;
532     CHKPV(pointerEvent);
533     auto iter = touchItemDownInfos_.find(pointerEvent->GetPointerId());
534     if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
535         if (iter == touchItemDownInfos_.end()) {
536             MMI_HILOG_DISPATCHD("Unable to find finger information for touch.pointerId:%{public}d",
537                 pointerEvent->GetPointerId());
538             return;
539         }
540     }
541     auto displayId = pointerEvent->GetTargetDisplayId();
542     Direction physicDisplayInfoDirection = GetLogicalPositionDirection(displayId);
543     if (lastDirection_.first != displayId || lastDirection_.second == static_cast<Direction>(-1)) {
544         lastDirection_ = std::make_pair(displayId, physicDisplayInfoDirection);
545         return;
546     }
547     if (physicDisplayInfoDirection != lastDirection_.second) {
548         if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) {
549             PointerEvent::PointerItem item;
550             if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), item)) {
551                 MMI_HILOGE("Get pointer item failed. pointer:%{public}d", pointerEvent->GetPointerId());
552                 lastDirection_ = std::make_pair(displayId, physicDisplayInfoDirection);
553                 return;
554             }
555             if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE && !(item.IsPressed())) {
556                 lastDirection_ = std::make_pair(displayId, physicDisplayInfoDirection);
557                 return;
558             }
559         }
560         if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_MOVE ||
561             pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_HOVER_MOVE) {
562             int32_t pointerAction = pointerEvent->GetPointerAction();
563             if (IsAccessibilityFocusEvent(pointerEvent)) {
564                     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_CANCEL);
565             } else {
566                 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
567             }
568             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
569             pointerEvent->SetOriginPointerAction(pointerAction);
570             MMI_HILOG_DISPATCHI("touch event send cancel");
571             if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
572                 iter->second.flag = false;
573             }
574         }
575     }
576     lastDirection_ = std::make_pair(displayId, physicDisplayInfoDirection);
577 }
578 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
579 
FindTargetDisplayGroupInfo(int32_t displayId)580 OLD::DisplayGroupInfo& InputWindowsManager::FindTargetDisplayGroupInfo(int32_t displayId)
581 {
582     for (auto& it : displayGroupInfoMap_) {
583         for (const auto& item : it.second.displaysInfo) {
584             if (item.id == displayId) {
585                 return it.second;
586             }
587         }
588     }
589     return GetDefaultDisplayGroupInfo();
590 }
591 
FindDisplayGroupId(int32_t displayId) const592 int32_t InputWindowsManager::FindDisplayGroupId(int32_t displayId) const
593 {
594     for (const auto& it : displayGroupInfoMap_) {
595         for (const auto& item : it.second.displaysInfo) {
596             if (item.id == displayId) {
597                 return it.second.groupId;
598             }
599         }
600     }
601     return DEFAULT_GROUP_ID;
602 }
603 
GetDefaultDisplayGroupInfo()604 OLD::DisplayGroupInfo& InputWindowsManager::GetDefaultDisplayGroupInfo()
605 {
606     for (auto &item : displayGroupInfoMap_) {
607         if (item.second.type == GroupType::GROUP_DEFAULT) {
608             return item.second;
609         }
610     }
611     return displayGroupInfo_;
612 }
613 
GetConstMainDisplayGroupInfo() const614 const OLD::DisplayGroupInfo& InputWindowsManager::GetConstMainDisplayGroupInfo() const
615 {
616     for (auto &it : displayGroupInfoMap_)
617         if (it.second.type == GroupType::GROUP_DEFAULT) {
618             return it.second;
619         }
620     return displayGroupInfo_;
621 }
622 
FindDisplayGroupInfo(int32_t displayId) const623 const OLD::DisplayGroupInfo& InputWindowsManager::FindDisplayGroupInfo(int32_t displayId) const {
624     for (auto& it : displayGroupInfoMap_) {
625         for (auto& item : it.second.displaysInfo) {
626             if (item.id == displayId) {
627                 return it.second;
628             }
629         }
630     }
631     return displayGroupInfo_;
632 }
633 
634 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
UpdateTarget(std::shared_ptr<KeyEvent> keyEvent)635 std::vector<std::pair<int32_t, TargetInfo>> InputWindowsManager::UpdateTarget(std::shared_ptr<KeyEvent> keyEvent)
636 {
637     CALL_DEBUG_ENTER;
638     if (!isParseConfig_) {
639         ParseConfig();
640         isParseConfig_ = true;
641     }
642     std::vector<std::pair<int32_t, TargetInfo>> secSubWindowTargets;
643     if (keyEvent == nullptr) {
644         MMI_HILOG_DISPATCHE("keyEvent is nullptr");
645         return secSubWindowTargets;
646     }
647     auto secSubWindows = GetPidAndUpdateTarget(keyEvent);
648     for (const auto &item : secSubWindows) {
649         int32_t fd = INVALID_FD;
650         int32_t pid = item.first;
651         if (pid <= 0) {
652             MMI_HILOG_DISPATCHE("Invalid pid:%{public}d", pid);
653             continue;
654         }
655         CHKPC(udsServer_);
656         fd = udsServer_->GetClientFd(pid);
657         if (fd < 0) {
658             MMI_HILOG_DISPATCHE("The windowPid:%{public}d matching fd:%{public}d is invalid", pid, fd);
659             continue;
660         }
661         secSubWindowTargets.emplace_back(std::make_pair(fd, item.second));
662     }
663     return secSubWindowTargets;
664 }
665 
HandleKeyEventWindowId(std::shared_ptr<KeyEvent> keyEvent)666 void InputWindowsManager::HandleKeyEventWindowId(std::shared_ptr<KeyEvent> keyEvent)
667 {
668     CALL_DEBUG_ENTER;
669     CHKPV(keyEvent);
670     int32_t groupId = FindDisplayGroupId(keyEvent->GetTargetDisplayId());
671     int32_t focusWindowId = GetFocusWindowId(groupId);
672     std::vector<WindowInfo> windowsInfo = GetWindowGroupInfoByDisplayId(keyEvent->GetTargetDisplayId());
673     for (auto &item : windowsInfo) {
674         if (item.id == focusWindowId) {
675             keyEvent->SetTargetWindowId(item.id);
676             keyEvent->SetAgentWindowId(item.agentWindowId);
677             if (item.privacyMode == SecureFlag::PRIVACY_MODE) {
678                 keyEvent->AddFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE);
679             }
680             return;
681         }
682     }
683 }
684 
ReissueEvent(std::shared_ptr<KeyEvent> keyEvent,int32_t focusWindowId)685 void InputWindowsManager::ReissueEvent(std::shared_ptr<KeyEvent> keyEvent, int32_t focusWindowId)
686 {
687     CHKPV(keyEvent);
688     if (keyEvent->GetKeyAction() != KeyEvent::KEY_ACTION_CANCEL && focusWindowId_ != -1 &&
689         focusWindowId_ != focusWindowId && keyEvent->IsRepeatKey()) {
690         auto keyEventReissue = std::make_shared<KeyEvent>(*keyEvent);
691         auto keyItem = keyEventReissue->GetKeyItems();
692         for (auto item = keyItem.begin(); item != keyItem.end(); ++item) {
693             item->SetPressed(false);
694         }
695         keyEventReissue->SetKeyItem(keyItem);
696         keyEventReissue->UpdateId();
697         keyEventReissue->SetAction(KeyEvent::KEY_ACTION_CANCEL);
698         keyEventReissue->SetKeyAction(KeyEvent::KEY_ACTION_CANCEL);
699         keyEventReissue->SetTargetWindowId(focusWindowId_);
700         keyEventReissue->SetAgentWindowId(focusWindowId_);
701 
702         auto eventDispatchHandler = InputHandler->GetEventDispatchHandler();
703         auto udServer = InputHandler->GetUDSServer();
704         CHKPV(udServer);
705         auto fd = udServer->GetClientFd(GetWindowPid(focusWindowId_));
706         MMI_HILOG_DISPATCHI("Out focus window:%{public}d is replaced by window:%{public}d",
707             focusWindowId_, focusWindowId);
708         if (eventDispatchHandler != nullptr && udServer != nullptr) {
709             eventDispatchHandler->DispatchKeyEvent(fd, *udServer, keyEventReissue);
710         }
711     }
712     focusWindowId_ = focusWindowId;
713 }
714 #endif // OHOS_BUILD_ENABLE_KEYBOARD
715 
GetDisplayId(std::shared_ptr<InputEvent> inputEvent) const716 int32_t InputWindowsManager::GetDisplayId(std::shared_ptr<InputEvent> inputEvent) const
717 {
718     CHKPR(inputEvent, RET_ERR);
719     int32_t displayId = inputEvent->GetTargetDisplayId();
720     if (displayId < 0) {
721         MMI_HILOGD("Target display is -1");
722         int32_t groupId = FindDisplayGroupId(displayId);
723             const auto iter = displayGroupInfoMap_.find(groupId);
724             if (iter != displayGroupInfoMap_.end()) {
725                 if (iter->second.displaysInfo.empty()) {
726                     return displayId;
727                 }
728                 displayId = iter->second.displaysInfo[0].id;
729             } else {
730                 if (displayGroupInfo_.displaysInfo.empty()) {
731                     return displayId;
732                 }
733                 displayId = displayGroupInfo_.displaysInfo[0].id;
734             }
735         inputEvent->SetTargetDisplayId(displayId);
736     }
737     return displayId;
738 }
739 
740 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
GetClientFd(std::shared_ptr<PointerEvent> pointerEvent,int32_t windowId)741 int32_t InputWindowsManager::GetClientFd(std::shared_ptr<PointerEvent> pointerEvent, int32_t windowId)
742 {
743     CALL_DEBUG_ENTER;
744     CHKPR(udsServer_, INVALID_FD);
745     CHKPR(pointerEvent, INVALID_FD);
746     const WindowInfo* windowInfo = nullptr;
747     std::vector<WindowInfo> windowInfos = GetWindowGroupInfoByDisplayId(pointerEvent->GetTargetDisplayId());
748     for (const auto &item : windowInfos) {
749         bool checkUIExtentionWindow = false;
750         // Determine whether it is a safety sub window
751         for (const auto &uiExtentionWindowInfo : item.uiExtentionWindowInfo) {
752             if (uiExtentionWindowInfo.id == windowId) {
753                 MMI_HILOGD("Find windowInfo by window id %{public}d", uiExtentionWindowInfo.id);
754                 windowInfo = &uiExtentionWindowInfo;
755                 checkUIExtentionWindow = true;
756                 break;
757             }
758         }
759         if (checkUIExtentionWindow) {
760             break;
761         }
762         bool checkWindow = (item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) == WindowInfo::FLAG_BIT_UNTOUCHABLE ||
763             !IsValidZorderWindow(item, pointerEvent);
764         if (checkWindow) {
765             MMI_HILOG_DISPATCHD("Skip the untouchable or invalid zOrder window to continue searching,"
766                 "window:%{public}d, flags:%{public}d", item.id, item.flags);
767             continue;
768         }
769         if (item.id == windowId) {
770             MMI_HILOGD("Find windowInfo by window id %{public}d", item.id);
771             windowInfo = &item;
772             break;
773         }
774     }
775     if (windowInfo == nullptr) {
776         MMI_HILOGE("WindowInfo is nullptr, pointerAction:%{public}d", pointerEvent->GetPointerAction());
777         return INVALID_FD;
778     }
779     MMI_HILOGD("Get pid:%{public}d from idxPidMap", windowInfo->pid);
780     return udsServer_->GetClientFd(windowInfo->pid);
781 }
782 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
783 
784 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
GetPidAndUpdateTarget(std::shared_ptr<KeyEvent> keyEvent)785 std::vector<std::pair<int32_t, TargetInfo>> InputWindowsManager::GetPidAndUpdateTarget(
786     std::shared_ptr<KeyEvent> keyEvent)
787 {
788     CALL_DEBUG_ENTER;
789     std::vector<std::pair<int32_t, TargetInfo>> secSubWindows;
790     if (keyEvent == nullptr) {
791         MMI_HILOG_DISPATCHE("keyEvent is nullptr");
792         return secSubWindows;
793     }
794     int32_t groupId = FindDisplayGroupId(keyEvent->GetTargetDisplayId());
795     const int32_t focusWindowId = GetFocusWindowId(groupId);
796     if (GetHardCursorEnabled()) {
797         UpdateKeyEventDisplayId(keyEvent, focusWindowId, groupId);
798     }
799     WindowInfo* windowInfo = nullptr;
800     std::vector<WindowInfo> windowsInfo = GetWindowGroupInfoByDisplayId(keyEvent->GetTargetDisplayId());
801     bool isUIExtention = false;
802     auto iter = windowsInfo.begin();
803     for (; iter != windowsInfo.end(); ++iter) {
804         if (iter->id == focusWindowId) {
805             windowInfo = &(*iter);
806             if (!iter->uiExtentionWindowInfo.empty() && !IsOnTheWhitelist(keyEvent)) {
807                 isUIExtention = true;
808             }
809             break;
810         }
811     }
812     if (windowInfo == nullptr) {
813         MMI_HILOG_DISPATCHE("windowInfo is nullptr");
814         return secSubWindows;
815     }
816 #ifdef OHOS_BUILD_ENABLE_ANCO
817     if (IsAncoWindowFocus(*windowInfo)) {
818         MMI_HILOG_DISPATCHD("focusWindowId:%{public}d is anco window", focusWindowId);
819         return secSubWindows;
820     }
821 #endif // OHOS_BUILD_ENABLE_ANCO
822     TargetInfo targetInfo = { windowInfo->privacyMode, windowInfo->id, windowInfo->agentWindowId };
823     secSubWindows.emplace_back(std::make_pair(windowInfo->pid, targetInfo));
824     if (isUIExtention) {
825         for (const auto &item : iter->uiExtentionWindowInfo) {
826             if (item.privacyUIFlag) {
827                 MMI_HILOG_DISPATCHD("security sub windowId:%{public}d,pid:%{public}d", item.id, item.pid);
828                 targetInfo.privacyMode = item.privacyMode;
829                 targetInfo.id = item.id;
830                 targetInfo.agentWindowId = item.agentWindowId;
831                 secSubWindows.emplace_back(std::make_pair(item.pid, targetInfo));
832             }
833         }
834     }
835     return secSubWindows;
836 }
837 #endif // OHOS_BUILD_ENABLE_KEYBOARD
838 
GetWindowPid(int32_t windowId) const839 int32_t InputWindowsManager::GetWindowPid(int32_t windowId) const
840 {
841     CALL_DEBUG_ENTER;
842     for (const auto &groupItem : displayGroupInfoMap_) {
843         for (const auto &item : groupItem.second.windowsInfo) {
844             MMI_HILOGD("Get windowId:%{public}d", item.id);
845             if (item.id == windowId) {
846                 return item.pid;
847             }
848             for (const auto &uiExtentionWindow : item.uiExtentionWindowInfo) {
849                 CHKCC(uiExtentionWindow.id == windowId);
850                 return uiExtentionWindow.pid;
851             }
852         }
853     }
854     return INVALID_PID;
855 }
856 
GetWindowPid(int32_t windowId,const std::vector<WindowInfo> & windowsInfo) const857 int32_t InputWindowsManager::GetWindowPid(int32_t windowId, const std::vector<WindowInfo> &windowsInfo) const
858 {
859     int32_t windowPid = INVALID_PID;
860     for (const auto &item : windowsInfo) {
861         if (item.id == windowId) {
862             windowPid = item.pid;
863             break;
864         }
865     }
866     return windowPid;
867 }
868 
CheckFocusWindowChange(const OLD::DisplayGroupInfo & displayGroupInfo)869 void InputWindowsManager::CheckFocusWindowChange(const OLD::DisplayGroupInfo &displayGroupInfo)
870 {
871     const int32_t oldFocusWindowId = GetFocusWindowId(displayGroupInfo.groupId);
872     const int32_t newFocusWindowId = displayGroupInfo.focusWindowId;
873     if (oldFocusWindowId == newFocusWindowId) {
874         return;
875     }
876     const int32_t oldFocusWindowPid = GetWindowPid(oldFocusWindowId);
877     const int32_t newFocusWindowPid = GetWindowPid(newFocusWindowId, displayGroupInfo.windowsInfo);
878     DfxHisysevent::OnFocusWindowChanged(oldFocusWindowId, newFocusWindowId, oldFocusWindowPid, newFocusWindowPid);
879 }
880 
CheckZorderWindowChange(const std::vector<WindowInfo> & oldWindowsInfo,const std::vector<WindowInfo> & newWindowsInfo)881 void InputWindowsManager::CheckZorderWindowChange(const std::vector<WindowInfo> &oldWindowsInfo,
882     const std::vector<WindowInfo> &newWindowsInfo)
883 {
884     int32_t oldZorderFirstWindowId = -1;
885     int32_t newZorderFirstWindowId = -1;
886     if (!oldWindowsInfo.empty()) {
887         oldZorderFirstWindowId = oldWindowsInfo[0].id;
888     }
889     if (!newWindowsInfo.empty()) {
890         newZorderFirstWindowId = newWindowsInfo[0].id;
891     }
892     if (oldZorderFirstWindowId == newZorderFirstWindowId) {
893         return;
894     }
895     const int32_t oldZorderFirstWindowPid = GetWindowPid(oldZorderFirstWindowId);
896     const int32_t newZorderFirstWindowPid = GetWindowPid(newZorderFirstWindowId, newWindowsInfo);
897     DfxHisysevent::OnZorderWindowChanged(oldZorderFirstWindowId, newZorderFirstWindowId,
898         oldZorderFirstWindowPid, newZorderFirstWindowPid);
899 }
900 
UpdateDisplayIdAndName()901 void InputWindowsManager::UpdateDisplayIdAndName()
902 {
903     CALL_DEBUG_ENTER;
904     using IdNames = std::set<std::pair<uint64_t, std::string>>;
905     IdNames newInfo;
906     auto &DisplaysInfo = GetDisplayInfoVector(MAIN_GROUPID);
907     for (const auto &item : DisplaysInfo) {
908         newInfo.insert(std::make_pair(item.rsId, item.uniq));
909     }
910     auto oldInfo = bindInfo_.GetDisplayIdNames();
911     if (newInfo == oldInfo) {
912         return;
913     }
914     for (auto it = oldInfo.begin(); it != oldInfo.end();) {
915         if (newInfo.find(*it) == newInfo.end()) {
916             bindInfo_.RemoveDisplay(it->first);
917             oldInfo.erase(it++);
918         } else {
919             ++it;
920         }
921     }
922     for (const auto &item : newInfo) {
923         if (item.first >= HICAR_MIN_DISPLAY_ID) {
924             MMI_HILOGI("Displayinfo id:%{public}" PRIu64 ", name:%{public}s", item.first, item.second.c_str());
925             continue;
926         }
927         if (!bindInfo_.IsDisplayAdd(item.first, item.second)) {
928             bindInfo_.AddDisplay(item.first, item.second);
929         }
930     }
931 }
932 
GetDisplayBindInfo(DisplayBindInfos & infos)933 int32_t InputWindowsManager::GetDisplayBindInfo(DisplayBindInfos &infos)
934 {
935     CALL_DEBUG_ENTER;
936     return bindInfo_.GetDisplayBindInfo(infos);
937 }
938 
SetDisplayBind(int32_t deviceId,int32_t displayId,std::string & msg)939 int32_t InputWindowsManager::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg)
940 {
941     CALL_DEBUG_ENTER;
942     return bindInfo_.SetDisplayBind(deviceId, displayId, msg);
943 }
944 
UpdateCaptureMode(const OLD::DisplayGroupInfo & displayGroupInfo)945 void InputWindowsManager::UpdateCaptureMode(const OLD::DisplayGroupInfo &displayGroupInfo)
946 {
947     auto &WindowInfo = GetWindowInfoVector(displayGroupInfo.groupId);
948     int32_t focusWindowId = GetFocusWindowId(displayGroupInfo.groupId);
949     if (displayGroupInfo.windowsInfo.empty()) {
950         MMI_HILOGW("windowsInfo is empty");
951         return;
952     }
953     if (WindowInfo.empty()) {
954         MMI_HILOGW("windowsInfo is empty");
955         return;
956     }
957     CaptureModeInfo captureModeInfo;
958     auto itr = captureModeInfoMap_.find(displayGroupInfo.groupId);
959     if (itr != captureModeInfoMap_.end()) {
960         captureModeInfo = itr->second;
961     }
962     if (captureModeInfo.isCaptureMode && !WindowInfo.empty() &&
963         ((focusWindowId != displayGroupInfo.focusWindowId) ||
964         (WindowInfo[0].id != displayGroupInfo.windowsInfo[0].id))) {
965         captureModeInfoMap_[displayGroupInfo.groupId].isCaptureMode = false;
966     }
967 }
968 
IsFocusedSession(int32_t session) const969 bool InputWindowsManager::IsFocusedSession(int32_t session) const
970 {
971     if (session >= 0) {
972         for (auto &curGroupInfo : displayGroupInfoMap_) {
973             if (session == GetWindowPid(curGroupInfo.second.focusWindowId)) {
974                 return true;
975             }
976         }
977     }
978     return false;
979 }
980 
UpdateWindowInfo(const WindowGroupInfo & windowGroupInfo)981 void InputWindowsManager::UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo)
982 {
983     CALL_DEBUG_ENTER;
984     PrintWindowGroupInfo(windowGroupInfo);
985     std::map<int32_t, std::vector<WindowInfo>> groupWindows;
986     for (const auto &item : windowGroupInfo.windowsInfo) {
987         groupWindows[item.groupId].emplace_back(item);
988     }
989     WindowGroupInfo windowGroupInfoTmp;
990     windowGroupInfoTmp.focusWindowId = windowGroupInfo.focusWindowId;
991     windowGroupInfoTmp.displayId = windowGroupInfo.displayId;
992     int32_t focusWid = 0;
993     for (const auto &it : groupWindows) {
994         if (it.first != MAIN_GROUPID) {
995             focusWid = GetFocusWindowId(it.first);
996             windowGroupInfoTmp.focusWindowId = focusWid;
997         }
998         windowGroupInfoTmp.windowsInfo = it.second;
999 #ifdef OHOS_BUILD_ENABLE_ANCO
1000         if (windowGroupInfoTmp.windowsInfo.size() == SHELL_WINDOW_COUNT
1001             && IsAncoWindow(windowGroupInfoTmp.windowsInfo[0])) {
1002             return UpdateShellWindow(windowGroupInfoTmp.windowsInfo[0]);
1003         }
1004 #endif // OHOS_BUILD_ENABLE_ANCO
1005         OLD::DisplayGroupInfo displayGroupInfo;
1006         const auto &iter = displayGroupInfoMapTmp_.find(it.first);
1007         displayGroupInfo = (iter != displayGroupInfoMapTmp_.end()) ? iter->second : GetDefaultDisplayGroupInfo();
1008         if (it.first != MAIN_GROUPID) {
1009             displayGroupInfo.focusWindowId = focusWid;
1010         }
1011         for (const auto &item : windowGroupInfoTmp.windowsInfo) {
1012             UpdateDisplayInfoByIncrementalInfo(item, displayGroupInfo);
1013         }
1014 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1015         bool pointDrawFlag = NeedUpdatePointDrawFlag(windowGroupInfoTmp.windowsInfo);
1016         pointerDrawFlagMap_[displayGroupInfo.groupId] = pointDrawFlag;
1017 
1018 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1019 
1020 #ifdef OHOS_BUILD_ENABLE_ANCO
1021         UpdateWindowInfoExt(windowGroupInfoTmp, displayGroupInfo);
1022 #endif // OHOS_BUILD_ENABLE_ANCO
1023         UpdateDisplayInfoExtIfNeed(displayGroupInfo, false);
1024     }
1025 }
1026 
UpdateDisplayInfoExtIfNeed(OLD::DisplayGroupInfo & displayGroupInfo,bool needUpdateDisplayExt)1027 void InputWindowsManager::UpdateDisplayInfoExtIfNeed(OLD::DisplayGroupInfo &displayGroupInfo, bool needUpdateDisplayExt)
1028 {
1029     UpdateDisplayInfo(displayGroupInfo);
1030 #ifdef OHOS_BUILD_ENABLE_ANCO
1031     if (needUpdateDisplayExt) {
1032         UpdateDisplayInfoExt(displayGroupInfo);
1033     }
1034 #endif // OHOS_BUILD_ENABLE_ANCO
1035     if (displayGroupInfo.displaysInfo.empty()) {
1036         MMI_HILOGE("displaysInfo is empty");
1037         return;
1038     }
1039     if (displayGroupInfo.groupId != DEFAULT_GROUP_ID) {
1040         MMI_HILOGD("groupId:%{public}d", displayGroupInfo.groupId);
1041         return;
1042     }
1043     auto physicDisplayInfo = GetPhysicalDisplay(displayGroupInfo.displaysInfo[0].id);
1044     CHKPV(physicDisplayInfo);
1045 #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING
1046     TOUCH_DRAWING_MGR->UpdateDisplayInfo(*physicDisplayInfo);
1047     TOUCH_DRAWING_MGR->RotationScreen();
1048 #endif // #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING
1049 }
1050 
UpdateDisplayInfoByIncrementalInfo(const WindowInfo & window,OLD::DisplayGroupInfo & displayGroupInfo)1051 void InputWindowsManager::UpdateDisplayInfoByIncrementalInfo(const WindowInfo &window,
1052     OLD::DisplayGroupInfo &displayGroupInfo)
1053 {
1054     CALL_DEBUG_ENTER;
1055     switch (window.action) {
1056         case WINDOW_UPDATE_ACTION::ADD:
1057         case WINDOW_UPDATE_ACTION::ADD_END: {
1058             auto id = window.id;
1059             auto pos = std::find_if(std::begin(displayGroupInfo.windowsInfo), std::end(displayGroupInfo.windowsInfo),
1060                 [id](const auto& item) { return item.id == id; });
1061             if (pos == std::end(displayGroupInfo.windowsInfo)) {
1062                 displayGroupInfo.windowsInfo.emplace_back(window);
1063             } else {
1064                 *pos = window;
1065             }
1066             break;
1067         }
1068         case WINDOW_UPDATE_ACTION::DEL: {
1069             auto oldWindow = displayGroupInfo.windowsInfo.begin();
1070             while (oldWindow != displayGroupInfo.windowsInfo.end()) {
1071                 if (oldWindow->id == window.id) {
1072                     oldWindow = displayGroupInfo.windowsInfo.erase(oldWindow);
1073                 } else {
1074                     oldWindow++;
1075                 }
1076             }
1077             break;
1078         }
1079         case WINDOW_UPDATE_ACTION::CHANGE: {
1080             auto id = window.id;
1081             auto pos = std::find_if(std::begin(displayGroupInfo.windowsInfo), std::end(displayGroupInfo.windowsInfo),
1082                 [id](const auto& item) { return item.id == id; });
1083             if (pos != std::end(displayGroupInfo.windowsInfo)) {
1084                 *pos = window;
1085             }
1086             break;
1087         }
1088         default: {
1089             MMI_HILOGI("WINDOW_UPDATE_ACTION is action:%{public}d", window.action);
1090             break;
1091         }
1092     }
1093 }
1094 
UpdateWindowsInfoPerDisplay(const OLD::DisplayGroupInfo & displayGroupInfo)1095 void InputWindowsManager::UpdateWindowsInfoPerDisplay(const OLD::DisplayGroupInfo &displayGroupInfo)
1096 {
1097     CALL_DEBUG_ENTER;
1098     std::map<int32_t, WindowGroupInfo> windowsPerDisplay;
1099     int32_t groupId = displayGroupInfo.groupId;
1100     for (const auto &window : displayGroupInfo.windowsInfo) {
1101         auto it = windowsPerDisplay.find(window.displayId);
1102         if (it == windowsPerDisplay.end()) {
1103             windowsPerDisplay[window.displayId] = WindowGroupInfo {-1, window.displayId, {window}};
1104         } else {
1105             it->second.windowsInfo.emplace_back(window);
1106         }
1107         if (displayGroupInfo.focusWindowId == window.id) {
1108             windowsPerDisplay[window.displayId].focusWindowId = window.id;
1109         }
1110     }
1111     for (auto iter : windowsPerDisplay) {
1112         std::sort(iter.second.windowsInfo.begin(), iter.second.windowsInfo.end(),
1113             [](const WindowInfo &lwindow, const WindowInfo &rwindow) -> bool {
1114             return lwindow.zOrder > rwindow.zOrder;
1115         });
1116     }
1117     std::map<int32_t, WindowGroupInfo>& windowsPerDisplayTmp = windowsPerDisplay_;
1118 
1119     const auto& iter = windowsPerDisplayMap_.find(groupId);
1120     windowsPerDisplayTmp = (iter != windowsPerDisplayMap_.end()) ? iter->second : windowsPerDisplay_;
1121     for (const auto &item : windowsPerDisplay) {
1122         int32_t displayId = item.first;
1123         if (windowsPerDisplayTmp.find(displayId) != windowsPerDisplayTmp.end()) {
1124             CheckZorderWindowChange(windowsPerDisplayTmp[displayId].windowsInfo, item.second.windowsInfo);
1125         }
1126     }
1127 
1128     windowsPerDisplayMap_[groupId] = windowsPerDisplay;
1129     windowsPerDisplay_ = windowsPerDisplay;
1130 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
1131     for (const auto &window : displayGroupInfo.windowsInfo) {
1132         if (window.windowType == static_cast<int32_t>(Rosen::WindowType::WINDOW_TYPE_TRANSPARENT_VIEW)) {
1133             MMI_HILOGI("Transparent window of UNI-CUBIC emerges, redirect touches");
1134             if (auto touchGestureMgr = touchGestureMgr_.lock(); touchGestureMgr != nullptr) {
1135                 touchGestureMgr->HandleGestureWindowEmerged(window.id, lastPointerEventforGesture_);
1136             }
1137             break;
1138         }
1139     }
1140 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
1141 }
1142 
UpdateWindowInfo(OLD::DisplayGroupInfo & displayGroupInfo)1143 WINDOW_UPDATE_ACTION InputWindowsManager::UpdateWindowInfo(OLD::DisplayGroupInfo &displayGroupInfo)
1144 {
1145     auto action = WINDOW_UPDATE_ACTION::ADD_END;
1146     if (!displayGroupInfo.windowsInfo.empty()) {
1147         action = displayGroupInfo.windowsInfo.back().action;
1148     }
1149     MMI_HILOGD("Current action is:%{public}d", action);
1150 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1151     pointerDrawFlagMap_[displayGroupInfo.groupId] = NeedUpdatePointDrawFlag(displayGroupInfo.windowsInfo);
1152 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1153     std::sort(displayGroupInfo.windowsInfo.begin(), displayGroupInfo.windowsInfo.end(),
1154         [](const WindowInfo &lwindow, const WindowInfo &rwindow) -> bool {
1155         return lwindow.zOrder > rwindow.zOrder;
1156     });
1157     if (GetHardCursorEnabled()) {
1158         for (auto &windowInfo : displayGroupInfo.windowsInfo) {
1159             if (windowInfo.isDisplayCoord) {
1160                 continue;
1161             }
1162             auto displayInfo = GetPhysicalDisplay(windowInfo.displayId, displayGroupInfo);
1163             CHKPR(displayInfo, action);
1164             ChangeWindowArea(displayInfo->x, displayInfo->y, windowInfo);
1165             if (!windowInfo.uiExtentionWindowInfo.empty()) {
1166                 for (auto &item : windowInfo.uiExtentionWindowInfo) {
1167                     ChangeWindowArea(displayInfo->x, displayInfo->y, item);
1168                 }
1169             }
1170             windowInfo.isDisplayCoord = true;
1171         }
1172     }
1173     return action;
1174 }
1175 
ChangeWindowArea(int32_t x,int32_t y,WindowInfo & windowInfo)1176 void InputWindowsManager::ChangeWindowArea(int32_t x, int32_t y, WindowInfo &windowInfo)
1177 {
1178     windowInfo.area.x += x;
1179     windowInfo.area.y += y;
1180     for (auto &area : windowInfo.defaultHotAreas) {
1181         area.x += x;
1182         area.y += y;
1183     }
1184     for (auto &area : windowInfo.pointerHotAreas) {
1185         area.x += x;
1186         area.y += y;
1187     }
1188 }
1189 
GetMainScreenDisplayInfo(const std::vector<OLD::DisplayInfo> & displaysInfo,OLD::DisplayInfo & mainScreenDisplayInfo) const1190 int32_t InputWindowsManager::GetMainScreenDisplayInfo(const std::vector<OLD::DisplayInfo> &displaysInfo,
1191     OLD::DisplayInfo &mainScreenDisplayInfo) const
1192 {
1193     CALL_DEBUG_ENTER;
1194     if (displaysInfo.empty()) {
1195         MMI_HILOGE("displaysInfo doesn't contain displayInfo");
1196         return RET_ERR;
1197     }
1198     for (const OLD::DisplayInfo& display : displaysInfo) {
1199         if (display.displaySourceMode == OHOS::MMI::DisplaySourceMode::SCREEN_MAIN) {
1200             mainScreenDisplayInfo = display;
1201             return RET_OK;
1202         }
1203     }
1204     MMI_HILOGD("displayGroupInfo has no main screen, get displayGroupInfo.displaysInfo[0] back");
1205     mainScreenDisplayInfo = displaysInfo[0];
1206     return RET_OK;
1207 }
1208 
SendBackCenterPointerEevent(const CursorPosition & cursorPos)1209 void InputWindowsManager::SendBackCenterPointerEevent(const CursorPosition &cursorPos)
1210 {
1211     CALL_DEBUG_ENTER;
1212     auto lastPointerEventCopy = GetlastPointerEvent();
1213     CHKPV(lastPointerEventCopy);
1214     int32_t lastPointerAction = lastPointerEventCopy->GetPointerAction();
1215     std::shared_ptr<PointerEvent> pointerBackCenterEvent = std::make_shared<PointerEvent>(*lastPointerEventCopy);
1216     pointerBackCenterEvent->SetTargetDisplayId(cursorPos.displayId);
1217     int32_t mainDisplayInfoX = GetLogicalPositionX(cursorPos.displayId);
1218     int32_t mainDisplayInfoY = GetLogicalPositionY(cursorPos.displayId);
1219     int32_t logicalX = cursorPos.cursorPos.x + mainDisplayInfoX;
1220     int32_t logicalY = cursorPos.cursorPos.y + mainDisplayInfoY;
1221     auto touchWindow = SelectWindowInfo(logicalX, logicalY, pointerBackCenterEvent);
1222     if (touchWindow == std::nullopt) {
1223         MMI_HILOGD("Maybe just down left mouse button, the mouse did not on the window");
1224         return;
1225     }
1226     int32_t pointerId = pointerBackCenterEvent->GetPointerId();
1227     PointerEvent::PointerItem item;
1228     pointerBackCenterEvent->GetPointerItem(pointerId, item);
1229     item.SetDisplayX(cursorPos.cursorPos.x);
1230     item.SetDisplayY(cursorPos.cursorPos.y);
1231     GlobalCoords globalCoords = DisplayCoords2GlobalCoords({cursorPos.cursorPos.x, cursorPos.cursorPos.y},
1232         cursorPos.displayId);
1233     item.SetGlobalX(globalCoords.x);
1234     item.SetGlobalY(globalCoords.y);
1235     item.SetDisplayXPos(cursorPos.cursorPos.x);
1236     item.SetDisplayYPos(cursorPos.cursorPos.y);
1237     item.SetCanceled(true);
1238     pointerBackCenterEvent->UpdatePointerItem(pointerId, item);
1239     pointerBackCenterEvent->SetTargetWindowId(touchWindow->id);
1240     pointerBackCenterEvent->SetAgentWindowId(touchWindow->id);
1241 
1242     if (lastPointerAction == PointerEvent::POINTER_ACTION_MOVE) {
1243         pointerBackCenterEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
1244     } else if (lastPointerAction == PointerEvent::POINTER_ACTION_PULL_MOVE) {
1245         pointerBackCenterEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_CANCEL);
1246     }
1247     MMI_HILOGD("pointerBackCenterEvent status: %{private}s", pointerBackCenterEvent->ToString().c_str());
1248     auto filter = InputHandler->GetFilterHandler();
1249     CHKPV(filter);
1250     filter->HandlePointerEvent(pointerBackCenterEvent);
1251 }
1252 
ResetCursorPos(const OLD::DisplayGroupInfo & displayGroupInfo)1253 CursorPosition InputWindowsManager::ResetCursorPos(const OLD::DisplayGroupInfo &displayGroupInfo)
1254 {
1255     int32_t groupId = displayGroupInfo.groupId;
1256     if (!displayGroupInfo.displaysInfo.empty()) {
1257         OLD::DisplayInfo displayInfo = displayGroupInfo.displaysInfo[0];
1258         int32_t x = displayInfo.validWidth * HALF_RATIO;
1259         int32_t y = displayInfo.validHeight * HALF_RATIO;
1260         if (GetHardCursorEnabled()) {
1261             (void)GetMainScreenDisplayInfo(displayGroupInfo.displaysInfo, displayInfo);
1262             x = displayInfo.validWidth * HALF_RATIO;
1263             y = displayInfo.validHeight * HALF_RATIO;
1264             Direction direction = GetDisplayDirection(&displayInfo);
1265             if (direction == DIRECTION90 || direction == DIRECTION270) {
1266                 std::swap(x, y);
1267             }
1268         }
1269         cursorPosMap_[groupId].displayId = displayInfo.id;
1270         cursorPosMap_[groupId].cursorPos.x = x;
1271         cursorPosMap_[groupId].cursorPos.y = y;
1272     } else {
1273         cursorPosMap_[groupId].displayId = -1;
1274         cursorPosMap_[groupId].cursorPos.x = 0;
1275         cursorPosMap_[groupId].cursorPos.y = 0;
1276     }
1277     MMI_HILOGI("ResetCursorPos cursorPosMap_[groupId].displayId:%{public}d", cursorPosMap_[groupId].displayId);
1278     return cursorPosMap_[groupId];
1279 }
1280 
DisplayCoords2GlobalCoords(const Coordinate2D & displayCoords,int32_t displayId)1281 GlobalCoords InputWindowsManager::DisplayCoords2GlobalCoords(const Coordinate2D &displayCoords, int32_t displayId)
1282 {
1283     auto displayInfo = GetPhysicalDisplay(displayId);
1284     if (displayInfo == nullptr) {
1285         MMI_HILOGI("GetPhysicalDisplay failed");
1286         return { DBL_MAX, DBL_MAX };
1287     }
1288     GlobalCoords globalCoords {
1289         .x = displayInfo->x + displayCoords.x,
1290         .y = displayInfo->y + displayCoords.y
1291     };
1292     return globalCoords;
1293 }
1294 
ResetPointerPosition(const OLD::DisplayGroupInfo & displayGroupInfo)1295 void InputWindowsManager::ResetPointerPosition(const OLD::DisplayGroupInfo &displayGroupInfo)
1296 {
1297     CALL_DEBUG_ENTER;
1298     if (displayGroupInfo.displaysInfo.empty()) {
1299         return;
1300     }
1301     CursorPosition oldPtrPos = GetCursorPos();
1302     CursorPosition cursorPos;
1303     for (auto &currentDisplay : displayGroupInfo.displaysInfo) {
1304         if ((currentDisplay.displaySourceMode == OHOS::MMI::DisplaySourceMode::SCREEN_MAIN)) {
1305             auto displayInfo = GetPhysicalDisplay(oldPtrPos.displayId);
1306             CHKPV(displayInfo);
1307             MMI_HILOGI("CurDisplayId:%{public}" PRIu64 ", oldDisplayId:%{public}" PRIu64,
1308                 currentDisplay.rsId, displayInfo->rsId);
1309             if ((displayInfo->rsId != currentDisplay.rsId) || (!IsPointerOnCenter(oldPtrPos, currentDisplay))) {
1310                 cursorPos = ResetCursorPos(displayGroupInfo);
1311                 UpdateAndAdjustMouseLocation(cursorPos.displayId, cursorPos.cursorPos.x, cursorPos.cursorPos.y);
1312             }
1313             break;
1314         }
1315     }
1316 
1317     auto lastPointerEventCopy = GetlastPointerEvent();
1318     if ((lastPointerEventCopy != nullptr) &&
1319         (!lastPointerEventCopy->IsButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT))) {
1320         MMI_HILOGD("Reset pointer position, left mouse button is not pressed");
1321         return;
1322     }
1323     (void)SendBackCenterPointerEevent(cursorPos);
1324 }
1325 
IsPointerOnCenter(const CursorPosition & currentPos,const OLD::DisplayInfo & currentDisplay)1326 bool InputWindowsManager::IsPointerOnCenter(const CursorPosition &currentPos, const OLD::DisplayInfo &currentDisplay)
1327 {
1328     auto displayCenterX = currentDisplay.validWidth * HALF_RATIO;
1329     auto displayCenterY = currentDisplay.validHeight * HALF_RATIO;
1330     if ((currentPos.cursorPos.x == displayCenterX) &&
1331         (currentPos.cursorPos.y == displayCenterY)) {
1332         return true;
1333     }
1334     return false;
1335 }
1336 
HandleValidDisplayChange(const OLD::DisplayGroupInfo & displayGroupInfo)1337 void InputWindowsManager::HandleValidDisplayChange(const OLD::DisplayGroupInfo &displayGroupInfo)
1338 {
1339     ResetPointerPositionIfOutValidDisplay(displayGroupInfo);
1340     CancelTouchScreenEventIfValidDisplayChange(displayGroupInfo);
1341 }
1342 
GetCursorPos(const OLD::DisplayGroupInfo & displayGroupInfo)1343 CursorPosition InputWindowsManager::GetCursorPos(const OLD::DisplayGroupInfo &displayGroupInfo)
1344 {
1345     int32_t groupId = displayGroupInfo.groupId;
1346     if ((cursorPosMap_[groupId].displayId < 0) && !displayGroupInfoMap_[groupId].displaysInfo.empty()) {
1347         OLD::DisplayInfo displayInfo = displayGroupInfo.displaysInfo[0];
1348         if (GetHardCursorEnabled()) {
1349             (void)GetMainScreenDisplayInfo(displayGroupInfo.displaysInfo, displayInfo);
1350         }
1351         cursorPosMap_[groupId].displayId = displayInfo.id;
1352         cursorPosMap_[groupId].cursorPos.x = displayInfo.validWidth * HALF_RATIO;
1353         cursorPosMap_[groupId].cursorPos.y = displayInfo.validHeight * HALF_RATIO;
1354     }
1355     return cursorPosMap_[groupId];
1356 }
1357 
ResetPointerPositionIfOutValidDisplay(const OLD::DisplayGroupInfo & displayGroupInfo)1358 void InputWindowsManager::ResetPointerPositionIfOutValidDisplay(const OLD::DisplayGroupInfo &displayGroupInfo)
1359 {
1360     if (displayGroupInfo.displaysInfo.empty()) {
1361         MMI_HILOGD("DisplayInfo empty");
1362         return;
1363     }
1364     CursorPosition cursorPos = GetCursorPos(displayGroupInfo);
1365     int32_t cursorDisplayId = cursorPos.displayId;
1366     int32_t groupId = displayGroupInfo.groupId;
1367     for (auto &currentDisplay : displayGroupInfo.displaysInfo) {
1368         if (cursorDisplayId == currentDisplay.id) {
1369             bool isOut = IsPositionOutValidDisplay(cursorPos.cursorPos, currentDisplay);
1370             bool isChange = IsValidDisplayChange(currentDisplay);
1371             MMI_HILOGD("CurDisplayId = %{public}d CurPos = {x:%{private}d, y:%{private}d}, isOut = %{public}d, "
1372                        "isChange = %{public}d",
1373                 cursorDisplayId,
1374                 static_cast<int32_t>(cursorPos.cursorPos.x),
1375                 static_cast<int32_t>(cursorPos.cursorPos.y),
1376                 static_cast<int32_t>(isOut),
1377                 static_cast<int32_t>(isChange));
1378             int32_t validWidth = currentDisplay.validWidth;
1379             int32_t validHeight = currentDisplay.validHeight;
1380             bool pointerActiveRectValid = false;
1381 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
1382             MMI_HILOGD("Start checking vtp cursor active area");
1383             pointerActiveRectValid = IsPointerActiveRectValid(currentDisplay);
1384             if (pointerActiveRectValid) {
1385                 validWidth = currentDisplay.pointerActiveWidth;
1386                 validHeight = currentDisplay.pointerActiveHeight;
1387                 MMI_HILOGD("vtp cursor active area w:%{private}d, h:%{private}d", validWidth, validHeight);
1388             }
1389 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
1390             if (isOut && (isChange || pointerActiveRectValid)) {
1391                 double curX = validWidth * HALF_RATIO;
1392                 double curY = validHeight * HALF_RATIO;
1393                 UpdateAndAdjustMouseLocation(cursorDisplayId, curX, curY);
1394 
1395                 int32_t displayId = -1;
1396                 double cursorPosx = 0.0;
1397                 double cursorPosy = 0.0;
1398                 const auto iter = cursorPosMap_.find(groupId);
1399                 if (iter != cursorPosMap_.end()) {
1400                     displayId = iter->second.displayId;
1401                     cursorPosx = iter->second.cursorPos.x;
1402                     cursorPosy = iter->second.cursorPos.y;
1403                 }
1404                 auto displayInfo = GetPhysicalDisplay(displayId);
1405                 CHKPV(displayInfo);
1406                 CursorDrawingComponent::GetInstance().SetPointerLocation(
1407                     static_cast<int32_t>(cursorPosx),
1408                     static_cast<int32_t>(cursorPosy), displayInfo->rsId);
1409             }
1410             if (isChange) {
1411                 CancelMouseEvent();
1412             }
1413             return;
1414         }
1415     }
1416     MMI_HILOGE("Can't find displayInfo by displayId:%{public}d", cursorDisplayId);
1417 }
1418 
IsPositionOutValidDisplay(Coordinate2D & position,const OLD::DisplayInfo & currentDisplay,bool isPhysicalPos)1419 bool InputWindowsManager::IsPositionOutValidDisplay(
1420     Coordinate2D &position, const OLD::DisplayInfo &currentDisplay, bool isPhysicalPos)
1421 {
1422     double posX = position.x;
1423     double posY = position.y;
1424     double posWidth = currentDisplay.width;
1425     double posHeight = currentDisplay.height;
1426     double rotateX = posX;
1427     double rotateY = posY;
1428     double validW = currentDisplay.validWidth;
1429     double validH = currentDisplay.validHeight;
1430     double offsetX = 0;
1431     double offsetY = 0;
1432 
1433 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
1434     MMI_HILOGD("Start checking vtp cursor active area");
1435     if (IsPointerActiveRectValid(currentDisplay) && !isPhysicalPos) {
1436         validW = currentDisplay.pointerActiveWidth;
1437         validH = currentDisplay.pointerActiveHeight;
1438         MMI_HILOGD("vtp cursor active area w:%{private}f, h:%{private}f", validW, validH);
1439     }
1440 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
1441     if (isPhysicalPos) {
1442         Direction displayDirection = static_cast<Direction>((
1443         ((currentDisplay.direction - currentDisplay.fixedDirection) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90);
1444         if (displayDirection == DIRECTION90 || displayDirection == DIRECTION270) {
1445             std::swap(validW, validH);
1446             std::swap(posWidth, posHeight);
1447         }
1448         if (currentDisplay.fixedDirection == DIRECTION0) {
1449             rotateX = posX;
1450             rotateY = posY;
1451         } else if (currentDisplay.fixedDirection == DIRECTION90) {
1452             rotateX = posWidth - posY;
1453             rotateY = posX;
1454         } else if (currentDisplay.fixedDirection == DIRECTION180) {
1455             rotateX = posWidth - posX;
1456             rotateY = posHeight - posY;
1457         } else if (currentDisplay.fixedDirection == DIRECTION270) {
1458             rotateX = posY;
1459             rotateY = posHeight - posX;
1460         } else {
1461             MMI_HILOGD("Invalid fixedDirection:%{public}d", currentDisplay.fixedDirection);
1462         }
1463         offsetX = currentDisplay.offsetX;
1464         offsetY = currentDisplay.offsetY;
1465     }
1466     bool isOut = (rotateX < offsetX) || (rotateX > offsetX + validW) ||
1467                  (rotateY < offsetY) || (rotateY > offsetY + validH);
1468     PrintDisplayInfo(currentDisplay);
1469     MMI_HILOGD("isOut=%{public}d,isPhysicalPos=%{public}d Position={%{private}f %{private}f}"
1470                "->{%{private}f %{private}f} RealValidWH={w:%{private}f h:%{private}f}",
1471         static_cast<int32_t>(isOut),
1472         static_cast<int32_t>(isPhysicalPos),
1473         posX,
1474         posY,
1475         rotateX,
1476         rotateY,
1477         validW,
1478         validH);
1479 
1480     if (!isOut && isPhysicalPos) {
1481         double rotateX1 = rotateX - currentDisplay.offsetX;
1482         double rotateY1 = rotateY - currentDisplay.offsetY;
1483 
1484         if (currentDisplay.fixedDirection == DIRECTION0) {
1485             position.x = rotateX1;
1486             position.y = rotateY1;
1487         } else if (currentDisplay.fixedDirection == DIRECTION90) {
1488             position.x = rotateY1;
1489             position.y = posWidth - rotateX1;
1490         } else if (currentDisplay.fixedDirection == DIRECTION180) {
1491             position.x = posWidth - rotateX1;
1492             position.y = posHeight - rotateY1;
1493         } else if (currentDisplay.fixedDirection == DIRECTION270) {
1494             position.x = posHeight - rotateY1;
1495             position.y = rotateX1;
1496         } else {
1497             MMI_HILOGD("Invalid fixedDirection:%{public}d", currentDisplay.fixedDirection);
1498         }
1499         MMI_HILOGD("rerotate={%{private}f %{private}f}->{%{private}f %{private}f} RealValidWH = "
1500                    "{w:%{private}f h:%{private}f} RealWH{w:%{private}f h:%{private}f}",
1501             rotateX1,
1502             rotateY1,
1503             position.x,
1504             position.y,
1505             validW,
1506             validH,
1507             posWidth,
1508             posHeight);
1509     }
1510 
1511     return isOut;
1512 }
1513 
1514 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
IsPointerActiveRectValid(const OLD::DisplayInfo & currentDisplay)1515 bool InputWindowsManager::IsPointerActiveRectValid(const OLD::DisplayInfo &currentDisplay)
1516 {
1517     return currentDisplay.pointerActiveWidth > 0 && currentDisplay.pointerActiveHeight > 0;
1518 }
1519 
IsPointInsideWindowArea(int x,int y,const WindowInfo & windowItem) const1520 bool InputWindowsManager::IsPointInsideWindowArea(int x, int y, const WindowInfo& windowItem) const {
1521     return (x > windowItem.area.x && x < (windowItem.area.x + windowItem.area.width)) &&
1522         (y > windowItem.area.y && y < (windowItem.area.y + windowItem.area.height));
1523 }
1524 
IsPointInsideSpecialWindow(double pointX,double pointY)1525 bool InputWindowsManager::IsPointInsideSpecialWindow(double pointX, double pointY)
1526 {
1527     auto &WindowsInfo = GetWindowInfoVector();
1528     for (const auto& windowItem : WindowsInfo) {
1529         int32_t x = static_cast<int32_t>(pointX);
1530         int32_t y = static_cast<int32_t>(pointY);
1531         if (windowItem.windowType == GUIDE_WINDOW_TYPE) {
1532             for (const auto &win : windowItem.defaultHotAreas) {
1533                 return ((x > win.x && x < (win.x + win.width)) &&
1534                     (y > win.y && y < (win.y + win.height)));
1535             }
1536         }
1537         if (windowItem.zOrder == VOICE_WINDOW_ZORDER) {
1538             return IsPointInsideWindowArea(x, y, windowItem);
1539         }
1540     }
1541     return false;
1542 }
1543 
IsMouseInCastWindow()1544 bool InputWindowsManager::IsMouseInCastWindow()
1545 {
1546     auto &WindowsInfo = GetWindowInfoVector();
1547     for (const auto& windowItem : WindowsInfo) {
1548         if (windowItem.windowType == CAST_WINDOW_TYPE) {
1549             const auto &mouseInfo = GetMouseInfo();
1550             int32_t x = mouseInfo.physicalX;
1551             int32_t y = mouseInfo.physicalY;
1552             return IsPointInsideWindowArea(x, y, windowItem);
1553         }
1554     }
1555 
1556     return false;
1557 }
1558 
IsCaptureMode()1559 bool InputWindowsManager::IsCaptureMode()
1560 {
1561     auto &WindowsInfo = GetWindowInfoVector();
1562     for (const auto& window : WindowsInfo) {
1563         if (window.windowNameType == WINDOW_NAME_TYPE_SCREENSHOT) {
1564             return false;
1565         }
1566         if (window.zOrder == SCREEN_CAPTURE_WINDOW_ZORDER) {
1567             return (window.area.width > SCREEN_RECORD_WINDOW_WIDTH ||
1568                     window.area.height > SCREEN_RECORD_WINDOW_HEIGHT);
1569         }
1570     }
1571 
1572     return false;
1573 }
1574 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
1575 
1576 #ifdef OHOS_BUILD_ENABLE_POINTER
IsMouseDragging() const1577 bool InputWindowsManager::IsMouseDragging() const
1578 {
1579     return (extraData_.appended && (extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE));
1580 }
1581 
EnsureMouseEventCycle(std::shared_ptr<PointerEvent> event)1582 void InputWindowsManager::EnsureMouseEventCycle(std::shared_ptr<PointerEvent> event)
1583 {
1584     CHKPV(event);
1585     if (event->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE) {
1586         return;
1587     }
1588     if (IsMouseDragging()) {
1589         return;
1590     }
1591     if (!event->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) {
1592         return;
1593     }
1594     if ((event->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_UP) &&
1595         (mouseDownInfo_.id >= 0) &&
1596         (mouseDownInfo_.id != event->GetTargetWindowId())) {
1597         MMI_HILOGD("Target window shift from %{private}d to %{private}d at button-up",
1598             mouseDownInfo_.id, event->GetTargetWindowId());
1599         event->SetTargetDisplayId(mouseDownInfo_.displayId);
1600         event->SetTargetWindowId(mouseDownInfo_.id);
1601         event->SetAgentWindowId(mouseDownInfo_.agentWindowId);
1602     }
1603 }
1604 
CleanMouseEventCycle(std::shared_ptr<PointerEvent> event)1605 void InputWindowsManager::CleanMouseEventCycle(std::shared_ptr<PointerEvent> event)
1606 {
1607     CHKPV(event);
1608     if (event->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE) {
1609         return;
1610     }
1611     if ((event->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_UP) ||
1612         (event->GetPointerAction() == PointerEvent::POINTER_ACTION_CANCEL)) {
1613         InitMouseDownInfo();
1614         MMI_HILOGD("Clear button-down record at button-up");
1615     }
1616 }
1617 #endif // OHOS_BUILD_ENABLE_POINTER
1618 
CancelTouchScreenEventIfValidDisplayChange(const OLD::DisplayGroupInfo & displayGroupInfo)1619 void InputWindowsManager::CancelTouchScreenEventIfValidDisplayChange(const OLD::DisplayGroupInfo &displayGroupInfo)
1620 {
1621     if (lastPointerEventforGesture_ == nullptr) {
1622         MMI_HILOGD("lastPointerEventforGesture_ is null");
1623         return;
1624     }
1625     if (lastPointerEventforGesture_->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
1626         MMI_HILOGD("source type:[%{public}d] is not touchscreen", lastPointerEventforGesture_->GetSourceType());
1627         return;
1628     }
1629     int32_t touchDisplayId = lastPointerEventforGesture_->GetTargetDisplayId();
1630     for (auto &currentDisplay : displayGroupInfo.displaysInfo) {
1631         MMI_HILOGD("touchDisplayId=%{public}d currentDisplay.id=%{public}d", touchDisplayId, currentDisplay.id);
1632         if (touchDisplayId == currentDisplay.id && IsValidDisplayChange(currentDisplay)) {
1633             CancelAllTouches(lastPointerEventforGesture_, true);
1634             return;
1635         }
1636     }
1637 }
1638 
CancelMouseEvent()1639 void InputWindowsManager::CancelMouseEvent()
1640 {
1641     auto lastPointerEventCopy = GetlastPointerEvent();
1642     CHKPV(lastPointerEventCopy);
1643     if (lastPointerEventCopy->GetPointerAction() == PointerEvent::POINTER_ACTION_CANCEL ||
1644         lastPointerEventCopy->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_CANCEL) {
1645         MMI_HILOGE("lastPointerEventCopy has canceled");
1646         return;
1647     }
1648     int32_t action = PointerEvent::POINTER_ACTION_CANCEL;
1649     if (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) {
1650         action = PointerEvent::POINTER_ACTION_PULL_CANCEL;
1651     }
1652     if (lastPointerEventCopy->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE &&
1653         !lastPointerEventCopy->GetPressedButtons().empty()) {
1654         int32_t pointerId = lastPointerEventCopy->GetPointerId();
1655         int32_t originAction = lastPointerEventCopy->GetPointerAction();
1656         PointerEvent::PointerItem item;
1657         auto isItemExist = lastPointerEventCopy->GetPointerItem(pointerId, item);
1658         if (isItemExist) {
1659             item.SetCanceled(true);
1660             lastPointerEventCopy->UpdatePointerItem(pointerId, item);
1661         }
1662         MMI_HILOGI("Cancel mouse event for valid display change,pointerId:%{public}d action:%{public}d->%{public}d "
1663             "isItemExist=%{public}d",
1664             pointerId,
1665             originAction,
1666             action,
1667             static_cast<uint32_t>(isItemExist));
1668         auto lastPointerEvent = std::make_shared<PointerEvent>(*lastPointerEventCopy);
1669         lastPointerEvent->SetPointerAction(action);
1670         lastPointerEvent->SetOriginPointerAction(originAction);
1671         lastPointerEvent->SetPointerId(pointerId);
1672         auto filter = InputHandler->GetFilterHandler();
1673         CHKPV(filter);
1674         filter->HandlePointerEvent(lastPointerEvent);
1675         {
1676             std::lock_guard<std::mutex> guard(mtx_);
1677             lastPointerEvent_->SetPointerAction(action);
1678             lastPointerEvent_->DeleteReleaseButton(lastPointerEvent_->GetButtonId());
1679         }
1680     }
1681 }
1682 
IsValidDisplayChange(const OLD::DisplayInfo & displayInfo)1683 bool InputWindowsManager::IsValidDisplayChange(const OLD::DisplayInfo &displayInfo)
1684 {
1685     int32_t touchDisplayId = displayInfo.id;
1686     int32_t groupId = FindDisplayGroupId(touchDisplayId);
1687     auto &DisplaysInfo = GetDisplayInfoVector(groupId);
1688     for (auto &currentDisplay : DisplaysInfo) {
1689         if (touchDisplayId == currentDisplay.id) {
1690             auto currentDirection = currentDisplay.direction;
1691             auto currentValidWH =
1692                 RotateRect<int32_t>(currentDirection, {currentDisplay.validWidth, currentDisplay.validHeight});
1693             auto newDirection = displayInfo.direction;
1694             auto newValidWH = RotateRect<int32_t>(newDirection, {displayInfo.validWidth, displayInfo.validHeight});
1695             bool isChange =
1696                 !(displayInfo.offsetX == currentDisplay.offsetX && displayInfo.offsetY == currentDisplay.offsetY &&
1697                     newValidWH.x == currentValidWH.x && newValidWH.y == currentValidWH.y);
1698             MMI_HILOGD("isChange=%{private}d CurDisplayId=%{private}d "
1699                        "oldDisplayInfo={{w:%{private}d h:%{private}d} validWH:{%{private}d %{private}d} "
1700                        "offsetXY:{%{private}d %{private}d} direction:{%{private}d %{private}d %{private}d}} "
1701                        "newDisplayInfo={{w:%{private}d h:%{private}d} validWH:{%{private}d %{private}d}} "
1702                        "offsetXY:{%{private}d %{private}d} direction:{%{private}d %{private}d %{private}d}}"
1703                        "useDirection:{old:%{private}d new:%{private}d}}",
1704                 static_cast<int32_t>(isChange),
1705                 touchDisplayId,
1706                 currentDisplay.width,
1707                 currentDisplay.height,
1708                 currentDisplay.validWidth,
1709                 currentDisplay.validHeight,
1710                 currentDisplay.offsetX,
1711                 currentDisplay.offsetY,
1712                 currentDisplay.direction,
1713                 currentDisplay.displayDirection,
1714                 currentDisplay.fixedDirection,
1715                 displayInfo.width,
1716                 displayInfo.height,
1717                 displayInfo.validWidth,
1718                 displayInfo.validHeight,
1719                 displayInfo.offsetX,
1720                 displayInfo.offsetY,
1721                 displayInfo.direction,
1722                 displayInfo.displayDirection,
1723                 displayInfo.fixedDirection,
1724                 currentDirection,
1725                 newDirection);
1726             return isChange;
1727         }
1728     }
1729     return false;
1730 }
1731 
HandleWindowPositionChange(const OLD::DisplayGroupInfo & displayGroupInfo)1732 void InputWindowsManager::HandleWindowPositionChange(const OLD::DisplayGroupInfo &displayGroupInfo)
1733 {
1734     CALL_DEBUG_ENTER;
1735     int32_t groupId = displayGroupInfo.groupId;
1736     PrintWindowNavbar(groupId);
1737 
1738     auto WindowInfo = GetWindowInfoVector(groupId);
1739     for (auto it = touchItemDownInfosMap_[groupId].begin(); it != touchItemDownInfosMap_[groupId].end(); ++it) {
1740         int32_t pointerId = it->first;
1741         int32_t windowId = it->second.window.id;
1742         auto iter = std::find_if(WindowInfo.begin(), WindowInfo.end(),
1743             [windowId](const auto& windowInfo) {
1744             return windowId == windowInfo.id && windowInfo.rectChangeBySystem;
1745         });
1746         if (iter != WindowInfo.end()) {
1747             MMI_HILOGI("Dispatch cancel event pointerId:%{public}d", pointerId);
1748             CHKPV(lastPointerEventforWindowChangeMap_[groupId]);
1749             PointerEvent::PointerItem pointerItem;
1750             if (!lastPointerEventforWindowChangeMap_[groupId]->GetPointerItem(pointerId, pointerItem)) {
1751                 MMI_HILOGE("Can not find pointer item pointerid:%{public}d", pointerId);
1752                 return;
1753             }
1754             auto tmpEvent = std::make_shared<PointerEvent>(*lastPointerEventforWindowChangeMap_[groupId]);
1755             tmpEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
1756             tmpEvent->SetPointerId(pointerId);
1757             auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler();
1758             CHKPV(inputEventNormalizeHandler);
1759             inputEventNormalizeHandler->HandleTouchEvent(tmpEvent);
1760             it->second.flag = true;
1761             iter->rectChangeBySystem = false;
1762         }
1763     }
1764 }
1765 
SendCancelEventWhenWindowChange(int32_t pointerId,int32_t groupId)1766 void InputWindowsManager::SendCancelEventWhenWindowChange(int32_t pointerId, int32_t groupId)
1767 {
1768     MMI_HILOGD("Dispatch cancel event pointerId:%{public}d", pointerId);
1769     std::shared_ptr<PointerEvent> lastPointerEventforWindowChangeTmp = lastPointerEventforWindowChange_;
1770 
1771     const auto iter = lastPointerEventforWindowChangeMap_.find(groupId);
1772     if (iter != lastPointerEventforWindowChangeMap_.end()) {
1773         lastPointerEventforWindowChangeTmp = iter->second;
1774     }
1775     CHKPV(lastPointerEventforWindowChangeTmp);
1776     PointerEvent::PointerItem pointerItem;
1777     if (!lastPointerEventforWindowChangeTmp->GetPointerItem(pointerId, pointerItem)) {
1778         MMI_HILOGE("Can not find pointer item pointerid:%{public}d", pointerId);
1779         return;
1780     }
1781     auto tmpEvent = std::make_shared<PointerEvent>(*(lastPointerEventforWindowChangeTmp));
1782     tmpEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
1783 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
1784     DfxHisysevent::ReportPointerEventExitTimes(PointerEventStatistics::TRANSFORM_CANCEL);
1785 #endif // OHOS_BUILD_ENABLE_DFX_RADAR
1786     tmpEvent->SetPointerId(pointerId);
1787     auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler();
1788     CHKPV(inputEventNormalizeHandler);
1789     inputEventNormalizeHandler->HandleTouchEvent(tmpEvent);
1790 }
1791 
PrintWindowNavbar(int32_t groupId)1792 void InputWindowsManager::PrintWindowNavbar(int32_t groupId)
1793 {
1794     auto &WindowsInfo = GetWindowInfoVector(groupId);
1795     for (auto &item : WindowsInfo) {
1796         if (item.windowInputType == WindowInputType::MIX_BUTTOM_ANTI_AXIS_MOVE ||
1797             item.windowInputType == WindowInputType::DUALTRIGGER_TOUCH) {
1798             std::string dump;
1799             dump += StringPrintf("%d|%d|%d|%d|%d|%zu(", item.id, item.area.x, item.area.y, item.area.width,
1800                 item.area.height, item.defaultHotAreas.size());
1801             for (const auto &win : item.defaultHotAreas) {
1802                 dump += StringPrintf(" %d|%d|%d|%d ", win.x, win.y, win.width, win.height);
1803             }
1804             dump += StringPrintf(")\n");
1805             for (auto it : item.transform) {
1806                 dump += StringPrintf("%f,", it);
1807             }
1808             dump += StringPrintf("]\n");
1809             MMI_HILOGI("%{public}s", dump.c_str());
1810         }
1811     }
1812 }
1813 
JudgeCameraInFore()1814 bool InputWindowsManager::JudgeCameraInFore()
1815 {
1816     CALL_DEBUG_ENTER;
1817     int32_t focWid = GetFocusWindowId(MAIN_GROUPID);
1818     int32_t focPid = GetPidByWindowId(focWid);
1819     if (udsServer_ == nullptr) {
1820         MMI_HILOGW("The udsServer is nullptr");
1821         return false;
1822     }
1823     SessionPtr sess = udsServer_->GetSessionByPid(focPid);
1824     if (sess == nullptr) {
1825         MMI_HILOGW("The sess is nullptr");
1826         return false;
1827     }
1828     std::string programName = sess->GetProgramName();
1829     return programName.find(".camera") != std::string::npos;
1830 }
1831 
InitDisplayGroupInfo(OLD::DisplayGroupInfo & displayGroupInfo)1832 void InputWindowsManager::InitDisplayGroupInfo(OLD::DisplayGroupInfo &displayGroupInfo)
1833 {
1834     int32_t groupId = displayGroupInfo.groupId;
1835     if (displayGroupInfo.type == GroupType::GROUP_DEFAULT) {
1836         if (groupId != MAIN_GROUPID) {
1837             MMI_HILOGE("The groupId is incorrect, groupId:%{public}d", groupId);
1838             return;
1839         }
1840     }
1841     displayGroupInfoMap_[groupId] = displayGroupInfo;
1842 }
1843 
UpdateDisplayInfo(OLD::DisplayGroupInfo & displayGroupInfo)1844 void InputWindowsManager::UpdateDisplayInfo(OLD::DisplayGroupInfo &displayGroupInfo)
1845 {
1846     InitDisplayGroupInfo(displayGroupInfo);
1847     if (!mainGroupExisted_ && displayGroupInfo.type == GroupType::GROUP_DEFAULT) {
1848         mainGroupExisted_ = true;
1849     }
1850     int32_t groupId = displayGroupInfo.groupId;
1851     bool bFlag = false;
1852 #ifdef OHOS_BUILD_ENABLE_ANCO
1853     bFlag = displayGroupInfo.type == GroupType::GROUP_DEFAULT && !displayGroupInfo.displaysInfo.empty();
1854     if (bFlag) {
1855         const auto &displayInfo = displayGroupInfo.displaysInfo.front();
1856         std::lock_guard<std::mutex> lock(oneHandMtx_);
1857         if (scalePercent_ != displayInfo.scalePercent) {
1858             MMI_HILOGI("Send one hand data to anco, scalePercent:%{public}d", displayInfo.scalePercent);
1859             UpdateOneHandDataExt(displayInfo);
1860             scalePercent_ = displayInfo.scalePercent;
1861         }
1862     }
1863 #endif // OHOS_BUILD_ENABLE_ANCO
1864     MMI_HILOGI("Displays Info size:%{public}zu, focusWindowId:%{public}d",
1865         displayGroupInfo.displaysInfo.size(), displayGroupInfo.focusWindowId);
1866     auto action = UpdateWindowInfo(displayGroupInfo);
1867     CheckFocusWindowChange(displayGroupInfo);
1868     UpdateCaptureMode(displayGroupInfo);
1869     bool isDisplayChanged = false;
1870     if (GetHardCursorEnabled()) {
1871         isDisplayChanged = OnDisplayRemovedOrCombinationChanged(displayGroupInfo);
1872     }
1873     OLD::DisplayGroupInfo displayGroupInfoTemp;
1874     displayGroupInfoMapTmp_[displayGroupInfo.groupId] = displayGroupInfo;
1875     bFlag = (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled() || action == WINDOW_UPDATE_ACTION::ADD_END)
1876         && ((currentUserId_ < 0) || (currentUserId_ == displayGroupInfo.currentUserId));
1877     if (bFlag) {
1878         if (GetHardCursorEnabled()) {
1879             bool isDisplayUpdate = OnDisplayRemovedOrCombinationChanged(displayGroupInfo);
1880             if (isDisplayUpdate) {
1881                 ResetPointerPosition(displayGroupInfo);
1882             }
1883         }
1884         PrintChangedWindowBySync(displayGroupInfo);
1885         CleanInvalidPiexMap(groupId);
1886         HandleValidDisplayChange(displayGroupInfo);
1887         displayGroupInfoMap_[groupId] = displayGroupInfo;
1888         displayGroupInfo_ = displayGroupInfo;
1889         UpdateWindowsInfoPerDisplay(displayGroupInfo);
1890         HandleWindowPositionChange(displayGroupInfo);
1891         const auto iter = displayGroupInfoMap_.find(groupId);
1892         if (iter != displayGroupInfoMap_.end()) {
1893             displayGroupInfoTemp = iter->second;
1894         }
1895     }
1896     PrintDisplayGroupInfo(displayGroupInfoTemp);
1897     if (!displayGroupInfoTemp.displaysInfo.empty()) {
1898         UpdateDisplayIdAndName();
1899     }
1900     UpdateDisplayMode(displayGroupInfo.groupId);
1901 #ifdef OHOS_BUILD_ENABLE_POINTER
1902 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
1903     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() &&
1904        (INPUT_DEV_MGR->HasPointerDevice() || INPUT_DEV_MGR->HasVirtualPointerDevice())) {
1905 #else
1906     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
1907 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
1908         UpdatePointerChangeAreas(displayGroupInfo);
1909     }
1910     InitPointerStyle(displayGroupInfo.groupId);
1911 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
1912 
1913     const auto iter = pointerDrawFlagMap_.find(groupId);
1914     bFlag = (iter != pointerDrawFlagMap_.end()) ? true : false;
1915     if (!displayGroupInfo.displaysInfo.empty() && bFlag) {
1916         AdjustDisplayRotation(groupId);
1917         if (GetHardCursorEnabled()) {
1918             PointerDrawingManagerOnDisplayInfo(displayGroupInfo, isDisplayChanged);
1919         } else {
1920             PointerDrawingManagerOnDisplayInfo(displayGroupInfo);
1921         }
1922     }
1923 
1924     lastDpiMap_[groupId] = displayGroupInfoTemp.displaysInfo.empty() ? DEFAULT_DPI :
1925     displayGroupInfoTemp.displaysInfo[0].dpi;
1926     if (INPUT_DEV_MGR->HasPointerDevice() && bFlag) {
1927         NotifyPointerToWindow(groupId);
1928     }
1929 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
1930 #endif // OHOS_BUILD_ENABLE_POINTER
1931 }
1932 
1933 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1934 void InputWindowsManager::AdjustDisplayRotation(int32_t groupId)
1935 {
1936     CursorPosition cursorPosCur;
1937 
1938     const auto iter = cursorPosMap_.find(groupId);
1939     if (iter == cursorPosMap_.end()) {
1940         cursorPosMap_[groupId]  = cursorPosCur;
1941     }
1942     PhysicalCoordinate coord {
1943         .x = cursorPosCur.cursorPos.x,
1944         .y = cursorPosCur.cursorPos.y,
1945     };
1946     auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPosCur.displayId);
1947     CHKPV(displayInfo);
1948     if (cursorPosCur.displayDirection != displayInfo->displayDirection ||
1949         cursorPosCur.direction != displayInfo->direction) {
1950         MMI_HILOGI("displayId:%{public}d, cursorPosX:%{private}.2f, cursorPosY:%{private}.2f, direction:%{public}d, "
1951             "physicalDisplay id:%{public}d, x:%{private}d, y:%{private}d, width:%{public}d, height:%{public}d, "
1952             "dpi:%{public}d, name:%{public}s, uniq:%{public}s, direction:%{public}d, displayDirection:%{public}d",
1953             cursorPosCur.displayId, cursorPosCur.cursorPos.x,
1954             cursorPosCur.cursorPos.y, cursorPosCur.direction,
1955             displayInfo->id, displayInfo->x, displayInfo->y, displayInfo->width, displayInfo->height,
1956             displayInfo->dpi, displayInfo->name.c_str(), displayInfo->uniq.c_str(), displayInfo->direction,
1957             displayInfo->displayDirection);
1958         if (cursorPosCur.direction == displayInfo->direction) {
1959             ScreenRotateAdjustDisplayXY(*displayInfo, coord);
1960         }
1961 
1962         const auto iter = cursorPosMap_.find(groupId);
1963         if (iter != cursorPosMap_.end()) {
1964             cursorPosMap_[groupId].direction = displayInfo->direction;
1965             cursorPosMap_[groupId].displayDirection = displayInfo->displayDirection;
1966         }
1967         UpdateAndAdjustMouseLocation(cursorPosCur.displayId, coord.x, coord.y);
1968         if (GetHardCursorEnabled() && extraData_.appended &&
1969             (extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE)) {
1970             AdjustDragPosition(groupId);
1971         }
1972         CursorDrawingComponent::GetInstance().UpdateDisplayInfo(*displayInfo);
1973         int32_t displayId = -1;
1974 
1975         if (iter != cursorPosMap_.end()) {
1976             displayId = iter->second.displayId;
1977         }
1978         auto displayInfoTmp = GetPhysicalDisplay(displayId);
1979         CHKPV(displayInfoTmp);
1980         CursorDrawingComponent::GetInstance().SetPointerLocation(
1981             static_cast<int32_t>(coord.x), static_cast<int32_t>(coord.y), displayInfoTmp->rsId);
1982     }
1983 }
1984 
1985 void InputWindowsManager::AdjustDragPosition(int32_t groupId)
1986 {
1987     auto lastPointerEvent = GetlastPointerEvent();
1988     CHKPV(lastPointerEvent);
1989     int32_t displayId = -1;
1990     int32_t physicalX = 0;
1991     int32_t physicalY = 0;
1992 
1993     auto iter = mouseLocationMap_.find(groupId);
1994     if (iter != mouseLocationMap_.end()) {
1995         displayId = iter->second.displayId;
1996         physicalX = iter->second.physicalX;
1997         physicalY = iter->second.physicalY;
1998     }
1999     std::shared_ptr<PointerEvent> pointerEvent = std::make_shared<PointerEvent>(*lastPointerEvent);
2000     pointerEvent->SetTargetDisplayId(displayId);
2001     auto touchWindow = SelectWindowInfo(physicalX, physicalY, pointerEvent);
2002     if (touchWindow == std::nullopt) {
2003         MMI_HILOGE("SelectWindowInfo failed");
2004         return;
2005     }
2006     int32_t pointerId = pointerEvent->GetPointerId();
2007     PointerEvent::PointerItem item;
2008     pointerEvent->GetPointerItem(pointerId, item);
2009     item.SetDisplayX(physicalX);
2010     item.SetDisplayY(physicalY);
2011     GlobalCoords globalCoords = DisplayCoords2GlobalCoords({physicalX, physicalY}, displayId);
2012     item.SetGlobalX(globalCoords.x);
2013     item.SetGlobalY(globalCoords.y);
2014     item.SetDisplayXPos(physicalX);
2015     item.SetDisplayYPos(physicalY);
2016     pointerEvent->UpdatePointerItem(pointerId, item);
2017     pointerEvent->SetTargetWindowId(touchWindow->id);
2018     pointerEvent->SetAgentWindowId(touchWindow->id);
2019     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_MOVE);
2020     auto now = GetSysClockTime();
2021     pointerEvent->SetActionTime(now);
2022     pointerEvent->UpdateId();
2023     auto filterHandler = InputHandler->GetFilterHandler();
2024     CHKPV(filterHandler);
2025     filterHandler->HandlePointerEvent(pointerEvent);
2026     MMI_HILOGI("pointerEvent: %{private}s", pointerEvent->ToString().c_str());
2027 }
2028 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
2029 
2030 DisplayMode InputWindowsManager::GetDisplayMode() const
2031 {
2032     const auto iter = displayModeMap_.find(MAIN_GROUPID);
2033     if (iter != displayModeMap_.end()) {
2034         return iter->second;
2035     }
2036     return displayMode_;
2037 }
2038 
2039 void InputWindowsManager::UpdateDisplayMode(int32_t groupId)
2040 {
2041     CALL_DEBUG_ENTER;
2042     DisplayMode mode;
2043     const auto iter = displayGroupInfoMap_.find(groupId);
2044     if (iter != displayGroupInfoMap_.end()) {
2045         if (iter->second.displaysInfo.empty()) {
2046             MMI_HILOGE("DisplaysInfo is empty");
2047             return;
2048         }
2049         mode = iter->second.displaysInfo[0].displayMode;
2050     } else {
2051         if (displayGroupInfo_.displaysInfo.empty()) {
2052             MMI_HILOGE("DisplaysInfo is empty");
2053             return;
2054         }
2055         mode = displayGroupInfo_.displaysInfo[0].displayMode;
2056     }
2057     const auto tempMode = displayModeMap_.find(groupId);
2058     if (tempMode == displayModeMap_.end()) {
2059         return;
2060     }
2061     DisplayMode& displayMode = tempMode->second;
2062     if (mode == displayMode) {
2063         MMI_HILOGD("Displaymode not change, mode:%{public}d, diaplayMode_:%{public}d", mode, displayMode);
2064         return;
2065     }
2066     displayMode_ = mode;
2067     displayModeMap_[groupId] = mode;
2068     displayMode = mode;
2069 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
2070     if (FINGERSENSE_WRAPPER->sendFingerSenseDisplayMode_ == nullptr) {
2071         MMI_HILOGD("Send fingersense display mode is nullptr");
2072         return;
2073     }
2074     MMI_HILOGI("Update fingersense display mode, displayMode:%{public}d", displayMode);
2075     BytraceAdapter::StartUpdateDisplayMode("display mode change");
2076     FINGERSENSE_WRAPPER->sendFingerSenseDisplayMode_(static_cast<int32_t>(displayMode));
2077     BytraceAdapter::StopUpdateDisplayMode();
2078 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
2079 }
2080 
2081 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
2082 void InputWindowsManager::DrawPointer(bool isDisplayRemoved)
2083 {
2084     if (DISPLAY_MONITOR->GetScreenStatus() != EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) {
2085         if (!isDisplayRemoved) {
2086             CursorDrawingComponent::GetInstance().DrawPointerStyle(dragPointerStyle_);
2087         } else {
2088             CursorDrawingComponent::GetInstance().DrawScreenCenterPointer(dragPointerStyle_);
2089         }
2090     }
2091 }
2092 
2093 void InputWindowsManager::PointerDrawingManagerOnDisplayInfo(const OLD::DisplayGroupInfo &displayGroupInfo,
2094     bool isDisplayRemoved)
2095 {
2096     auto currentDisplayInfo = CursorDrawingComponent::GetInstance().GetCurrentDisplayInfo();
2097     CursorDrawingComponent::GetInstance().OnDisplayInfo(displayGroupInfo);
2098     int32_t groupId = displayGroupInfo.groupId;
2099     int32_t newId = 0;
2100     int32_t &lastDpiTmp = lastDpi_;
2101 
2102     const auto iter = displayGroupInfoMap_.find(groupId);
2103     if (iter != displayGroupInfoMap_.end()) {
2104         if (iter->second.displaysInfo.empty()) {
2105             MMI_HILOGE("DisplayGroup is empty.");
2106             return;
2107         }
2108         newId = iter->second.displaysInfo[0].id;
2109     } else {
2110         if (displayGroupInfo_.displaysInfo.empty()) {
2111             MMI_HILOGE("DisplayGroup is empty.");
2112             return;
2113         }
2114         newId = displayGroupInfo_.displaysInfo[0].id;
2115     }
2116     if (lastDpiMap_.find(groupId) == lastDpiMap_.end()) {
2117         lastDpiMap_[groupId]  = lastDpiTmp;
2118     }
2119     for (auto displayInfo : displayGroupInfo.displaysInfo) {
2120         if (displayInfo.rsId == currentDisplayInfo.rsId && displayInfo.dpi != currentDisplayInfo.dpi) {
2121             MMI_HILOGD("dpi changed, current rsId: %{public}" PRIu64 ", dpi: %{public}d, "
2122             "latest rsId: %{public}" PRIu64 ", dpi: %{public}d",
2123             currentDisplayInfo.rsId, currentDisplayInfo.dpi, displayInfo.rsId, displayInfo.dpi);
2124             auto drawNewDpiRes = CursorDrawingComponent::GetInstance().DrawNewDpiPointer();
2125             if (drawNewDpiRes != RET_OK) {
2126                 MMI_HILOGE("Draw New Dpi pointer failed.");
2127             }
2128             break;
2129         }
2130     }
2131     auto lastPointerEventCopy = GetlastPointerEvent();
2132     CHKPV(lastPointerEventCopy);
2133     if (INPUT_DEV_MGR->HasPointerDevice() || INPUT_DEV_MGR->HasVirtualPointerDevice()) {
2134         MouseLocation mouseLocation = GetMouseInfo();
2135         int32_t displayId = MouseEventHdr->GetDisplayId();
2136         displayId = displayId < 0 ? newId : displayId;
2137         auto displayInfo = GetPhysicalDisplay(displayId);
2138         CHKPV(displayInfo);
2139         int32_t displayInfoX = GetLogicalPositionX(displayId);
2140         int32_t displayInfoY = GetLogicalPositionY(displayId);
2141         Direction DirectionCopy = GetLogicalPositionDirection(displayId);
2142         Direction DisplayDirection = GetPositionDisplayDirection(displayId);
2143         DispatchPointerCancel(displayId);
2144         int32_t logicX = mouseLocation.physicalX + displayInfoX;
2145         int32_t logicY = mouseLocation.physicalY + displayInfoY;
2146         lastLogicX_ = logicX;
2147         lastLogicY_ = logicY;
2148         std::optional<WindowInfo> windowInfo;
2149         if (lastPointerEventCopy->GetPointerAction() != PointerEvent::POINTER_ACTION_DOWN &&
2150         lastPointerEventCopy->GetPressedButtons().empty()) {
2151             PhysicalCoordinate coord {
2152                 .x = logicX,
2153                 .y = logicY,
2154             };
2155             CursorPosition cursorPosRef;
2156             double cursorPosx = 0.0;
2157             double cursorPosy = 0.0;
2158             Direction direction = Direction::DIRECTION0;
2159             Direction displayDirection = Direction::DIRECTION0;
2160             const auto iter = cursorPosMap_.find(groupId);
2161             if (iter == cursorPosMap_.end()) {
2162                 cursorPosMap_[groupId] = cursorPosRef;
2163             }
2164             else {
2165                 direction = iter->second.direction;
2166                 displayDirection = iter->second.displayDirection;
2167                 cursorPosx = iter->second.cursorPos.x;;
2168                 cursorPosy = iter->second.cursorPos.y;
2169             }
2170             if (direction != DirectionCopy &&
2171                 displayDirection == DisplayDirection) {
2172                 coord.x = cursorPosx;
2173                 coord.y = cursorPosy;
2174                 RotateDisplayScreen(*displayInfo, coord);
2175             }
2176             windowInfo = GetWindowInfo(coord.x, coord.y, groupId);
2177         } else {
2178             windowInfo = SelectWindowInfo(logicX, logicY, lastPointerEventCopy);
2179         }
2180         if (windowInfo == std::nullopt) {
2181             MMI_HILOGE("The windowInfo is nullptr");
2182             DrawPointer(isDisplayRemoved);
2183             return;
2184         }
2185         int32_t windowPid = GetWindowPid(windowInfo->id);
2186         WinInfo info = { .windowPid = windowPid, .windowId = windowInfo->id };
2187         CursorDrawingComponent::GetInstance().OnWindowInfo(info);
2188         PointerStyle pointerStyle;
2189         GetPointerStyle(info.windowPid, info.windowId, pointerStyle);
2190         MMI_HILOGD("Get pointer style, pid:%{public}d, windowid:%{public}d, style:%{public}d",
2191             info.windowPid, info.windowId, pointerStyle.id);
2192         if (!dragFlag_) {
2193             SetMouseFlag(lastPointerEventCopy->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_UP);
2194             isDragBorder_ = SelectPointerChangeArea(*windowInfo, pointerStyle, logicX, logicY);
2195             dragPointerStyle_ = pointerStyle;
2196             MMI_HILOGD("Not in drag SelectPointerStyle, pointerStyle is:%{public}d", dragPointerStyle_.id);
2197         }
2198         JudgMouseIsDownOrUp(dragFlag_);
2199         if (lastPointerEventCopy->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
2200             dragFlag_ = true;
2201             MMI_HILOGD("Is in drag scene");
2202         }
2203         if (lastPointerEventCopy->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_UP) {
2204             dragFlag_ = false;
2205             isDragBorder_ = false;
2206         }
2207         int32_t focusWindowId = GetFocusWindowId(groupId);
2208         bool isCursopRestoredFlag = (firstBtnDownWindowInfo_.first != focusWindowId) &&
2209             (PRODUCT_TYPE == PRODUCT_TYPE_PC) && isDragBorder_;
2210         if (isCursopRestoredFlag) {
2211             dragPointerStyle_ = pointerStyle;
2212             MMI_HILOGI("Window is changed, pointerStyle is:%{public}d", dragPointerStyle_.id);
2213         }
2214         DrawPointer(isDisplayRemoved);
2215     }
2216 }
2217 
2218 void InputWindowsManager::DispatchPointerCancel(int32_t displayId)
2219 {
2220     if (mouseDownInfo_.id < 0 || (extraData_.appended && (extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE))) {
2221         return;
2222     }
2223     auto lastPointerEventCopy = GetlastPointerEvent();
2224     CHKPV(lastPointerEventCopy);
2225     std::optional<WindowInfo> windowInfo;
2226     std::vector<WindowInfo> windowInfos = GetWindowGroupInfoByDisplayId(displayId);
2227     for (const auto &item : windowInfos) {
2228         if (item.id == mouseDownInfo_.id) {
2229             windowInfo = std::make_optional(item);
2230             break;
2231         }
2232     }
2233     if (windowInfo == std::nullopt && displayId != firstBtnDownWindowInfo_.second) {
2234         std::vector<WindowInfo> firstBtnDownWindowsInfo =
2235             GetWindowGroupInfoByDisplayId(firstBtnDownWindowInfo_.second);
2236         for (const auto &item : firstBtnDownWindowsInfo) {
2237             if (item.id == mouseDownInfo_.id) {
2238                 windowInfo = std::make_optional(item);
2239                 break;
2240             }
2241         }
2242     }
2243     if (windowInfo != std::nullopt) {
2244         return;
2245     }
2246     auto pointerEvent = PointerEvent::Create();
2247     CHKPV(pointerEvent);
2248     pointerEvent->UpdateId();
2249     LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), PointerEvent::POINTER_ACTION_CANCEL);
2250     SetPointerEvent(PointerEvent::POINTER_ACTION_CANCEL, pointerEvent);
2251     EventLogHelper::PrintEventData(pointerEvent, MMI_LOG_FREEZE);
2252     auto filter = InputHandler->GetFilterHandler();
2253     CHKPV(filter);
2254     filter->HandlePointerEvent(pointerEvent);
2255 }
2256 
2257 void InputWindowsManager::UpdatePointerDrawingManagerWindowInfo()
2258 {
2259     auto lastPointerEventCopy = GetlastPointerEvent();
2260     CHKPV(lastPointerEventCopy);
2261     MouseLocation mouseLocation = GetMouseInfo();
2262     int32_t displayId = MouseEventHdr->GetDisplayId();
2263     int32_t groupId = FindDisplayGroupId(displayId);
2264     int32_t newId = 0;
2265 
2266     const auto iter = displayGroupInfoMap_.find(groupId);
2267     if (iter != displayGroupInfoMap_.end()) {
2268         if (iter->second.displaysInfo.empty()) {
2269             MMI_HILOGW("DisplaysInfo is empty");
2270             return;
2271         }
2272         newId = iter->second.displaysInfo[0].id;
2273     } else {
2274         if (displayGroupInfo_.displaysInfo.empty()) {
2275             MMI_HILOGW("DisplaysInfo is empty");
2276             return;
2277         }
2278         newId = displayGroupInfo_.displaysInfo[0].id;
2279     }
2280     displayId = displayId < 0 ? newId : displayId;
2281     auto displayInfo = GetPhysicalDisplay(displayId);
2282     CHKPV(displayInfo);
2283     int32_t displayInfoX = GetLogicalPositionX(displayId);
2284     int32_t displayInfoY = GetLogicalPositionY(displayId);
2285     Direction DirectionCopy = GetLogicalPositionDirection(displayId);
2286     Direction DisplayDirection = GetPositionDisplayDirection(displayId);
2287     DispatchPointerCancel(displayId);
2288     int32_t logicX = mouseLocation.physicalX + displayInfoX;
2289     int32_t logicY = mouseLocation.physicalY + displayInfoY;
2290     lastLogicX_ = logicX;
2291     lastLogicY_ = logicY;
2292     std::optional<WindowInfo> windowInfo;
2293     if (lastPointerEventCopy->GetPointerAction() != PointerEvent::POINTER_ACTION_DOWN &&
2294     lastPointerEventCopy->GetPressedButtons().empty()) {
2295         PhysicalCoordinate coord {
2296             .x = logicX,
2297             .y = logicY,
2298         };
2299         Direction direction = Direction::DIRECTION0;
2300         Direction displayDirection = Direction::DIRECTION0;
2301         double cursorPosx = 0.0;
2302         double cursorPosy = 0.0;
2303 
2304         const auto iter = cursorPosMap_.find(groupId);
2305         if (iter != cursorPosMap_.end()) {
2306             direction = iter->second.direction;
2307             displayDirection = iter->second.displayDirection;
2308             cursorPosx = iter->second.cursorPos.x;
2309             cursorPosy = iter->second.cursorPos.y;
2310         }
2311         if (direction != DirectionCopy &&
2312             displayDirection == DisplayDirection) {
2313             coord.x = cursorPosx;
2314             coord.y = cursorPosy;
2315             RotateDisplayScreen(*displayInfo, coord);
2316         }
2317         windowInfo = GetWindowInfo(coord.x, coord.y, groupId);
2318     } else {
2319         windowInfo = SelectWindowInfo(logicX, logicY, lastPointerEventCopy);
2320     }
2321     CHKFRV(windowInfo, "The windowInfo is nullptr");
2322     int32_t windowPid = GetWindowPid(windowInfo->id);
2323     WinInfo info = { .windowPid = windowPid, .windowId = windowInfo->id };
2324     CursorDrawingComponent::GetInstance().OnWindowInfo(info);
2325 }
2326 
2327 void InputWindowsManager::SetPointerEvent(int32_t pointerAction, std::shared_ptr<PointerEvent> pointerEvent)
2328 {
2329     CHKPV(pointerEvent);
2330     PointerEvent::PointerItem lastPointerItem;
2331     auto lastPointerEventCopy = GetlastPointerEvent();
2332     CHKPV(lastPointerEventCopy);
2333     int32_t lastPointerId = lastPointerEventCopy->GetPointerId();
2334     if (!lastPointerEventCopy->GetPointerItem(lastPointerId, lastPointerItem)) {
2335         MMI_HILOGE("GetPointerItem:%{public}d fail", lastPointerId);
2336         return;
2337     }
2338     bool checkFlag = lastPointerItem.IsPressed() && lastWindowInfo_.id != mouseDownInfo_.id;
2339     int32_t id = lastWindowInfo_.id;
2340     if (checkFlag) {
2341         id = mouseDownInfo_.id;
2342     }
2343     PointerEvent::PointerItem currentPointerItem;
2344     currentPointerItem.SetWindowX(lastLogicX_- lastWindowInfo_.area.x);
2345     currentPointerItem.SetWindowY(lastLogicY_- lastWindowInfo_.area.y);
2346     currentPointerItem.SetWindowXPos(lastLogicX_- lastWindowInfo_.area.x);
2347     currentPointerItem.SetWindowYPos(lastLogicY_- lastWindowInfo_.area.y);
2348     currentPointerItem.SetDisplayX(lastPointerItem.GetDisplayX());
2349     currentPointerItem.SetDisplayY(lastPointerItem.GetDisplayY());
2350     GlobalCoords globalCoords = DisplayCoords2GlobalCoords({currentPointerItem.GetDisplayX(),
2351         currentPointerItem.GetDisplayY()}, lastPointerEventCopy->GetTargetDisplayId());
2352     currentPointerItem.SetGlobalX(globalCoords.x);
2353     currentPointerItem.SetGlobalY(globalCoords.y);
2354     currentPointerItem.SetDisplayXPos(lastPointerItem.GetDisplayXPos());
2355     currentPointerItem.SetDisplayYPos(lastPointerItem.GetDisplayYPos());
2356     currentPointerItem.SetPointerId(0);
2357     pointerEvent->SetTargetDisplayId(lastPointerEventCopy->GetTargetDisplayId());
2358     SetPrivacyModeFlag(lastWindowInfo_.privacyMode, pointerEvent);
2359     pointerEvent->SetTargetWindowId(id);
2360     pointerEvent->SetAgentWindowId(id);
2361     pointerEvent->SetPointerId(0);
2362     pointerEvent->SetButtonPressed(lastPointerEventCopy->GetButtonId());
2363     pointerEvent->SetButtonId(lastPointerEventCopy->GetButtonId());
2364     pointerEvent->AddPointerItem(currentPointerItem);
2365     pointerEvent->SetPointerAction(pointerAction);
2366     pointerEvent->SetOriginPointerAction(lastPointerEventCopy->GetPointerAction());
2367     pointerEvent->SetSourceType(lastPointerEventCopy->GetSourceType());
2368     int64_t time = GetSysClockTime();
2369     pointerEvent->SetActionTime(time);
2370     pointerEvent->SetActionStartTime(time);
2371     pointerEvent->SetDeviceId(lastPointerEventCopy->GetDeviceId());
2372 }
2373 
2374 bool InputWindowsManager::NeedUpdatePointDrawFlag(const std::vector<WindowInfo> &windows)
2375 {
2376     CALL_DEBUG_ENTER;
2377     return !windows.empty() && windows.back().action == WINDOW_UPDATE_ACTION::ADD_END;
2378 }
2379 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
2380 
2381 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
2382 void InputWindowsManager::SendPointerEvent(int32_t pointerAction)
2383 {
2384     CALL_INFO_TRACE;
2385     CHKPV(udsServer_);
2386     auto pointerEvent = PointerEvent::Create();
2387     CHKPV(pointerEvent);
2388     pointerEvent->UpdateId();
2389     LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerAction);
2390     MouseLocation mouseLocation = GetMouseInfo();
2391     int32_t displayInfoX = GetLogicalPositionX(mouseLocation.displayId);
2392     int32_t displayInfoY = GetLogicalPositionY(mouseLocation.displayId);
2393     lastLogicX_ = mouseLocation.physicalX + displayInfoX;
2394     lastLogicY_ = mouseLocation.physicalY + displayInfoY;
2395     if (pointerAction == PointerEvent::POINTER_ACTION_ENTER_WINDOW ||
2396         Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
2397         auto touchWindow = GetWindowInfo(lastLogicX_, lastLogicY_, MAIN_GROUPID);
2398         if (!touchWindow) {
2399             MMI_HILOGE("TouchWindow is nullptr");
2400             return;
2401         }
2402         lastWindowInfo_ = *touchWindow;
2403     }
2404     PointerEvent::PointerItem pointerItem;
2405     pointerItem.SetWindowX(lastLogicX_ - lastWindowInfo_.area.x);
2406     pointerItem.SetWindowY(lastLogicY_ - lastWindowInfo_.area.y);
2407     pointerItem.SetWindowXPos(lastLogicX_ - lastWindowInfo_.area.x);
2408     pointerItem.SetWindowYPos(lastLogicY_ - lastWindowInfo_.area.y);
2409     pointerItem.SetDisplayX(mouseLocation.physicalX);
2410     pointerItem.SetDisplayY(mouseLocation.physicalY);
2411     GlobalCoords globalCoords = DisplayCoords2GlobalCoords({mouseLocation.physicalX, mouseLocation.physicalY},
2412         mouseLocation.displayId);
2413     pointerItem.SetGlobalX(globalCoords.x);
2414     pointerItem.SetGlobalY(globalCoords.y);
2415     pointerItem.SetDisplayXPos(mouseLocation.physicalX);
2416     pointerItem.SetDisplayYPos(mouseLocation.physicalY);
2417     pointerItem.SetPointerId(0);
2418 
2419     pointerEvent->SetTargetDisplayId(-1);
2420     auto displayId = pointerEvent->GetTargetDisplayId();
2421     if (!UpdateDisplayId(displayId)) {
2422         MMI_HILOGE("This display:%{public}d is not existent", displayId);
2423         return;
2424     }
2425     pointerEvent->SetTargetDisplayId(displayId);
2426     SetPrivacyModeFlag(lastWindowInfo_.privacyMode, pointerEvent);
2427     pointerEvent->SetTargetWindowId(lastWindowInfo_.id);
2428     pointerEvent->SetAgentWindowId(lastWindowInfo_.agentWindowId);
2429     pointerEvent->SetPointerId(0);
2430     pointerEvent->AddPointerItem(pointerItem);
2431     pointerEvent->SetPointerAction(pointerAction);
2432     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2433     int64_t time = GetSysClockTime();
2434     pointerEvent->SetActionTime(time);
2435     pointerEvent->SetActionStartTime(time);
2436     pointerEvent->UpdateId();
2437     LogTracer lt1(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction());
2438     if (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) {
2439         pointerEvent->SetBuffer(extraData_.buffer);
2440         pointerEvent->SetPullId(extraData_.pullId);
2441         UpdatePointerAction(pointerEvent);
2442     } else {
2443         pointerEvent->ClearBuffer();
2444     }
2445     auto filter = InputHandler->GetFilterHandler();
2446     CHKPV(filter);
2447     filter->HandlePointerEvent(pointerEvent);
2448 }
2449 
2450 void InputWindowsManager::DispatchPointer(int32_t pointerAction, int32_t windowId)
2451 {
2452     CALL_INFO_TRACE;
2453     CHKPV(udsServer_);
2454 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
2455     if (!CursorDrawingComponent::GetInstance().GetMouseDisplayState() && !HasMouseHideFlag()) {
2456         MMI_HILOGI("The mouse is hide");
2457         return;
2458     }
2459 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
2460     auto lastPointerEventCopy = GetlastPointerEvent();
2461     if (lastPointerEventCopy == nullptr) {
2462         SendPointerEvent(pointerAction);
2463         return;
2464     }
2465     auto pointerEvent = PointerEvent::Create();
2466     CHKPV(pointerEvent);
2467     pointerEvent->UpdateId();
2468     LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerAction);
2469     PointerEvent::PointerItem lastPointerItem;
2470     int32_t lastPointerId = lastPointerEventCopy->GetPointerId();
2471     if (!lastPointerEventCopy->GetPointerItem(lastPointerId, lastPointerItem)) {
2472         MMI_HILOGE("GetPointerItem:%{public}d fail", lastPointerId);
2473         return;
2474     }
2475     if (pointerAction == PointerEvent::POINTER_ACTION_ENTER_WINDOW && windowId <= 0) {
2476         std::optional<WindowInfo> windowInfo;
2477         int32_t eventAction = lastPointerEventCopy->GetPointerAction();
2478         bool checkFlag = (eventAction == PointerEvent::POINTER_ACTION_MOVE &&
2479             lastPointerEventCopy->GetPressedButtons().empty()) ||
2480             (eventAction >= PointerEvent::POINTER_ACTION_AXIS_BEGIN &&
2481             eventAction <= PointerEvent::POINTER_ACTION_AXIS_END);
2482         if (checkFlag) {
2483             windowInfo = GetWindowInfo(lastLogicX_, lastLogicY_, MAIN_GROUPID);
2484         } else {
2485             windowInfo = SelectWindowInfo(lastLogicX_, lastLogicY_, lastPointerEventCopy);
2486         }
2487         if (!windowInfo) {
2488             MMI_HILOGE("windowInfo is nullptr");
2489             return;
2490         }
2491         if (windowInfo->id != lastWindowInfo_.id) {
2492             lastWindowInfo_ = *windowInfo;
2493         }
2494     }
2495     PointerEvent::PointerItem currentPointerItem;
2496     currentPointerItem.SetWindowX(lastLogicX_ - lastWindowInfo_.area.x);
2497     currentPointerItem.SetWindowY(lastLogicY_ - lastWindowInfo_.area.y);
2498     currentPointerItem.SetWindowXPos(lastLogicX_ - lastWindowInfo_.area.x);
2499     currentPointerItem.SetWindowYPos(lastLogicY_ - lastWindowInfo_.area.y);
2500     if (pointerAction == PointerEvent::POINTER_ACTION_ENTER_WINDOW && windowId > 0) {
2501         auto displayGroupInfo = GetDefaultDisplayGroupInfo();
2502         int32_t displayId = 0;
2503         double cursorPosx = 0.0;
2504         double cursorPosy = 0.0;
2505 
2506         const auto iter = mouseLocationMap_.find(MAIN_GROUPID);
2507         if (iter != mouseLocationMap_.end()) {
2508             displayId = iter->second.displayId;
2509             cursorPosx = iter->second.physicalX;
2510             cursorPosy = iter->second.physicalY;
2511         }
2512         currentPointerItem.SetDisplayX(cursorPosx);
2513         currentPointerItem.SetDisplayY(cursorPosy);
2514         auto mouseLocationTmp = iter->second;
2515         GlobalCoords globalCoords = DisplayCoords2GlobalCoords({mouseLocationTmp.physicalX, mouseLocationTmp.physicalY},
2516            mouseLocationTmp.displayId);
2517         currentPointerItem.SetGlobalX(globalCoords.x);
2518         currentPointerItem.SetGlobalY(globalCoords.y);
2519         currentPointerItem.SetDisplayXPos(cursorPosx);
2520         currentPointerItem.SetDisplayYPos(cursorPosy);
2521         pointerEvent->SetTargetDisplayId(displayId);
2522         if (IsMouseSimulate()) {
2523             currentPointerItem.SetWindowX(lastPointerItem.GetWindowX());
2524             currentPointerItem.SetWindowY(lastPointerItem.GetWindowY());
2525             currentPointerItem.SetWindowXPos(lastPointerItem.GetWindowXPos());
2526             currentPointerItem.SetWindowYPos(lastPointerItem.GetWindowYPos());
2527             currentPointerItem.SetDisplayX(lastPointerItem.GetDisplayX());
2528             currentPointerItem.SetDisplayY(lastPointerItem.GetDisplayY());
2529             GlobalCoords globalCoords = DisplayCoords2GlobalCoords({lastPointerItem.GetDisplayX(),
2530                 lastPointerItem.GetDisplayY()}, lastPointerEventCopy->GetTargetDisplayId());
2531             currentPointerItem.SetGlobalX(globalCoords.x);
2532             currentPointerItem.SetGlobalY(globalCoords.y);
2533             currentPointerItem.SetDisplayXPos(lastPointerItem.GetDisplayXPos());
2534             currentPointerItem.SetDisplayYPos(lastPointerItem.GetDisplayYPos());
2535             pointerEvent->SetTargetDisplayId(lastPointerEventCopy->GetTargetDisplayId());
2536         }
2537     } else {
2538         if (IsMouseSimulate()) {
2539             currentPointerItem.SetWindowX(lastPointerItem.GetWindowX());
2540             currentPointerItem.SetWindowY(lastPointerItem.GetWindowY());
2541             currentPointerItem.SetWindowXPos(lastPointerItem.GetWindowXPos());
2542             currentPointerItem.SetWindowYPos(lastPointerItem.GetWindowYPos());
2543         }
2544         currentPointerItem.SetDisplayX(lastPointerItem.GetDisplayX());
2545         currentPointerItem.SetDisplayY(lastPointerItem.GetDisplayY());
2546         GlobalCoords globalCoords = DisplayCoords2GlobalCoords({lastPointerItem.GetDisplayX(),
2547             lastPointerItem.GetDisplayY()}, lastPointerEventCopy->GetTargetDisplayId());
2548         currentPointerItem.SetGlobalX(globalCoords.x);
2549         currentPointerItem.SetGlobalY(globalCoords.y);
2550         currentPointerItem.SetDisplayXPos(lastPointerItem.GetDisplayXPos());
2551         currentPointerItem.SetDisplayYPos(lastPointerItem.GetDisplayYPos());
2552         pointerEvent->SetTargetDisplayId(lastPointerEventCopy->GetTargetDisplayId());
2553     }
2554     currentPointerItem.SetPointerId(0);
2555 
2556     SetPrivacyModeFlag(lastWindowInfo_.privacyMode, pointerEvent);
2557     pointerEvent->SetTargetWindowId(lastWindowInfo_.id);
2558     pointerEvent->SetAgentWindowId(lastWindowInfo_.agentWindowId);
2559     pointerEvent->SetPointerId(0);
2560     pointerEvent->AddPointerItem(currentPointerItem);
2561     pointerEvent->SetPointerAction(pointerAction);
2562     pointerEvent->SetSourceType(lastPointerEventCopy->GetSourceType());
2563     int64_t time = GetSysClockTime();
2564     pointerEvent->SetActionTime(time);
2565     pointerEvent->SetActionStartTime(time);
2566     pointerEvent->SetDeviceId(lastPointerEventCopy->GetDeviceId());
2567     if (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) {
2568         pointerEvent->SetBuffer(extraData_.buffer);
2569         pointerEvent->SetPullId(extraData_.pullId);
2570         UpdatePointerAction(pointerEvent);
2571     } else {
2572         pointerEvent->ClearBuffer();
2573     }
2574     if (pointerAction == PointerEvent::POINTER_ACTION_LEAVE_WINDOW) {
2575         pointerEvent->SetAgentWindowId(lastWindowInfo_.id);
2576     }
2577     PrintEnterEventInfo(pointerEvent);
2578     EventLogHelper::PrintEventData(pointerEvent, MMI_LOG_FREEZE);
2579 #ifdef OHOS_BUILD_ENABLE_POINTER
2580     auto filter = InputHandler->GetFilterHandler();
2581     CHKPV(filter);
2582     filter->HandlePointerEvent(pointerEvent);
2583 #endif // OHOS_BUILD_ENABLE_POINTER
2584 }
2585 
2586 void InputWindowsManager::PrintEnterEventInfo(std::shared_ptr<PointerEvent> pointerEvent)
2587 {
2588     int32_t pointerAc = pointerEvent->GetPointerAction();
2589     if (pointerAc == PointerEvent::POINTER_ACTION_LEAVE_WINDOW &&
2590         pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE) {
2591         auto device = INPUT_DEV_MGR->GetInputDevice(pointerEvent->GetDeviceId());
2592         CHKPV(device);
2593         MMI_HILOGE("leave-window type:%{public}d, id:%{public}d, pointerid:%{public}d, action:%{public}d by:%{public}s",
2594             pointerEvent->GetSourceType(), pointerEvent->GetId(), pointerEvent->GetPointerId(),
2595             pointerAc, device->GetName().c_str());
2596     }
2597 }
2598 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
2599 
2600 #ifdef OHOS_BUILD_ENABLE_POINTER
2601 void InputWindowsManager::NotifyPointerToWindow(int32_t groupId)
2602 {
2603     CALL_DEBUG_ENTER;
2604     std::optional<WindowInfo> windowInfo;
2605     auto lastPointerEventCopy = GetlastPointerEvent();
2606     CHKPV(lastPointerEventCopy);
2607     if ((lastPointerEventCopy->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) &&
2608         (!lastPointerEventCopy->GetPressedButtons().empty())) {
2609         MMI_HILOGD("No need to respond to new interface layouts, btnCounts:%{public}d",
2610             static_cast<int32_t>(lastPointerEventCopy->GetPressedButtons().size()));
2611         return;
2612     }
2613     if (IsMouseSimulate()) {
2614         int32_t pointerId = lastPointerEventCopy->GetPointerId();
2615         PointerEvent::PointerItem pointerItem;
2616         if (!lastPointerEventCopy->GetPointerItem(pointerId, pointerItem)) {
2617             MMI_HILOGE("Get pointer item failed, pointerId:%{public}d", pointerId);
2618             return;
2619         }
2620         windowInfo = GetWindowInfo(pointerItem.GetDisplayX(), pointerItem.GetDisplayY(), groupId);
2621     } else {
2622         windowInfo = GetWindowInfo(lastLogicX_, lastLogicY_, groupId);
2623     }
2624     if (!windowInfo) {
2625         MMI_HILOGE("The windowInfo is nullptr");
2626         return;
2627     }
2628     if (windowInfo->id == lastWindowInfo_.id) {
2629         MMI_HILOGI("The mouse pointer does not leave the window:%{public}d", lastWindowInfo_.id);
2630         lastWindowInfo_ = *windowInfo;
2631         return;
2632     }
2633     bool isFindLastWindow = false;
2634     auto &WindowsInfo = GetWindowInfoVector(groupId);
2635     for (const auto &item : WindowsInfo) {
2636         if (item.id == lastWindowInfo_.id) {
2637             DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
2638             isFindLastWindow = true;
2639             break;
2640         }
2641     }
2642     if (!isFindLastWindow) {
2643         if (udsServer_ != nullptr && udsServer_->GetClientFd(lastWindowInfo_.pid) != INVALID_FD) {
2644             DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
2645         }
2646     }
2647     lastWindowInfo_ = *windowInfo;
2648     DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW, lastWindowInfo_.id);
2649 }
2650 #endif // OHOS_BUILD_ENABLE_POINTER
2651 
2652 void InputWindowsManager::PrintHighZorder(const std::vector<WindowInfo> &windowsInfo, int32_t pointerAction,
2653     int32_t targetWindowId, int32_t logicalX, int32_t logicalY)
2654 {
2655     std::optional<WindowInfo> info = GetWindowInfoById(targetWindowId);
2656     if (!info) {
2657         return;
2658     }
2659     WindowInfo targetWindow = *info;
2660     bool isPrint = false;
2661     std::string windowPrint;
2662     windowPrint += StringPrintf("highZorder");
2663     for (const auto &windowInfo : windowsInfo) {
2664         if (MMI_GNE(windowInfo.zOrder, targetWindow.zOrder) && !windowInfo.flags &&
2665             pointerAction == PointerEvent::POINTER_ACTION_AXIS_BEGIN &&
2666             windowInfo.windowInputType != WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE &&
2667             windowInfo.windowInputType != WindowInputType::DUALTRIGGER_TOUCH &&
2668             windowInfo.windowInputType != WindowInputType::MIX_BUTTOM_ANTI_AXIS_MOVE &&
2669             windowInfo.windowInputType != WindowInputType::TRANSMIT_ALL) {
2670             if (IsInHotArea(logicalX, logicalY, windowInfo.pointerHotAreas, windowInfo)) {
2671                 PrintZorderInfo(windowInfo, windowPrint);
2672                 isPrint = true;
2673             }
2674         }
2675     }
2676     if (isPrint) {
2677         MMI_HILOGW("%{public}s", windowPrint.c_str());
2678     }
2679 }
2680 
2681 void InputWindowsManager::PrintZorderInfo(const WindowInfo &windowInfo, std::string &windowPrint)
2682 {
2683     windowPrint += StringPrintf("|");
2684     windowPrint += StringPrintf("%d", windowInfo.id);
2685     windowPrint += StringPrintf("|");
2686     windowPrint += StringPrintf("%d", windowInfo.pid);
2687     windowPrint += StringPrintf("|");
2688     windowPrint += StringPrintf("%.2f", windowInfo.zOrder);
2689     windowPrint += StringPrintf("|");
2690     for (const auto &win : windowInfo.defaultHotAreas) {
2691         windowPrint += StringPrintf("%d ", win.x);
2692         windowPrint += StringPrintf("%d ", win.y);
2693         windowPrint += StringPrintf("%d ", win.width);
2694         windowPrint += StringPrintf("%d,", win.height);
2695     }
2696     windowPrint += StringPrintf("|");
2697     for (auto it : windowInfo.transform) {
2698         windowPrint += StringPrintf("%.2f,", it);
2699     }
2700     windowPrint += StringPrintf("|");
2701 }
2702 
2703 void InputWindowsManager::PrintWindowInfo(const std::vector<WindowInfo> &windowsInfo)
2704 {
2705     std::string window;
2706     window += StringPrintf("windowId:[");
2707     for (const auto &item : windowsInfo) {
2708         MMI_HILOGD("windowsInfos, id:%{public}d, pid:%{public}d, uid:%{public}d, "
2709             "area.x:%d, area.y:%d, area.width:%{public}d, area.height:%{public}d, "
2710             "defaultHotAreas.size:%{public}zu, pointerHotAreas.size:%{public}zu, "
2711             "agentWindowId:%{public}d, flags:%{public}d, action:%{public}d, displayId:%{public}d, "
2712             "zOrder:%{public}f, privacyMode:%{public}d, privacyProtect:%{public}d, windowType:%{public}d",
2713             item.id, item.pid, item.uid, item.area.x, item.area.y, item.area.width,
2714             item.area.height, item.defaultHotAreas.size(), item.pointerHotAreas.size(),
2715             item.agentWindowId, item.flags, item.action, item.displayId, item.zOrder, item.privacyMode,
2716             item.isSkipSelfWhenShowOnVirtualScreen, static_cast<int32_t>(item.windowInputType));
2717         for (const auto &win : item.defaultHotAreas) {
2718             MMI_HILOGD("defaultHotAreas:x:%d, y:%d, width:%{public}d, height:%{public}d",
2719                 win.x, win.y, win.width, win.height);
2720         }
2721         for (const auto &pointer : item.pointerHotAreas) {
2722             MMI_HILOGD("pointerHotAreas:x:%d, y:%d, width:%{public}d, height:%{public}d",
2723                 pointer.x, pointer.y, pointer.width, pointer.height);
2724         }
2725 
2726         window += StringPrintf("%d,", item.id);
2727         std::string dump;
2728         dump += StringPrintf("pointChangeAreas:[");
2729         for (const auto &it : item.pointerChangeAreas) {
2730             dump += StringPrintf("%d,", it);
2731         }
2732         dump += StringPrintf("]\n");
2733 
2734         dump += StringPrintf("transform:[");
2735         for (const auto &it : item.transform) {
2736             dump += StringPrintf("%f,", it);
2737         }
2738         dump += StringPrintf("]\n");
2739         std::istringstream stream(dump);
2740         std::string line;
2741         while (std::getline(stream, line, '\n')) {
2742             MMI_HILOGD("%{public}s", line.c_str());
2743         }
2744         if (!item.uiExtentionWindowInfo.empty()) {
2745             PrintWindowInfo(item.uiExtentionWindowInfo);
2746         }
2747     }
2748     window += StringPrintf("]\n");
2749     MMI_HILOGI("%{public}s", window.c_str());
2750 }
2751 
2752 void InputWindowsManager::PrintWindowGroupInfo(const WindowGroupInfo &windowGroupInfo)
2753 {
2754     if (!HiLogIsLoggable(MMI_LOG_DOMAIN, MMI_LOG_TAG, LOG_DEBUG)) {
2755         return;
2756     }
2757     MMI_HILOGD("windowsGroupInfo,focusWindowId:%{public}d, displayId:%{public}d",
2758         windowGroupInfo.focusWindowId, windowGroupInfo.displayId);
2759     PrintWindowInfo(windowGroupInfo.windowsInfo);
2760 }
2761 
2762 void InputWindowsManager::PrintDisplayGroupInfo(const OLD::DisplayGroupInfo displayGroupInfo)
2763 {
2764     if (!HiLogIsLoggable(MMI_LOG_DOMAIN, MMI_LOG_TAG, LOG_DEBUG)) {
2765         return;
2766     }
2767     MMI_HILOGD("logicalInfo,focusWindowId:%{public}d,"
2768                "windowsInfosNum:%{public}zu,displayInfosNum:%{public}zu",
2769         displayGroupInfo.focusWindowId,
2770         displayGroupInfo.windowsInfo.size(),
2771         displayGroupInfo.displaysInfo.size());
2772     PrintWindowInfo(displayGroupInfo.windowsInfo);
2773     for (const auto &item : displayGroupInfo.displaysInfo) {
2774         PrintDisplayInfo(item);
2775     }
2776 }
2777 
2778 void InputWindowsManager::PrintDisplayInfo(const OLD::DisplayInfo displayInfo)
2779 {
2780     if (!HiLogIsLoggable(MMI_LOG_DOMAIN, MMI_LOG_TAG, LOG_DEBUG)) {
2781         return;
2782     }
2783     MMI_HILOGD("displayInfo{id:%{public}d, name:%{public}s, uniq:%{public}s "
2784         "XY:{%{private}d %{private}d} offsetXY:{%{private}d %{private}d} "
2785         "WH:{%{private}d %{private}d} validWH:{%{private}d %{private}d} "
2786         "direction:%{public}d, displayDirection:%{public}d, fixedDirection:%{public}d} "
2787         "oneHandXY:{%{private}d %{private}d},"
2788         "pointerActiveWidth:%{private}d, pointerActiveHeight:%{private}d",
2789         displayInfo.id,
2790         displayInfo.name.c_str(),
2791         displayInfo.uniq.c_str(),
2792         displayInfo.x,
2793         displayInfo.y,
2794         displayInfo.offsetX,
2795         displayInfo.offsetY,
2796         displayInfo.width,
2797         displayInfo.height,
2798         displayInfo.validWidth,
2799         displayInfo.validHeight,
2800         displayInfo.direction,
2801         displayInfo.displayDirection,
2802         displayInfo.fixedDirection,
2803         displayInfo.oneHandX,
2804         displayInfo.oneHandY,
2805         displayInfo.pointerActiveWidth,
2806         displayInfo.pointerActiveHeight);
2807 }
2808 
2809 const OLD::DisplayInfo *InputWindowsManager::GetPhysicalDisplay(int32_t id) const
2810 {
2811     int32_t groupId = FindDisplayGroupId(id);
2812     const auto iter = displayGroupInfoMap_.find(groupId);
2813     if (iter != displayGroupInfoMap_.end()) {
2814         for (auto &it : iter->second.displaysInfo) {
2815             if (it.id == id) {
2816                 return &it;
2817             }
2818         }
2819     } else {
2820         for (auto &it : displayGroupInfo_.displaysInfo) {
2821             if (it.id == id) {
2822                 return &it;
2823             }
2824         }
2825     }
2826     MMI_HILOGW("Failed to obtain physical(%{public}d) display", id);
2827     return nullptr;
2828 }
2829 
2830 #ifdef OHOS_BUILD_ENABLE_TOUCH
2831 const OLD::DisplayInfo *InputWindowsManager::FindPhysicalDisplayInfo(const std::string& uniq) const
2832 {
2833     for (const auto &item : displayGroupInfoMap_) {
2834         for (const auto &it : item.second.displaysInfo) {
2835             if (it.uniq == uniq) {
2836                 return &it;
2837             }
2838         }
2839     }
2840     MMI_HILOGD("Failed to search for Physical,uniq:%{public}s", uniq.c_str());
2841     OLD::DisplayGroupInfo displayGroupInfo;
2842     auto iter = displayGroupInfoMap_.find(MAIN_GROUPID);
2843     if (iter != displayGroupInfoMap_.end()) {
2844         if (iter->second.displaysInfo.size() > 0) {
2845             return &iter->second.displaysInfo[0];
2846         }
2847     }
2848     return nullptr;
2849 }
2850 
2851 const OLD::DisplayInfo *InputWindowsManager::GetDefaultDisplayInfo() const
2852 {
2853     return FindPhysicalDisplayInfo("default0");
2854 }
2855 #endif // OHOS_BUILD_ENABLE_TOUCH
2856 
2857 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
2858 void InputWindowsManager::ScreenRotateAdjustDisplayXY(const OLD::DisplayInfo& info, PhysicalCoordinate& coord) const
2859 {
2860     int32_t groupId = FindDisplayGroupId(info.id);
2861     Direction rotation = info.direction;
2862     auto it = cursorPosMap_.find(groupId);
2863     Direction lastRotation = (it != cursorPosMap_.end()) ? it->second.direction : cursorPos_.direction;
2864     int32_t width = info.validWidth;
2865     int32_t height = info.validHeight;
2866     if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled() &&
2867         (rotation == DIRECTION90 || rotation == DIRECTION270)) {
2868         height = info.validWidth;
2869         width = info.validHeight;
2870     }
2871     if ((static_cast<int32_t>(lastRotation) + 1) % 4 == static_cast<int32_t>(rotation)) {
2872         double temp = coord.x;
2873         coord.x = width - coord.y;
2874         coord.y = temp;
2875     } else if ((static_cast<int32_t>(lastRotation) + 2) % 4 == static_cast<int32_t>(rotation)) {
2876         coord.x = width - coord.x;
2877         coord.y = height - coord.y;
2878     } else {
2879         double temp = coord.y;
2880         coord.y = height -coord.x;
2881         coord.x = temp;
2882     }
2883 }
2884 
2885 void InputWindowsManager::RotateScreen90(const OLD::DisplayInfo& info, PhysicalCoordinate& coord) const
2886 {
2887     double oldX = coord.x;
2888     double oldY = coord.y;
2889     double temp = coord.x;
2890     if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
2891         coord.x = info.validHeight - 1 - coord.y;
2892     } else {
2893         coord.x = info.validWidth - 1 - coord.y;
2894     }
2895     coord.y = temp;
2896     MMI_HILOGD("DIRECTION90, physicalXY:{%f %f}->{%f %f}", oldX, oldY, coord.x, coord.y);
2897     return;
2898 }
2899 
2900 void InputWindowsManager::RotateScreen(const OLD::DisplayInfo& info, PhysicalCoordinate& coord) const
2901 {
2902     double oldX = coord.x;
2903     double oldY = coord.y;
2904     const Direction direction = info.direction;
2905     int32_t groupId = FindDisplayGroupId(info.id);
2906     if (direction == DIRECTION0) {
2907         int32_t groupId = FindDisplayGroupId(info.id);
2908         Direction directiontemp = Direction::DIRECTION0 ;
2909         Direction displaydirectiontemp = Direction::DIRECTION0 ;
2910 
2911         const auto iter = cursorPosMap_.find(groupId);
2912         if (iter != cursorPosMap_.end()) {
2913             directiontemp = iter->second.direction;
2914             displaydirectiontemp = iter->second.displayDirection;
2915         }
2916         if (displaydirectiontemp != info.displayDirection && directiontemp != info.direction) {
2917             if (directiontemp == Direction::DIRECTION90) {
2918                 double temp = coord.y;
2919                 coord.y = info.validHeight - coord.x;
2920                 coord.x = temp;
2921             } else if (directiontemp == Direction::DIRECTION270) {
2922                 double temp = coord.x;
2923                 coord.x = info.validWidth - coord.y;
2924                 coord.y = temp;
2925             }
2926         }
2927         MMI_HILOGD("DIRECTION0, physicalXY:{%f %f}->{%f %f}", oldX, oldY, coord.x, coord.y);
2928         return;
2929     }
2930     if (direction == DIRECTION90) {
2931         RotateScreen90(info, coord);
2932         return;
2933     }
2934     if (direction == DIRECTION180) {
2935         coord.x = info.validWidth - 1 - coord.x;
2936         coord.y = info.validHeight - 1 - coord.y;
2937         MMI_HILOGD("DIRECTION180, physicalXY:{%f %f}->{%f %f}", oldX, oldY, coord.x, coord.y);
2938         return;
2939     }
2940     if (direction == DIRECTION270) {
2941         double temp = coord.y;
2942         if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
2943             coord.y = info.validWidth - 1 - coord.x;
2944         } else {
2945             coord.y = info.validHeight - 1 - coord.x;
2946         }
2947         coord.x = temp;
2948         MMI_HILOGD("DIRECTION270, physicalXY:{%f %f}->{%f %f}", oldX, oldY, coord.x, coord.y);
2949     }
2950 }
2951 
2952 void InputWindowsManager::RotateDisplayScreen(const OLD::DisplayInfo& info, PhysicalCoordinate& coord)
2953 {
2954     Direction displayDirection = GetDisplayDirection(&info);
2955     bool isEnable = Rosen::SceneBoardJudgement::IsSceneBoardEnabled();
2956     double oldX = coord.x;
2957     double oldY = coord.y;
2958     if (displayDirection == DIRECTION0) {
2959         MMI_HILOGD("DIRECTION0, IsSceneBoardEnabled:%d physicalXY:{%f,%f}", isEnable, oldX, oldY);
2960         return;
2961     }
2962     if (displayDirection == DIRECTION90) {
2963         double temp = coord.x;
2964         if (!isEnable) {
2965             coord.x = info.validHeight - 1 - coord.y;
2966         } else {
2967             coord.x = info.validWidth - 1 - coord.y;
2968         }
2969         coord.y = temp;
2970         MMI_HILOGD(
2971             "DIRECTION90, IsSceneBoardEnabled:%d physicalXY:{%f,%f}->{%f,%f}", isEnable, oldX, oldY, coord.x, coord.y);
2972         return;
2973     }
2974     if (displayDirection == DIRECTION180) {
2975         coord.x = info.validWidth - 1 - coord.x;
2976         coord.y = info.validHeight - 1 - coord.y;
2977         MMI_HILOGD(
2978             "DIRECTION180, IsSceneBoardEnabled:%d physicalXY:{%f,%f}->{%f,%f}", isEnable, oldX, oldY, coord.x, coord.y);
2979         return;
2980     }
2981     if (displayDirection == DIRECTION270) {
2982         double temp = coord.y;
2983         if (!isEnable) {
2984             coord.y = info.validWidth - 1 - coord.x;
2985         } else {
2986             coord.y = info.validHeight - 1 - coord.x;
2987         }
2988         coord.x = temp;
2989         MMI_HILOGD(
2990             "DIRECTION270, IsSceneBoardEnabled:%d physicalXY:{%f,%f}->{%f,%f}", isEnable, oldX, oldY, coord.x, coord.y);
2991     }
2992 }
2993 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
2994 
2995 #ifdef OHOS_BUILD_ENABLE_TOUCH
2996 bool InputWindowsManager::GetPhysicalDisplayCoord(struct libinput_event_touch* touch,
2997     const OLD::DisplayInfo& info, EventTouch& touchInfo, bool isNeedClear)
2998 {
2999     PrintDisplayInfo(info);
3000     auto width = info.width;
3001     auto height = info.height;
3002     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
3003         if (info.direction == DIRECTION90 || info.direction == DIRECTION270) {
3004             width = info.height;
3005             height = info.width;
3006         }
3007     }
3008 
3009     PhysicalCoordinate coord {
3010         .x = libinput_event_touch_get_x_transformed(touch, width),
3011         .y = libinput_event_touch_get_y_transformed(touch, height - info.expandHeight),
3012     };
3013     MMI_HILOGD("width:%{private}d, height:%{private}d, physicalX:%{private}f, physicalY:%{private}f",
3014         width, height, coord.x, coord.y);
3015     Coordinate2D pos = { .x = coord.x, .y = coord.y };
3016     if (IsPositionOutValidDisplay(pos, info, true)) {
3017         MMI_HILOGW("Position out valid display width:%{private}d, height:%{private}d, "
3018             "physicalX:%{private}f, physicalY:%{private}f", width, height, pos.x, pos.y);
3019         if (isNeedClear) {
3020             int32_t seatSlot = libinput_event_touch_get_seat_slot(touch);
3021             TriggerTouchUpOnInvalidAreaEntry(seatSlot);
3022         }
3023         return false;
3024     }
3025     MMI_HILOGD("IsPositionOutValidDisplay physicalXY:{%{private}f %{private}f}->{%{private}f %{private}f}",
3026         coord.x, coord.y, pos.x, pos.y);
3027     coord.x = pos.x;
3028     coord.y = pos.y;
3029     RotateScreen(info, coord);
3030     touchInfo.coordF = coord;
3031     touchInfo.point.x = static_cast<int32_t>(coord.x);
3032     touchInfo.point.y = static_cast<int32_t>(coord.y);
3033 
3034     touchInfo.globalCoord.x =  info.x + touchInfo.point.x;
3035     touchInfo.globalCoord.y =  info.y + touchInfo.point.y;
3036 
3037     touchInfo.toolRect.point.x = static_cast<int32_t>(libinput_event_touch_get_tool_x_transformed(touch, width));
3038     touchInfo.toolRect.point.y =
3039         static_cast<int32_t>(libinput_event_touch_get_tool_y_transformed(touch, height - info.expandHeight));
3040     touchInfo.toolRect.width = static_cast<int32_t>(
3041         libinput_event_touch_get_tool_width_transformed(touch, width));
3042     touchInfo.toolRect.height = static_cast<int32_t>(
3043         libinput_event_touch_get_tool_height_transformed(touch, height));
3044     return true;
3045 }
3046 
3047 // When the finger moves out of the active area, the touch up event is triggered
3048 void InputWindowsManager::TriggerTouchUpOnInvalidAreaEntry(int32_t pointerId)
3049 {
3050     if (lastPointerEventforGesture_ == nullptr) {
3051         MMI_HILOGE("lastPointerEventforGesture_ is null");
3052         return;
3053     }
3054     PointerEvent::PointerItem item;
3055     if (!(lastPointerEventforGesture_->GetPointerItem(pointerId, item))) {
3056         MMI_HILOGE("Get pointer item failed, pointerId:%{public}d", pointerId);
3057         return;
3058     }
3059     // Make sure to trigger touch up the first time out of the valid area
3060     if ((!item.IsCanceled()) && item.IsPressed()) {
3061         auto pointerEvent = std::make_shared<PointerEvent>(*lastPointerEventforGesture_);
3062         int32_t originAction = pointerEvent->GetPointerAction();
3063         pointerEvent->SetOriginPointerAction(originAction);
3064         int32_t action = PointerEvent::POINTER_ACTION_UP;
3065         bool isDragging = extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN &&
3066                           (item.GetToolType() == PointerEvent::TOOL_TYPE_FINGER && extraData_.pointerId == pointerId);
3067         if (isDragging) {
3068             action = PointerEvent::POINTER_ACTION_PULL_UP;
3069         }
3070         pointerEvent->SetPointerAction(action);
3071         pointerEvent->SetPointerId(pointerId);
3072         auto now = GetSysClockTime();
3073         pointerEvent->SetActionTime(now);
3074         pointerEvent->SetTargetWindowId(item.GetTargetWindowId());
3075         auto winOpt = GetWindowAndDisplayInfo(item.GetTargetWindowId(), pointerEvent->GetTargetDisplayId());
3076         if (winOpt) {
3077             pointerEvent->SetAgentWindowId(winOpt->agentWindowId);
3078         }
3079         pointerEvent->UpdateId();
3080         auto eventDispatchHandler = InputHandler->GetEventDispatchHandler();
3081         CHKPV(eventDispatchHandler);
3082         eventDispatchHandler->HandleTouchEvent(pointerEvent);
3083         MMI_HILOGI("Trigger touch up, pointerId:%{public}d, pointerAction:%{public}d", pointerId, action);
3084 
3085         // Flag event have been cleaned up
3086         item.SetCanceled(true);
3087         lastPointerEventforGesture_->UpdatePointerItem(pointerId, item);
3088     }
3089 }
3090 
3091 void InputWindowsManager::SetAntiMisTake(bool state)
3092 {
3093     antiMistake_.isOpen = state;
3094 }
3095 
3096 void InputWindowsManager::SetAntiMisTakeStatus(bool state)
3097 {
3098     isOpenAntiMisTakeObserver_ = state;
3099 }
3100 
3101 bool InputWindowsManager::TouchPointToDisplayPoint(int32_t deviceId, struct libinput_event_touch* touch,
3102     EventTouch& touchInfo, int32_t& physicalDisplayId, bool isNeedClear)
3103 {
3104     CHKPF(touch);
3105     std::string screenId = bindInfo_.GetBindDisplayNameByInputDevice(deviceId);
3106     if (screenId.empty() || (PRODUCT_TYPE == PRODUCT_TYPE_PC)) {
3107         screenId = "default0";
3108     }
3109     auto info = FindPhysicalDisplayInfo(screenId);
3110     CHKPF(info);
3111     physicalDisplayId = info->id;
3112     if ((info->width <= 0) || (info->height <= 0)) {
3113         MMI_HILOGE("Get OLD::DisplayInfo is error");
3114         return false;
3115     }
3116     return GetPhysicalDisplayCoord(touch, *info, touchInfo, isNeedClear);
3117 }
3118 
3119 bool InputWindowsManager::TransformTipPoint(struct libinput_event_tablet_tool* tip,
3120     PhysicalCoordinate& coord, int32_t& displayId)
3121 {
3122     CHKPF(tip);
3123     auto displayInfo = FindPhysicalDisplayInfo("default0");
3124     CHKPF(displayInfo);
3125     MMI_HILOGD("PhysicalDisplay.width:%{public}d, PhysicalDisplay.height:%{public}d, "
3126                "PhysicalDisplay.topLeftX:%{private}d, PhysicalDisplay.topLeftY:%{private}d",
3127                displayInfo->width, displayInfo->height, displayInfo->x, displayInfo->y);
3128     displayId = displayInfo->id;
3129     auto width = displayInfo->width;
3130     auto height = displayInfo->height;
3131     if (displayInfo->direction == DIRECTION90 || displayInfo->direction == DIRECTION270) {
3132         width = displayInfo->height;
3133         height = displayInfo->width;
3134     }
3135     PhysicalCoordinate phys {
3136         .x = libinput_event_tablet_tool_get_x_transformed(tip, width),
3137         .y = libinput_event_tablet_tool_get_y_transformed(tip, height),
3138     };
3139     MMI_HILOGD("width:%{private}d, height:%{private}d, physicalX:%{private}f, physicalY:%{private}f",
3140         width, height, phys.x, phys.y);
3141     Coordinate2D pos = { .x = phys.x, .y = phys.y };
3142     if (IsPositionOutValidDisplay(pos, *displayInfo, true)) {
3143         MMI_HILOGD("The position is out of the valid display");
3144         return false;
3145     }
3146     MMI_HILOGD("IsPositionOutValidDisplay physicalXY:{%{private}f %{private}f}->{%{private}f %{private}f}",
3147         phys.x, phys.y, pos.x, pos.y);
3148     coord.x = pos.x;
3149     coord.y = pos.y;
3150     RotateScreen(*displayInfo, coord);
3151     MMI_HILOGD("physicalX:%{private}f, physicalY:%{private}f, displayId:%{public}d", pos.x, pos.y, displayId);
3152     return true;
3153 }
3154 
3155 bool InputWindowsManager::CalculateTipPoint(struct libinput_event_tablet_tool* tip,
3156     int32_t& targetDisplayId, PhysicalCoordinate& coord)
3157 {
3158     CHKPF(tip);
3159     return TransformTipPoint(tip, coord, targetDisplayId);
3160 }
3161 #endif // OHOS_BUILD_ENABLE_TOUCH
3162 
3163 #ifdef OHOS_BUILD_ENABLE_POINTER
3164 const OLD::DisplayGroupInfo InputWindowsManager::GetDisplayGroupInfo(int32_t groupId)
3165 {
3166     auto iter = displayGroupInfoMap_.find(groupId);
3167     if (iter != displayGroupInfoMap_.end()) {
3168         return iter->second;
3169     }
3170     return displayGroupInfo_;
3171 }
3172 
3173 const std::vector<OLD::DisplayInfo>& InputWindowsManager::GetDisplayInfoVector(int32_t groupId) const
3174 {
3175     const auto &groupInfo = displayGroupInfoMap_.find(groupId);
3176     if (groupInfo != displayGroupInfoMap_.end()) {
3177         const auto &displaysInfo = groupInfo->second.displaysInfo;
3178         return displaysInfo;
3179     }
3180     const auto &mainGroupInfo = displayGroupInfoMap_.find(MAIN_GROUPID);
3181     if (mainGroupInfo != displayGroupInfoMap_.end()) {
3182         const auto &displaysInfo = mainGroupInfo->second.displaysInfo;
3183         return displaysInfo;
3184     }
3185     return displayGroupInfo_.displaysInfo;
3186 }
3187 
3188 const std::vector<WindowInfo>& InputWindowsManager::GetWindowInfoVector(int32_t groupId) const
3189 {
3190     const auto &groupInfo = displayGroupInfoMap_.find(groupId);
3191     if (groupInfo != displayGroupInfoMap_.end()) {
3192         const auto &windowsInfo = groupInfo->second.windowsInfo;
3193         return windowsInfo;
3194     }
3195     const auto &mainGroupInfo = displayGroupInfoMap_.find(MAIN_GROUPID);
3196     if (mainGroupInfo != displayGroupInfoMap_.end()) {
3197         const auto &windowsInfo = mainGroupInfo->second.windowsInfo;
3198         return windowsInfo;
3199     }
3200     return displayGroupInfo_.windowsInfo;
3201 }
3202 
3203 int32_t InputWindowsManager::GetFocusWindowId(int32_t groupId) const
3204 {
3205     auto iter = displayGroupInfoMap_.find(groupId);
3206     if (iter != displayGroupInfoMap_.end()) {
3207         return iter->second.focusWindowId;
3208     }
3209     iter = displayGroupInfoMap_.find(MAIN_GROUPID);
3210     if (iter != displayGroupInfoMap_.end()) {
3211         return iter->second.focusWindowId;
3212     }
3213     return 0;
3214 }
3215 
3216 int32_t InputWindowsManager::GetLogicalPositionX(int32_t id)
3217 {
3218     int32_t groupId = FindDisplayGroupId(id);
3219     const auto iter = displayGroupInfoMap_.find(groupId);
3220     if (iter != displayGroupInfoMap_.end()) {
3221         for (auto &it : iter->second.displaysInfo) {
3222             if (it.id == id) {
3223                 return it.x;
3224             }
3225         }
3226     } else {
3227         for (auto &it : displayGroupInfo_.displaysInfo) {
3228             if (it.id == id) {
3229                 return it.x;
3230             }
3231         }
3232     }
3233     MMI_HILOGW("Failed to LogicalPosition");
3234     return DEFAULT_POSITION;
3235 }
3236 
3237 int32_t InputWindowsManager::GetLogicalPositionY(int32_t id)
3238 {
3239     int32_t groupId = FindDisplayGroupId(id);
3240     const auto iter = displayGroupInfoMap_.find(groupId);
3241     if (iter != displayGroupInfoMap_.end()) {
3242         for (auto &it : iter->second.displaysInfo) {
3243             if (it.id == id) {
3244                 return it.y;
3245             }
3246         }
3247     } else {
3248         for (auto &it : displayGroupInfo_.displaysInfo) {
3249             if (it.id == id) {
3250                 return it.y;
3251             }
3252         }
3253     }
3254     MMI_HILOGW("Failed to LogicalPosition");
3255     return DEFAULT_POSITION;
3256 }
3257 
3258 Direction InputWindowsManager::GetLogicalPositionDirection(int32_t id)
3259 {
3260     int32_t groupId = FindDisplayGroupId(id);
3261     const auto iter = displayGroupInfoMap_.find(groupId);
3262     if (iter != displayGroupInfoMap_.end()) {
3263         for (auto &it : iter->second.displaysInfo) {
3264             if (it.id == id) {
3265                 return it.direction;
3266             }
3267         }
3268     } else {
3269         for (auto &it : displayGroupInfo_.displaysInfo) {
3270             if (it.id == id) {
3271                 return it.direction;
3272             }
3273         }
3274     }
3275     MMI_HILOGW("Failed to get direction");
3276     return Direction::DIRECTION0;
3277 }
3278 
3279 Direction InputWindowsManager::GetPositionDisplayDirection(int32_t id)
3280 {
3281     int32_t groupId = FindDisplayGroupId(id);
3282     const auto iter = displayGroupInfoMap_.find(groupId);
3283     if (iter != displayGroupInfoMap_.end()) {
3284         for (auto &it : iter->second.displaysInfo) {
3285             if (it.id == id) {
3286                 return it.displayDirection;
3287             }
3288         }
3289     } else {
3290         for (auto &it : displayGroupInfo_.displaysInfo) {
3291             if (it.id == id) {
3292                 return it.displayDirection;
3293             }
3294         }
3295     }
3296     MMI_HILOGW("Failed to get direction");
3297     return Direction::DIRECTION0;
3298 }
3299 
3300 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
3301 bool InputWindowsManager::IsNeedRefreshLayer(int32_t windowId)
3302 {
3303     CALL_DEBUG_ENTER;
3304     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
3305         return true;
3306     }
3307     MouseLocation mouseLocation = GetMouseInfo();
3308     int32_t displayId = MouseEventHdr->GetDisplayId();
3309     int32_t groupId = FindDisplayGroupId(displayId);
3310     int32_t newId = 0;
3311     const auto iter = displayGroupInfoMap_.find(groupId);
3312     if (iter != displayGroupInfoMap_.end()) {
3313         if (iter->second.displaysInfo.empty()) {
3314             MMI_HILOGW("DisplaysInfo is empty");
3315             return false;
3316         }
3317         newId = iter->second.displaysInfo[0].id;
3318     } else {
3319         if (displayGroupInfo_.displaysInfo.empty()) {
3320             MMI_HILOGW("DisplaysInfo is empty");
3321             return false;
3322         }
3323         newId = displayGroupInfo_.displaysInfo[0].id;
3324     }
3325     if (displayId < 0) {
3326         displayId = newId;
3327     }
3328     int32_t displayInfoX = GetLogicalPositionX(displayId);
3329     int32_t displayInfoY = GetLogicalPositionY(displayId);
3330     int32_t logicX = mouseLocation.physicalX + displayInfoX;
3331     int32_t logicY = mouseLocation.physicalY + displayInfoY;
3332     std::optional<WindowInfo> touchWindow = GetWindowInfo(logicX, logicY, groupId);
3333     if (!touchWindow) {
3334         MMI_HILOGE("TouchWindow is nullptr");
3335         return false;
3336     }
3337     if (touchWindow->id == windowId || windowId == GLOBAL_WINDOW_ID) {
3338         MMI_HILOGD("Need refresh pointer style, focusWindow type:%{public}d, window type:%{public}d",
3339             touchWindow->id, windowId);
3340         return true;
3341     }
3342     MMI_HILOGD("Not need refresh pointer style, focusWindow type:%{public}d, window type:%{public}d",
3343         touchWindow->id, windowId);
3344     return false;
3345 }
3346 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
3347 
3348 void InputWindowsManager::OnSessionLost(SessionPtr session)
3349 {
3350     CALL_DEBUG_ENTER;
3351     CHKPV(session);
3352     int32_t pid = session->GetPid();
3353     CursorDrawingComponent::GetInstance().OnSessionLost(pid);
3354     auto it = pointerStyle_.find(pid);
3355     if (it != pointerStyle_.end()) {
3356         pointerStyle_.erase(it);
3357         MMI_HILOGD("Clear the pointer style map, pd:%{public}d", pid);
3358     }
3359 }
3360 #endif // OHOS_BUILD_ENABLE_POINTER
3361 
3362 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
3363 int32_t InputWindowsManager::UpdatePoinerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle)
3364 {
3365     CALL_DEBUG_ENTER;
3366     auto it = pointerStyle_.find(pid);
3367     if (it == pointerStyle_.end()) {
3368         MMI_HILOG_CURSORE("The pointer style map is not include param pd:%{public}d", pid);
3369         return COMMON_PARAMETER_ERROR;
3370     }
3371     auto iter = it->second.find(windowId);
3372     if (iter != it->second.end()) {
3373         iter->second = pointerStyle;
3374         return RET_OK;
3375     }
3376 
3377     auto [iterator, sign] = it->second.insert(std::make_pair(windowId, pointerStyle));
3378     if (!sign) {
3379         MMI_HILOG_CURSORW("The window type is duplicated");
3380         return COMMON_PARAMETER_ERROR;
3381     }
3382     return RET_OK;
3383 }
3384 
3385 int32_t InputWindowsManager::UpdateSceneBoardPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle,
3386     bool isUiExtension)
3387 {
3388     CALL_DEBUG_ENTER;
3389     auto scenePid = pid;
3390     auto sceneWinId = windowId;
3391     if (isUiExtension) {
3392         auto iter = uiExtensionPointerStyle_.find(scenePid);
3393         if (iter == uiExtensionPointerStyle_.end() || iter->second.find(sceneWinId) == iter->second.end()) {
3394             uiExtensionPointerStyle_[scenePid] = {};
3395             MMI_HILOG_CURSORE("SceneBoardPid %{public}d or windowId:%{public}d does not exist on"
3396                 "uiExtensionPointerStyle_", scenePid, sceneWinId);
3397         }
3398         uiExtensionPointerStyle_[scenePid][sceneWinId] = pointerStyle;
3399         MMI_HILOG_CURSORI("set uiextension pointer success. pid:%{public}d, windowid:%{public}d, pointerid:%{public}d",
3400             scenePid, sceneWinId, pointerStyle.id);
3401         return RET_OK;
3402     }
3403     auto sceneIter = pointerStyle_.find(scenePid);
3404     if (sceneIter == pointerStyle_.end()) {
3405         pointerStyle_[scenePid] = {};
3406     } else if (sceneIter->second.find(sceneWinId) == sceneIter->second.end()) {
3407         if (sceneIter->second.size() > POINTER_STYLE_WINDOW_NUM) {
3408             pointerStyle_[scenePid] = {};
3409             MMI_HILOG_CURSORE("SceneBoardPid %{public}d windowId:%{public}d exceed",
3410                 scenePid, sceneWinId);
3411         }
3412     }
3413     pointerStyle_[scenePid][sceneWinId] = pointerStyle;
3414     MMI_HILOG_CURSORD("Sceneboard pid:%{public}d windowId:%{public}d is set to %{public}d",
3415         scenePid, sceneWinId, pointerStyle.id);
3416     auto it = pointerStyle_.find(pid);
3417     if (it == pointerStyle_.end()) {
3418         MMI_HILOG_CURSORE("Pid:%{public}d does not exist in mmi,", pid);
3419         std::map<int32_t, PointerStyle> tmpPointerStyle = {{windowId, pointerStyle}};
3420         auto res = pointerStyle_.insert(std::make_pair(pid, tmpPointerStyle));
3421         if (!res.second) return RET_ERR;
3422         return RET_OK;
3423     }
3424     auto iter = it->second.find(windowId);
3425     if (iter == it->second.end()) {
3426         auto res = it->second.insert(std::make_pair(windowId, pointerStyle));
3427         if (!res.second) return RET_ERR;
3428         return RET_OK;
3429     }
3430     iter->second = pointerStyle;
3431     SetMouseFlag(pointerActionFlag_ == PointerEvent::POINTER_ACTION_BUTTON_DOWN);
3432     UpdateCustomStyle(windowId, pointerStyle);
3433     return RET_OK;
3434 }
3435 
3436 void InputWindowsManager::UpdateCustomStyle(int32_t windowId, PointerStyle pointerStyle)
3437 {
3438     if (pointerStyle.id != MOUSE_ICON::DEVELOPER_DEFINED_ICON) {
3439         return;
3440     }
3441     for (auto &item : pointerStyle_) {
3442         for (auto &innerIt : item.second) {
3443             if (innerIt.first != windowId && innerIt.second.id == MOUSE_ICON::DEVELOPER_DEFINED_ICON) {
3444                 innerIt.second.id = MOUSE_ICON::DEFAULT;
3445             }
3446         }
3447     }
3448 }
3449 
3450 void InputWindowsManager::SetUiExtensionInfo(bool isUiExtension, int32_t uiExtensionPid, int32_t uiExtensionWindoId)
3451 {
3452     MMI_HILOGI("SetUiExtensionInfo. pid:%{public}d, windowid:%{public}d", uiExtensionPid, uiExtensionWindoId);
3453     isUiExtension_ = isUiExtension;
3454     uiExtensionPid_ = uiExtensionPid;
3455     uiExtensionWindowId_ = uiExtensionWindoId;
3456 }
3457 
3458 void InputWindowsManager::SetGlobalDefaultPointerStyle()
3459 {
3460     for (auto &iter : pointerStyle_) {
3461         for (auto &item : iter.second) {
3462             if (item.second.id == CURSOR_CIRCLE_STYLE || item.second.id == AECH_DEVELOPER_DEFINED_STYLE) {
3463                 item.second.id = globalStyle_.id;
3464             }
3465             item.second.options = globalStyle_.options;
3466         }
3467     }
3468 }
3469 
3470 int32_t InputWindowsManager::SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle,
3471     bool isUiExtension)
3472 {
3473     CALL_DEBUG_ENTER;
3474     if (windowId == GLOBAL_WINDOW_ID) {
3475         globalStyle_.id = pointerStyle.id;
3476         globalStyle_.options = pointerStyle.options;
3477         SetGlobalDefaultPointerStyle();
3478         MMI_HILOG_CURSORD("Setting global pointer style");
3479         return RET_OK;
3480     }
3481     MMI_HILOG_CURSORD("Start to get pid by window %{public}d", windowId);
3482     if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
3483         return UpdatePoinerStyle(pid, windowId, pointerStyle);
3484     }
3485     if (!isUiExtension && uiExtensionPointerStyle_.count(pid) != 0) {
3486         MMI_HILOG_CURSORI("Clear the uiextension mouse style for pid %{public}d", pid);
3487         uiExtensionPointerStyle_.erase(pid);
3488     }
3489     SetUiExtensionInfo(isUiExtension, pid, windowId);
3490     return UpdateSceneBoardPointerStyle(pid, windowId, pointerStyle, isUiExtension);
3491 }
3492 
3493 bool InputWindowsManager::IsMouseSimulate()
3494 {
3495     auto lastPointerEventCopy = GetlastPointerEvent();
3496     CHKPF(lastPointerEventCopy);
3497     return lastPointerEventCopy->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE &&
3498     lastPointerEventCopy->HasFlag(InputEvent::EVENT_FLAG_SIMULATE);
3499 }
3500 
3501 bool InputWindowsManager::HasMouseHideFlag()
3502 {
3503     auto lastPointerEventCopy = GetlastPointerEvent();
3504     CHKPF(lastPointerEventCopy);
3505     int32_t pointerId = lastPointerEventCopy->GetPointerId();
3506     PointerEvent::PointerItem pointerItem;
3507     if (!lastPointerEventCopy->GetPointerItem(pointerId, pointerItem)) {
3508         MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId);
3509         return false;
3510     }
3511     return (lastPointerEventCopy->HasFlag(InputEvent::EVENT_FLAG_HIDE_POINTER) ||
3512         pointerItem.GetMoveFlag() == POINTER_MOVEFLAG);
3513 }
3514 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
3515 
3516 int32_t InputWindowsManager::ClearWindowPointerStyle(int32_t pid, int32_t windowId)
3517 {
3518     CALL_DEBUG_ENTER;
3519 #ifdef OHOS_BUILD_ENABLE_POINTER
3520     auto it = pointerStyle_.find(pid);
3521     if (it == pointerStyle_.end()) {
3522         MMI_HILOG_CURSORE("Pid:%{public}d does not exist in mmi", pid);
3523         return RET_OK;
3524     }
3525     auto windowIt = it->second.find(windowId);
3526     if (windowIt == it->second.end()) {
3527         MMI_HILOG_CURSORE("windowId %{public}d does not exist in pid%{public}d", windowId, pid);
3528         return RET_OK;
3529     }
3530 
3531     it->second.erase(windowIt);
3532 #endif // OHOS_BUILD_ENABLE_POINTER
3533     return RET_OK;
3534 }
3535 
3536 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
3537 int32_t InputWindowsManager::GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle,
3538     bool isUiExtension) const
3539 {
3540     CALL_DEBUG_ENTER;
3541     if (isUiExtension) {
3542         auto it = uiExtensionPointerStyle_.find(pid);
3543         if (it == uiExtensionPointerStyle_.end()) {
3544             MMI_HILOG_CURSORE("The uiextension pointer style map is not include pid:%{public}d", pid);
3545             pointerStyle.id = globalStyle_.id;
3546             return RET_OK;
3547         }
3548         auto iter = it->second.find(windowId);
3549         if (iter == it->second.end()) {
3550             pointerStyle.id = globalStyle_.id;
3551             return RET_OK;
3552         }
3553         MMI_HILOG_CURSORI("window type:%{public}d, get pointer style:%{public}d success", windowId, iter->second.id);
3554         pointerStyle = iter->second;
3555         return RET_OK;
3556     }
3557     if (windowId == GLOBAL_WINDOW_ID) {
3558         MMI_HILOG_CURSORD("Getting global pointer style");
3559         pointerStyle.id = globalStyle_.id;
3560         pointerStyle.options = globalStyle_.options;
3561         return RET_OK;
3562     }
3563     auto it = pointerStyle_.find(pid);
3564     if (it == pointerStyle_.end()) {
3565         if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
3566             pointerStyle.id = globalStyle_.id;
3567             return RET_OK;
3568         }
3569         MMI_HILOG_CURSORE("The pointer style map is not include param pd, %{public}d", pid);
3570         return RET_OK;
3571     }
3572     auto iter = it->second.find(windowId);
3573     if (iter == it->second.end()) {
3574         pointerStyle.id = globalStyle_.id;
3575         return RET_OK;
3576     }
3577     if (iter->second.id == DEFAULT_POINTER_STYLE) {
3578         pointerStyle.id = globalStyle_.id;
3579     } else {
3580         pointerStyle = iter->second;
3581     }
3582     MMI_HILOG_CURSORD("Window type:%{public}d get pointer style:%{public}d success", windowId, pointerStyle.id);
3583     return RET_OK;
3584 }
3585 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
3586 
3587 #ifdef OHOS_BUILD_ENABLE_POINTER
3588 void InputWindowsManager::InitPointerStyle(int32_t groupId)
3589 {
3590     CALL_DEBUG_ENTER;
3591     PointerStyle pointerStyle;
3592     pointerStyle.id = DEFAULT_POINTER_STYLE;
3593     auto &WindowsInfo = GetWindowInfoVector(groupId);
3594     for (const auto& windowItem : WindowsInfo) {
3595         int32_t pid = windowItem.pid;
3596         auto it = pointerStyle_.find(pid);
3597         if (it == pointerStyle_.end()) {
3598             std::map<int32_t, PointerStyle> tmpPointerStyle = {};
3599             auto iter = pointerStyle_.insert(std::make_pair(pid, tmpPointerStyle));
3600             if (!iter.second) {
3601                 MMI_HILOGW("The pd is duplicated");
3602             }
3603             continue;
3604         }
3605     }
3606     MMI_HILOGD("Number of pointer style:%{public}zu", pointerStyle_.size());
3607 }
3608 
3609 #endif // OHOS_BUILD_ENABLE_POINTER
3610 
3611 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
3612 bool InputWindowsManager::IsInHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects,
3613     const WindowInfo &window) const
3614 {
3615     auto windowXY = TransformWindowXY(window, x, y);
3616     auto windowX = static_cast<int32_t>(windowXY.first);
3617     auto windowY = static_cast<int32_t>(windowXY.second);
3618     for (const auto &item : rects) {
3619         int32_t displayMaxX = 0;
3620         int32_t displayMaxY = 0;
3621         if (!AddInt32(item.x - currentDisplayXY_.first, item.width, displayMaxX)) {
3622             MMI_HILOGE("The addition of displayMaxX overflows");
3623             return false;
3624         }
3625         if (!AddInt32(item.y - currentDisplayXY_.second, item.height, displayMaxY)) {
3626             MMI_HILOGE("The addition of displayMaxY overflows");
3627             return false;
3628         }
3629         if (((windowX >= (item.x - currentDisplayXY_.first)) && (windowX < displayMaxX)) &&
3630             (windowY >= (item.y - currentDisplayXY_.second)) && (windowY < displayMaxY)) {
3631             lastWinX_ = windowX;
3632             lastWinY_ = windowY;
3633             return true;
3634         }
3635     }
3636     return false;
3637 }
3638 
3639 bool InputWindowsManager::InWhichHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects,
3640     PointerStyle &pointerStyle) const
3641 {
3642     int32_t areaNum = 0;
3643     bool findFlag = false;
3644     for (const auto &item : rects) {
3645         if (item.width == 0 || item.height == 0) {
3646             MMI_HILOGD("The width or height of hotArea is 0, width: %{public}d, height: %{public}d, "
3647                 "areaNum: %{public}d", item.width, item.height, areaNum);
3648             areaNum++;
3649             continue;
3650         }
3651         int32_t displayMaxX = 0;
3652         int32_t displayMaxY = 0;
3653         if (!AddInt32(item.x, item.width, displayMaxX)) {
3654             MMI_HILOGE("The addition of displayMaxX overflows");
3655             return findFlag;
3656         }
3657         if (!AddInt32(item.y, item.height, displayMaxY)) {
3658             MMI_HILOGE("The addition of displayMaxY overflows");
3659             return findFlag;
3660         }
3661         if (((x >= item.x) && (x <= displayMaxX)) && (y >= item.y) && (y <= displayMaxY)) {
3662             findFlag = true;
3663             pointerStyle.id = areaNum;
3664         }
3665         areaNum++;
3666     }
3667     if (!findFlag) {
3668         MMI_HILOGD("pointer not match any area");
3669         return findFlag;
3670     }
3671     switch (pointerStyle.id) {
3672         case PointerHotArea::TOP:
3673         case PointerHotArea::BOTTOM:
3674             pointerStyle.id = MOUSE_ICON::NORTH_SOUTH;
3675             break;
3676         case PointerHotArea::LEFT:
3677         case PointerHotArea::RIGHT:
3678             pointerStyle.id = MOUSE_ICON::WEST_EAST;
3679             break;
3680         case PointerHotArea::TOP_LEFT:
3681             pointerStyle.id = MOUSE_ICON::NORTH_WEST_SOUTH_EAST;
3682             break;
3683         case PointerHotArea::TOP_RIGHT:
3684             pointerStyle.id = MOUSE_ICON::NORTH_EAST_SOUTH_WEST;
3685             break;
3686         case PointerHotArea::BOTTOM_LEFT:
3687             pointerStyle.id = MOUSE_ICON::NORTH_EAST_SOUTH_WEST;
3688             break;
3689         case PointerHotArea::BOTTOM_RIGHT:
3690             pointerStyle.id = MOUSE_ICON::NORTH_WEST_SOUTH_EAST;
3691             break;
3692         default:
3693             MMI_HILOGD("pointerStyle in default is:%{public}d", pointerStyle.id);
3694             break;
3695     }
3696     MMI_HILOGD("pointerStyle after switch ID is :%{public}d", pointerStyle.id);
3697     return findFlag;
3698 }
3699 
3700 bool InputWindowsManager::InWhichHotArea(int32_t x, int32_t y, const std::vector<Rect> &rects) const
3701 {
3702     bool findFlag = false;
3703     for (const auto &item : rects) {
3704         int32_t displayMaxX = 0;
3705         int32_t displayMaxY = 0;
3706         if (!AddInt32(item.x, item.width, displayMaxX)) {
3707             MMI_HILOGE("The addition of displayMaxX overflows");
3708             return findFlag;
3709         }
3710         if (!AddInt32(item.y, item.height, displayMaxY)) {
3711             MMI_HILOGE("The addition of displayMaxY overflows");
3712             return findFlag;
3713         }
3714         if (((x > item.x) && (x <= displayMaxX)) && (y > item.y) && (y <= displayMaxY)) {
3715             findFlag = true;
3716             break;
3717         }
3718     }
3719     return findFlag;
3720 }
3721 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
3722 
3723 #ifdef OHOS_BUILD_ENABLE_TOUCH
3724 void InputWindowsManager::AdjustDisplayCoordinate(
3725     const OLD::DisplayInfo& displayInfo, double& physicalX, double& physicalY) const
3726 {
3727     int32_t width = displayInfo.validWidth;
3728     int32_t height = displayInfo.validHeight;
3729     if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
3730         if (displayInfo.direction == DIRECTION90 || displayInfo.direction == DIRECTION270) {
3731             width = displayInfo.height;
3732             height = displayInfo.width;
3733         }
3734     }
3735     if (physicalX <= 0) {
3736         physicalX = 0;
3737     }
3738     if (physicalX >= width && width > 0) {
3739         physicalX = width - 1;
3740     }
3741     if (physicalY <= 0) {
3742         physicalY = 0;
3743     }
3744     if (physicalY >= height && height > 0) {
3745         physicalY = height - 1;
3746     }
3747 }
3748 #endif // OHOS_BUILD_ENABLE_TOUCH
3749 
3750 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
3751 bool InputWindowsManager::UpdateDisplayId(int32_t& displayId)
3752 {
3753     int32_t groupId = FindDisplayGroupId(displayId);
3754     auto &DisplaysInfo = GetDisplayInfoVector(groupId);
3755     if (DisplaysInfo.empty()) {
3756         MMI_HILOGE("DisplaysInfo is empty");
3757         return false;
3758     }
3759     if (displayId < 0) {
3760         displayId = DisplaysInfo[0].id;
3761         return true;
3762     }
3763     for (const auto &item : DisplaysInfo) {
3764         if (item.id == displayId) {
3765             return true;
3766         }
3767     }
3768     return false;
3769 }
3770 
3771 void InputWindowsManager::UpdateCurrentDisplay(int32_t displayId) const
3772 {
3773     auto physicalDisplayInfo = GetPhysicalDisplay(displayId);
3774     CHKPV(physicalDisplayInfo);
3775     currentDisplayXY_ =  std::make_pair(physicalDisplayInfo->x, physicalDisplayInfo->y);
3776 }
3777 
3778 std::optional<WindowInfo> InputWindowsManager::SelectWindowInfo(int32_t logicalX, int32_t logicalY,
3779     const std::shared_ptr<PointerEvent>& pointerEvent)
3780 {
3781     CALL_DEBUG_ENTER;
3782     int32_t action = pointerEvent->GetPointerAction();
3783     bool checkFlag = (firstBtnDownWindowInfo_.first == -1) ||
3784         ((action == PointerEvent::POINTER_ACTION_BUTTON_DOWN) && (pointerEvent->GetPressedButtons().size() <= 1)) ||
3785         ((action == PointerEvent::POINTER_ACTION_MOVE) && (pointerEvent->GetPressedButtons().empty())) ||
3786         (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) ||
3787         (action == PointerEvent::POINTER_ACTION_PULL_UP) ||
3788         ((action == PointerEvent::POINTER_ACTION_AXIS_BEGIN || action == PointerEvent::POINTER_ACTION_ROTATE_BEGIN) &&
3789         (pointerEvent->GetPressedButtons().empty()));
3790     std::vector<WindowInfo> windowsInfo = GetWindowGroupInfoByDisplayId(pointerEvent->GetTargetDisplayId());
3791     if (checkFlag) {
3792         int32_t targetWindowId = pointerEvent->GetTargetWindowId();
3793         static std::unordered_map<int32_t, int32_t> winId2ZorderMap;
3794         bool isHotArea = false;
3795         if (targetWindowId <= 1) {
3796             targetMouseWinIds_.clear();
3797         }
3798         for (const auto &item : windowsInfo) {
3799             if (transparentWins_.find(item.id) != transparentWins_.end()) {
3800                 if (IsTransparentWin(transparentWins_[item.id], logicalX - item.area.x, logicalY - item.area.y)) {
3801                     winId2ZorderMap.insert({item.id, item.zOrder});
3802                     MMI_HILOG_DISPATCHE("It's an abnormal window and pointer find the next window, window:%{public}d",
3803                         item.id);
3804                     continue;
3805                 }
3806             }
3807             if (item.windowInputType == WindowInputType::TRANSMIT_ANTI_AXIS_MOVE) {
3808                 MMI_HILOG_DISPATCHD("Pointer enents do not respond to the window, window:%{public}d, "
3809                     "windowInputType%{public}d", item.id, static_cast<int32_t>(item.windowInputType));
3810                 continue;
3811             }
3812             if (SkipPrivacyProtectionWindow(pointerEvent, item.isSkipSelfWhenShowOnVirtualScreen)) {
3813                 winId2ZorderMap.insert({item.id, item.zOrder});
3814                 continue;
3815             }
3816             if ((item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) == WindowInfo::FLAG_BIT_UNTOUCHABLE ||
3817                 !IsValidZorderWindow(item, pointerEvent)) {
3818                 winId2ZorderMap.insert({item.id, item.zOrder});
3819                 MMI_HILOG_DISPATCHD("Skip the untouchable or invalid zOrder window to continue searching, "
3820                     "window:%{public}d, flags:%{public}d, pid:%{public}d", item.id, item.flags, item.pid);
3821                 continue;
3822             }
3823             if (IsAccessibilityEventWithZorderInjected(pointerEvent) && pointerEvent->GetZOrder() <= item.zOrder) {
3824                 winId2ZorderMap.insert({item.id, item.zOrder});
3825                 continue;
3826             } else if ((extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) ||
3827                 (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_UP)) {
3828                 if (IsInHotArea(logicalX, logicalY, item.pointerHotAreas, item)) {
3829                     if (item.windowInputType == WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE) {
3830                         winId2ZorderMap.insert({item.id, item.zOrder});
3831                         continue;
3832                     }
3833                     firstBtnDownWindowInfo_.first = item.id;
3834                     firstBtnDownWindowInfo_.second = item.displayId;
3835                     MMI_HILOG_DISPATCHD("Mouse event select pull window, window:%{public}d, pid:%{public}d",
3836                         firstBtnDownWindowInfo_.first, item.pid);
3837                     break;
3838                 } else {
3839                     winId2ZorderMap.insert({item.id, item.zOrder});
3840                     continue;
3841                 }
3842             } else if ((targetWindowId < 0) && (IsInHotArea(logicalX, logicalY, item.pointerHotAreas, item))) {
3843                 if ((item.windowInputType == WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE ||
3844                     item.windowInputType == WindowInputType::DUALTRIGGER_TOUCH ||
3845                     item.windowInputType == WindowInputType::MIX_BUTTOM_ANTI_AXIS_MOVE) &&
3846                     ((pointerEvent->GetPressedButtons().empty()) ||
3847                     (action == PointerEvent::POINTER_ACTION_PULL_UP) ||
3848                     (action == PointerEvent::POINTER_ACTION_AXIS_BEGIN) ||
3849                     (action == PointerEvent::POINTER_ACTION_AXIS_UPDATE) ||
3850                     (action == PointerEvent::POINTER_ACTION_AXIS_END)||
3851                     (PointerEvent::MOUSE_BUTTON_LEFT != pointerEvent->GetButtonId()))) {
3852                     MMI_HILOG_DISPATCHD("Mouse event transparent, action:%{public}d, ButtonId:%{public}d",
3853                         action, pointerEvent->GetButtonId());
3854                     continue;
3855                 }
3856                 firstBtnDownWindowInfo_.first = item.id;
3857                 firstBtnDownWindowInfo_.second = item.displayId;
3858                 if (!item.uiExtentionWindowInfo.empty()) {
3859                     // Determine whether the landing point as a safety sub window
3860                     CheckUIExtentionWindowPointerHotArea(logicalX, logicalY,
3861                         item.uiExtentionWindowInfo, firstBtnDownWindowInfo_.first);
3862                 }
3863                 MMI_HILOG_DISPATCHD("Find out the dispatch window of this pointer event when the targetWindowId "
3864                     "hasn't been set up yet, window:%{public}d, pid:%{public}d",
3865                     firstBtnDownWindowInfo_.first, item.pid);
3866                 bool isSpecialWindow = HandleWindowInputType(item, pointerEvent);
3867                 if (isSpecialWindow) {
3868                     AddTargetWindowIds(pointerEvent->GetPointerId(), pointerEvent->GetSourceType(), item.id);
3869                     isHotArea = true;
3870                     continue;
3871                 } else if (isHotArea) {
3872                     AddTargetWindowIds(pointerEvent->GetPointerId(), pointerEvent->GetSourceType(), item.id);
3873                     break;
3874                 } else {
3875                     break;
3876                 }
3877 
3878             } else if ((targetWindowId >= 0) && (targetWindowId == item.id)) {
3879                 firstBtnDownWindowInfo_.first = targetWindowId;
3880                 firstBtnDownWindowInfo_.second = item.displayId;
3881                 MMI_HILOG_DISPATCHD("Find out the dispatch window of this pointer event when the targetWindowId "
3882                     "has been set up already, window:%{public}d, pid:%{public}d",
3883                     firstBtnDownWindowInfo_.first, item.pid);
3884                 break;
3885             } else {
3886                 winId2ZorderMap.insert({item.id, item.zOrder});
3887                 MMI_HILOG_DISPATCHD("Continue searching for the dispatch window of this pointer event");
3888             }
3889         }
3890         if ((firstBtnDownWindowInfo_.first < 0) && (action == PointerEvent::POINTER_ACTION_BUTTON_DOWN) &&
3891             (pointerEvent->GetPressedButtons().size() == 1)) {
3892             for (const auto &iter : winId2ZorderMap) {
3893                 MMI_HILOG_DISPATCHI("%{public}d, %{public}d", iter.first, iter.second);
3894             }
3895         }
3896         winId2ZorderMap.clear();
3897     }
3898     if (axisBeginWindowInfo_ &&
3899         (action == PointerEvent::POINTER_ACTION_AXIS_UPDATE || action == PointerEvent::POINTER_ACTION_AXIS_END)) {
3900         firstBtnDownWindowInfo_ = { axisBeginWindowInfo_->id, axisBeginWindowInfo_->displayId };
3901     }
3902     MMI_HILOG_DISPATCHD("firstBtnDownWindowInfo_.first:%{public}d", firstBtnDownWindowInfo_.first);
3903 #ifdef OHOS_BUILD_PC_PRIORITY
3904     PrintHighZorder(windowsInfo, pointerEvent->GetPointerAction(), firstBtnDownWindowInfo_.first, logicalX, logicalY);
3905 #endif // OHOS_BUILD_PC_PRIORITY
3906     for (const auto &item : windowsInfo) {
3907         for (const auto &windowInfo : item.uiExtentionWindowInfo) {
3908             if (windowInfo.id == firstBtnDownWindowInfo_.first) {
3909                 firstBtnDownWindowInfo_.second = pointerEvent->GetTargetDisplayId();
3910                 return std::make_optional(windowInfo);
3911             }
3912         }
3913         if (item.id == firstBtnDownWindowInfo_.first) {
3914             firstBtnDownWindowInfo_.second = pointerEvent->GetTargetDisplayId();
3915             return std::make_optional(item);
3916         }
3917     }
3918     if (pointerEvent->GetTargetDisplayId() != firstBtnDownWindowInfo_.second) {
3919         std::vector<WindowInfo> firstBtnDownWindowsInfo =
3920             GetWindowGroupInfoByDisplayId(firstBtnDownWindowInfo_.second);
3921         for (const auto &item : firstBtnDownWindowsInfo) {
3922             for (const auto &windowInfo : item.uiExtentionWindowInfo) {
3923                 if (windowInfo.id == firstBtnDownWindowInfo_.first) {
3924                     return std::make_optional(windowInfo);
3925                 }
3926             }
3927             if (item.id == firstBtnDownWindowInfo_.first) {
3928                 return std::make_optional(item);
3929             }
3930         }
3931     }
3932     return std::nullopt;
3933 }
3934 
3935 void InputWindowsManager::CheckUIExtentionWindowPointerHotArea(int32_t logicalX, int32_t logicalY,
3936     const std::vector<WindowInfo>& windowInfos, int32_t& windowId)
3937 {
3938     for (const auto &it : windowInfos) {
3939         if (IsInHotArea(logicalX, logicalY, it.pointerHotAreas, it)) {
3940             windowId = it.id;
3941             break;
3942         }
3943     }
3944 }
3945 
3946 std::optional<WindowInfo> InputWindowsManager::GetWindowInfo(int32_t logicalX, int32_t logicalY, int32_t groupId)
3947 {
3948     CALL_DEBUG_ENTER;
3949     auto &WindowsInfo = GetWindowInfoVector(groupId);
3950     for (const auto& item : WindowsInfo) {
3951         if ((item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) == WindowInfo::FLAG_BIT_UNTOUCHABLE) {
3952             MMI_HILOGD("Skip the untouchable window to continue searching, "
3953                 "window:%{public}d, flags:%{public}d", item.id, item.flags);
3954             continue;
3955         } else if (IsInHotArea(logicalX, logicalY, item.pointerHotAreas, item)) {
3956             return std::make_optional(item);
3957         } else {
3958             MMI_HILOGD("Continue searching for the dispatch window");
3959         }
3960     }
3961     return std::nullopt;
3962 }
3963 
3964 bool InputWindowsManager::SelectPointerChangeArea(const WindowInfo &windowInfo, PointerStyle &pointerStyle,
3965     int32_t logicalX, int32_t logicalY)
3966 {
3967     CALL_DEBUG_ENTER;
3968     int32_t windowId = windowInfo.id;
3969     bool findFlag = false;
3970     if (windowsHotAreas_.find(windowId) != windowsHotAreas_.end()) {
3971         std::vector<Rect> windowHotAreas = windowsHotAreas_[windowId];
3972         MMI_HILOG_CURSORD("windowHotAreas size:%{public}zu, windowId:%{public}d, pid:%{public}d",
3973             windowHotAreas.size(), windowId, windowInfo.pid);
3974         findFlag = InWhichHotArea(logicalX, logicalY, windowHotAreas, pointerStyle);
3975     }
3976     return findFlag;
3977 }
3978 
3979 bool InputWindowsManager::SelectPointerChangeArea(int32_t windowId, int32_t logicalX, int32_t logicalY)
3980 {
3981     CALL_DEBUG_ENTER;
3982     bool findFlag = false;
3983     if (windowsHotAreas_.find(windowId) != windowsHotAreas_.end()) {
3984         std::vector<Rect> windowHotAreas = windowsHotAreas_[windowId];
3985         MMI_HILOGE("windowHotAreas size:%{public}zu, windowId:%{public}d",
3986             windowHotAreas.size(), windowId);
3987         findFlag = InWhichHotArea(logicalX, logicalY, windowHotAreas);
3988     }
3989     return findFlag;
3990 }
3991 
3992 void InputWindowsManager::UpdatePointerChangeAreas(const OLD::DisplayGroupInfo &displayGroupInfo)
3993 {
3994     CALL_DEBUG_ENTER;
3995     std::map<int32_t, std::vector<Rect>> &winHotAreasTmp = windowsHotAreasMap_[displayGroupInfo.groupId];
3996     for (const auto &windowInfo : displayGroupInfo.windowsInfo) {
3997         std::vector<Rect> windowHotAreas;
3998         int32_t windowId = windowInfo.id;
3999         Rect windowArea = windowInfo.area;
4000         if (windowInfo.transform.size() <= 0) {
4001             continue;
4002         }
4003         windowArea.width = windowInfo.transform[SCALE_X] != 0 ? windowInfo.area.width / windowInfo.transform[SCALE_X]
4004             : windowInfo.area.width;
4005         windowArea.height = windowInfo.transform[SCALE_Y] != 0 ? windowInfo.area.height / windowInfo.transform[SCALE_Y]
4006             : windowInfo.area.height;
4007         std::vector<int32_t> pointerChangeAreas = windowInfo.pointerChangeAreas;
4008         if (!pointerChangeAreas.empty()) {
4009             UpdateTopBottomArea(windowArea, pointerChangeAreas, windowHotAreas);
4010             UpdateLeftRightArea(windowArea, pointerChangeAreas, windowHotAreas);
4011             UpdateInnerAngleArea(windowArea, pointerChangeAreas, windowHotAreas);
4012         }
4013         if (winHotAreasTmp.find(windowId) == winHotAreasTmp.end()) {
4014             winHotAreasTmp.emplace(windowId, windowHotAreas);
4015         } else {
4016             winHotAreasTmp[windowId] = windowHotAreas;
4017         }
4018     }
4019 }
4020 
4021 void InputWindowsManager::UpdatePointerChangeAreas()
4022 {
4023     CALL_DEBUG_ENTER;
4024     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
4025         const auto iter = displayGroupInfoMapTmp_.find(MAIN_GROUPID);
4026         if(iter == displayGroupInfoMapTmp_.end()) {
4027             return;
4028         }
4029         UpdatePointerChangeAreas(iter->second);
4030     }
4031 }
4032 
4033 void InputWindowsManager::UpdateTopBottomArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas,
4034     std::vector<Rect> &windowHotAreas)
4035 {
4036     CALL_DEBUG_ENTER;
4037     Rect newTopRect;
4038     newTopRect.x = windowArea.x + pointerChangeAreas[TOP_LEFT_AREA];
4039     newTopRect.y = windowArea.y - OUTWINDOW_HOT_AREA;
4040     newTopRect.width = windowArea.width - pointerChangeAreas[TOP_LEFT_AREA] - pointerChangeAreas[TOP_RIGHT_AREA];
4041     newTopRect.height = OUTWINDOW_HOT_AREA + pointerChangeAreas[TOP_AREA];
4042     Rect newBottomRect;
4043     newBottomRect.x = windowArea.x + pointerChangeAreas[BOTTOM_LEFT_AREA];
4044     newBottomRect.y = windowArea.y + windowArea.height - pointerChangeAreas[BOTTOM_AREA];
4045     newBottomRect.width = windowArea.width - pointerChangeAreas[BOTTOM_LEFT_AREA] -
4046         pointerChangeAreas[BOTTOM_RIGHT_AREA];
4047     newBottomRect.height = OUTWINDOW_HOT_AREA + pointerChangeAreas[BOTTOM_AREA];
4048     if (pointerChangeAreas[TOP_AREA] == 0) {
4049         newTopRect.width = 0;
4050         newTopRect.height = 0;
4051     }
4052     if (pointerChangeAreas[BOTTOM_AREA] == 0) {
4053         newBottomRect.width = 0;
4054         newBottomRect.height = 0;
4055     }
4056     windowHotAreas.push_back(newTopRect);
4057     windowHotAreas.push_back(newBottomRect);
4058 }
4059 
4060 void InputWindowsManager::UpdateLeftRightArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas,
4061     std::vector<Rect> &windowHotAreas)
4062 {
4063     CALL_DEBUG_ENTER;
4064     Rect newLeftRect;
4065     newLeftRect.x = windowArea.x - OUTWINDOW_HOT_AREA;
4066     newLeftRect.y = windowArea.y + pointerChangeAreas[TOP_LEFT_AREA];
4067     newLeftRect.width = OUTWINDOW_HOT_AREA + pointerChangeAreas[LEFT_AREA];
4068     newLeftRect.height = windowArea.height - pointerChangeAreas[TOP_LEFT_AREA] - pointerChangeAreas[BOTTOM_LEFT_AREA];
4069     Rect newRightRect;
4070     newRightRect.x = windowArea.x + windowArea.width - pointerChangeAreas[RIGHT_AREA];
4071     newRightRect.y = windowArea.y + pointerChangeAreas[TOP_RIGHT_AREA];
4072     newRightRect.width = OUTWINDOW_HOT_AREA + pointerChangeAreas[RIGHT_AREA];
4073     newRightRect.height = windowArea.height - pointerChangeAreas[TOP_RIGHT_AREA] -
4074         pointerChangeAreas[BOTTOM_RIGHT_AREA];
4075     if (pointerChangeAreas[LEFT_AREA] == 0) {
4076         newLeftRect.width = 0;
4077         newLeftRect.height = 0;
4078     }
4079     if (pointerChangeAreas[RIGHT_AREA] == 0) {
4080         newRightRect.width = 0;
4081         newRightRect.height = 0;
4082     }
4083     windowHotAreas.push_back(newLeftRect);
4084     windowHotAreas.push_back(newRightRect);
4085 }
4086 
4087 void InputWindowsManager::UpdateInnerAngleArea(const Rect &windowArea, std::vector<int32_t> &pointerChangeAreas,
4088     std::vector<Rect> &windowHotAreas)
4089 {
4090     CALL_DEBUG_ENTER;
4091     Rect newTopLeftRect;
4092     newTopLeftRect.x = windowArea.x - OUTWINDOW_HOT_AREA;
4093     newTopLeftRect.y = windowArea.y - OUTWINDOW_HOT_AREA;
4094     newTopLeftRect.width = OUTWINDOW_HOT_AREA + pointerChangeAreas[TOP_LEFT_AREA];
4095     newTopLeftRect.height = OUTWINDOW_HOT_AREA + pointerChangeAreas[TOP_LEFT_AREA];
4096     Rect newTopRightRect;
4097     newTopRightRect.x = windowArea.x + windowArea.width - pointerChangeAreas[TOP_RIGHT_AREA];
4098     newTopRightRect.y = windowArea.y - OUTWINDOW_HOT_AREA;
4099     newTopRightRect.width = OUTWINDOW_HOT_AREA + pointerChangeAreas[TOP_RIGHT_AREA];
4100     newTopRightRect.height = OUTWINDOW_HOT_AREA + pointerChangeAreas[TOP_RIGHT_AREA];
4101     Rect newBottomLeftRect;
4102     newBottomLeftRect.x = windowArea.x - OUTWINDOW_HOT_AREA;
4103     newBottomLeftRect.y = windowArea.y + windowArea.height - pointerChangeAreas[BOTTOM_LEFT_AREA];
4104     newBottomLeftRect.width = OUTWINDOW_HOT_AREA + pointerChangeAreas[BOTTOM_LEFT_AREA];
4105     newBottomLeftRect.height = OUTWINDOW_HOT_AREA + pointerChangeAreas[BOTTOM_LEFT_AREA];
4106     Rect newBottomRightRect;
4107     newBottomRightRect.x = windowArea.x + windowArea.width - pointerChangeAreas[BOTTOM_RIGHT_AREA];
4108     newBottomRightRect.y = windowArea.y + windowArea.height - pointerChangeAreas[BOTTOM_RIGHT_AREA];
4109     newBottomRightRect.width = OUTWINDOW_HOT_AREA + pointerChangeAreas[BOTTOM_RIGHT_AREA];
4110     newBottomRightRect.height = OUTWINDOW_HOT_AREA + pointerChangeAreas[BOTTOM_RIGHT_AREA];
4111     if (pointerChangeAreas[TOP_LEFT_AREA] == 0) {
4112         newTopLeftRect.width = 0;
4113         newTopLeftRect.height = 0;
4114     }
4115     if (pointerChangeAreas[TOP_RIGHT_AREA] == 0) {
4116         newTopRightRect.width = 0;
4117         newTopRightRect.height = 0;
4118     }
4119     if (pointerChangeAreas[BOTTOM_LEFT_AREA] == 0) {
4120         newBottomLeftRect.width = 0;
4121         newBottomLeftRect.height = 0;
4122     }
4123     if (pointerChangeAreas[BOTTOM_RIGHT_AREA] == 0) {
4124         newBottomRightRect.width = 0;
4125         newBottomRightRect.height = 0;
4126     }
4127 
4128     windowHotAreas.push_back(newTopLeftRect);
4129     windowHotAreas.push_back(newTopRightRect);
4130     windowHotAreas.push_back(newBottomLeftRect);
4131     windowHotAreas.push_back(newBottomRightRect);
4132 }
4133 
4134 void InputWindowsManager::HandlePullEvent(std::shared_ptr<PointerEvent> pointerEvent)
4135 {
4136     CHKPV(pointerEvent);
4137     auto action = pointerEvent->GetPointerAction();
4138     if (action != PointerEvent::POINTER_ACTION_PULL_CANCEL &&
4139         action != PointerEvent::POINTER_ACTION_PULL_MOVE &&
4140         action != PointerEvent::POINTER_ACTION_PULL_UP) {
4141         return;
4142     }
4143     int32_t pullId = pointerEvent->GetPullId();
4144     static int32_t originPullId { -1 };
4145     if (action == PointerEvent::POINTER_ACTION_PULL_CANCEL) {
4146         originPullId = pullId;
4147         MMI_HILOGI("Set originPullId:%{public}d", originPullId);
4148         if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) {
4149             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
4150             MMI_HILOGI("Convert PULL_CANCEL to CANCEL When in accessibility");
4151         }
4152         return;
4153     }
4154     if (originPullId != pullId || originPullId == -1) {
4155         MMI_HILOGD("Not the same drag instance, originPullId:%{public}d, pullId:%{public}d", originPullId, pullId);
4156         return;
4157     }
4158     auto pointerId = pointerEvent->GetPointerId();
4159     PointerEvent::PointerItem pointerItem;
4160     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
4161         MMI_HILOGE("GetPointerItem of pointerId:%{public}d failed", pointerId);
4162         return;
4163     }
4164     pointerItem.SetCanceled(true);
4165     pointerItem.SetPressed(false);
4166     pointerEvent->UpdatePointerItem(pointerId, pointerItem);
4167     MMI_HILOGI("SetCanceled true, SetPressed false, pointerId:%{public}d, originPullId:%{public}d",
4168         pointerId, originPullId);
4169     originPullId = -1;
4170 }
4171 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
4172 
4173 #ifdef OHOS_BUILD_ENABLE_POINTER
4174 void InputWindowsManager::UpdatePointerEvent(int32_t logicalX, int32_t logicalY,
4175     const std::shared_ptr<PointerEvent>& pointerEvent, const WindowInfo& touchWindow)
4176 {
4177     CHKPV(pointerEvent);
4178     MMI_HILOG_DISPATCHD("LastWindowInfo:%{public}d, touchWindow:%{public}d", lastWindowInfo_.id, touchWindow.id);
4179     if (lastWindowInfo_.id != touchWindow.id) {
4180         DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
4181         lastLogicX_ = logicalX;
4182         lastLogicY_ = logicalY;
4183         {
4184             std::lock_guard<std::mutex> guard(mtx_);
4185             lastPointerEvent_ = pointerEvent;
4186         }
4187         lastWindowInfo_ = touchWindow;
4188         DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW, lastWindowInfo_.id);
4189         return;
4190     }
4191     lastLogicX_ = logicalX;
4192     lastLogicY_ = logicalY;
4193     {
4194         std::lock_guard<std::mutex> guard(mtx_);
4195         if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHPAD) {
4196             std::vector<int32_t> pointerIds{ pointerEvent->GetPointerIds() };
4197             std::string isSimulate = pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE) ? "true" : "false";
4198             auto device = INPUT_DEV_MGR->GetInputDevice(pointerEvent->GetDeviceId());
4199             std::string deviceName { "Null" };
4200             if (device != nullptr) {
4201                 deviceName = device->GetName();
4202             }
4203             MMI_HILOGE("Not mouse event id:%{public}d, PI:%{public}d, AC:%{public}d, wid:%{public}d by:%{public}s,"
4204                 " SI:%{public}s, PC:%{public}zu, LastEvent id:%{public}d, PI:%{public}d, AC:%{public}d, wid:%{public}d",
4205                 pointerEvent->GetId(), pointerEvent->GetPointerId(), pointerEvent->GetPointerAction(),
4206                 pointerEvent->GetTargetWindowId(), deviceName.c_str(), isSimulate.c_str(), pointerIds.size(),
4207                 lastPointerEvent_->GetId(), lastPointerEvent_->GetPointerId(), lastPointerEvent_->GetPointerAction(),
4208                 lastPointerEvent_->GetTargetWindowId());
4209         }
4210         lastPointerEvent_ = pointerEvent;
4211     }
4212     lastWindowInfo_ = touchWindow;
4213 }
4214 
4215 int32_t InputWindowsManager::SetHoverScrollState(bool state)
4216 {
4217     CALL_DEBUG_ENTER;
4218     MMI_HILOGD("Set mouse hover scroll state:%{public}d", state);
4219     std::string name = "isEnableHoverScroll";
4220     return PREFERENCES_MGR->SetBoolValue(name, MOUSE_FILE_NAME, state);
4221 }
4222 
4223 bool InputWindowsManager::GetHoverScrollState() const
4224 {
4225     CALL_DEBUG_ENTER;
4226     std::string name = "isEnableHoverScroll";
4227     bool state = PREFERENCES_MGR->GetBoolValue(name, true);
4228     MMI_HILOGD("Get mouse hover scroll state:%{public}d", state);
4229     return state;
4230 }
4231 
4232 std::vector<int32_t> InputWindowsManager::HandleHardwareCursor(const OLD::DisplayInfo *physicalDisplayInfo,
4233     int32_t physicalX, int32_t physicalY)
4234 {
4235     std::vector<int32_t> cursorPos = {DEFAULT_POSITION, DEFAULT_POSITION};
4236     if (physicalDisplayInfo == nullptr) {
4237         return cursorPos;
4238     }
4239     Direction direction = DIRECTION0;
4240     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
4241         direction = GetDisplayDirection(physicalDisplayInfo);
4242         TOUCH_DRAWING_MGR->GetOriginalTouchScreenCoordinates(direction, physicalDisplayInfo->validWidth,
4243             physicalDisplayInfo->validHeight, physicalX, physicalY);
4244     }
4245     cursorPos = {physicalX, physicalY};
4246     (void)direction;
4247     return cursorPos;
4248 }
4249 
4250 int32_t InputWindowsManager::UpdateMouseTarget(std::shared_ptr<PointerEvent> pointerEvent)
4251 {
4252     CALL_DEBUG_ENTER;
4253     CHKPR(pointerEvent, ERROR_NULL_POINTER);
4254     auto displayId = pointerEvent->GetTargetDisplayId();
4255     if (!UpdateDisplayId(displayId)) {
4256         MMI_HILOGE("This display:%{public}d is not existent", displayId);
4257         return RET_ERR;
4258     }
4259     pointerEvent->SetTargetDisplayId(displayId);
4260     int32_t groupId = FindDisplayGroupId(displayId);
4261     auto physicalDisplayInfo = GetPhysicalDisplay(displayId);
4262     CHKPR(physicalDisplayInfo, ERROR_NULL_POINTER);
4263     int32_t displayInfoX = GetLogicalPositionX(displayId);
4264     int32_t displayInfoY = GetLogicalPositionY(displayId);
4265     int32_t pointerId = pointerEvent->GetPointerId();
4266     PointerEvent::PointerItem pointerItem;
4267     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
4268         MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId);
4269         return RET_ERR;
4270     }
4271     int32_t logicalX = 0;
4272     int32_t logicalY = 0;
4273     int32_t physicalX = pointerItem.GetDisplayX();
4274     int32_t physicalY = pointerItem.GetDisplayY();
4275     if (!AddInt32(physicalX, displayInfoX, logicalX)) {
4276         MMI_HILOGE("The addition of logicalX overflows");
4277         return RET_ERR;
4278     }
4279     if (!AddInt32(physicalY, displayInfoY, logicalY)) {
4280         MMI_HILOGE("The addition of logicalY overflows");
4281         return RET_ERR;
4282     }
4283     if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) {
4284         ClearTargetWindowId(pointerId);
4285     }
4286     auto touchWindow = SelectWindowInfo(logicalX, logicalY, pointerEvent);
4287     if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_AXIS_BEGIN) {
4288         axisBeginWindowInfo_ = touchWindow;
4289     }
4290     if (!touchWindow) {
4291         MMI_HILOGI("UpdateMouseTarget rsId:%{public}" PRIu64 ", logicalX:%{private}d, logicalY:%{private}d,"
4292             "displayX:%{private}d, displayY:%{private}d", physicalDisplayInfo->rsId, logicalX, logicalY,
4293             physicalX, physicalY);
4294         if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_DOWN || (mouseDownInfo_.id == -1 &&
4295             axisBeginWindowInfo_ == std::nullopt)) {
4296             MMI_HILOGE("touchWindow is nullptr, targetWindow:%{public}d", pointerEvent->GetTargetWindowId());
4297             if (!CursorDrawingComponent::GetInstance().GetMouseDisplayState() &&
4298                 IsMouseDrawing(pointerEvent->GetPointerAction()) &&
4299                 pointerItem.GetMoveFlag() != POINTER_MOVEFLAG) {
4300                     MMI_HILOGD("Turn the mouseDisplay from false to true");
4301                     CursorDrawingComponent::GetInstance().SetMouseDisplayState(true);
4302             }
4303             int64_t beginTime = GetSysClockTime();
4304 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
4305             if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_HIDE_POINTER) &&
4306             pointerItem.GetMoveFlag() == POINTER_MOVEFLAG) {
4307                 CursorDrawingComponent::GetInstance().SetMouseDisplayState(false);
4308             } else {
4309                 CursorDrawingComponent::GetInstance().SetMouseDisplayState(true);
4310             }
4311             if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) {
4312                 if (GetHardCursorEnabled()) {
4313                     std::vector<int32_t> cursorPos = HandleHardwareCursor(physicalDisplayInfo, physicalX, physicalY);
4314                     CHKFR((cursorPos.size() >= CURSOR_POSITION_EXPECTED_SIZE), RET_ERR, "cursorPos is invalid");
4315                     CursorDrawingComponent::GetInstance().DrawMovePointer(physicalDisplayInfo->rsId,
4316                         cursorPos[0], cursorPos[1]);
4317                 } else {
4318                     CursorDrawingComponent::GetInstance().DrawMovePointer(physicalDisplayInfo->rsId,
4319                         physicalX, physicalY);
4320                 }
4321             }
4322             MMI_HILOGI("UpdateMouseTarget id:%{public}" PRIu64 ", logicalX:%{private}d, logicalY:%{private}d,"
4323                 "displayX:%{private}d, displayY:%{private}d", physicalDisplayInfo->rsId, logicalX, logicalY,
4324                 physicalX, physicalY);
4325 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
4326             int64_t timeDT = GetTimeToMilli(GetSysClockTime() - pointerEvent->GetActionTime());
4327             if (timeDT > SIMULATE_EVENT_LATENCY) {
4328                 MMI_HILOGI("Not touchWindow simulate event latency, pointerId:%{public}d, timeDT:%{public}" PRId64,
4329                     pointerEvent->GetId(), timeDT);
4330                 DfxHisyseventDevice::ReportSimulateToRsLatecyBehavior(pointerEvent->GetId(), timeDT);
4331             }
4332 #endif
4333 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
4334             int64_t endTime = GetSysClockTime();
4335             if ((endTime - beginTime) > RS_PROCESS_TIMEOUT) {
4336                 MMI_HILOGW("Rs process timeout");
4337             }
4338             return RET_ERR;
4339         }
4340         if (mouseDownInfo_.id != -1) {
4341             touchWindow = std::make_optional(mouseDownInfo_);
4342         } else if (axisBeginWindowInfo_) {
4343             touchWindow = axisBeginWindowInfo_;
4344         }
4345         int32_t pointerAction = pointerEvent->GetPointerAction();
4346         if (IsAccessibilityFocusEvent(pointerEvent)) {
4347             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_CANCEL);
4348         } else {
4349             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
4350         }
4351         pointerEvent->SetOriginPointerAction(pointerAction);
4352         MMI_HILOGI("Mouse event send cancel, window:%{public}d, pid:%{public}d", touchWindow->id, touchWindow->pid);
4353     }
4354 
4355     bool checkFlag = pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_AXIS_UPDATE ||
4356         pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_AXIS_BEGIN ||
4357         pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_AXIS_END;
4358     if (checkFlag) {
4359         int32_t focusWindowId = GetFocusWindowId(groupId);
4360         if ((!GetHoverScrollState()) && (focusWindowId != touchWindow->id)) {
4361             MMI_HILOGD("disable mouse hover scroll in inactive window, targetWindowId:%{public}d", touchWindow->id);
4362             return RET_OK;
4363         }
4364     }
4365     PointerStyle pointerStyle;
4366 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
4367     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
4368         if (timerId_ != DEFAULT_VALUE) {
4369             TimerMgr->RemoveTimer(timerId_);
4370             timerId_ = DEFAULT_VALUE;
4371         }
4372         if (!CursorDrawingComponent::GetInstance().GetMouseDisplayState() &&
4373             IsMouseDrawing(pointerEvent->GetPointerAction()) &&
4374             pointerItem.GetMoveFlag() != POINTER_MOVEFLAG) {
4375             MMI_HILOGD("Turn the mouseDisplay from false to true");
4376             CursorDrawingComponent::GetInstance().SetMouseDisplayState(true);
4377         }
4378         pointerStyle = CursorDrawingComponent::GetInstance().GetLastMouseStyle();
4379         MMI_HILOGD("showing the lastMouseStyle %{public}d, lastPointerStyle %{public}d",
4380             pointerStyle.id, lastPointerStyle_.id);
4381         CursorDrawingComponent::GetInstance().UpdateDisplayInfo(*physicalDisplayInfo);
4382         WinInfo info = { .windowPid = touchWindow->pid, .windowId = touchWindow->id };
4383         CursorDrawingComponent::GetInstance().OnWindowInfo(info);
4384     } else {
4385         if (timerId_ != DEFAULT_VALUE) {
4386             TimerMgr->RemoveTimer(timerId_);
4387             timerId_ = DEFAULT_VALUE;
4388         }
4389         GetPointerStyle(touchWindow->pid, touchWindow->id, pointerStyle);
4390         if (!CursorDrawingComponent::GetInstance().GetMouseDisplayState() &&
4391             pointerItem.GetMoveFlag() != POINTER_MOVEFLAG) {
4392             CursorDrawingComponent::GetInstance().SetMouseDisplayState(true);
4393             DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW);
4394         }
4395         CursorDrawingComponent::GetInstance().UpdateDisplayInfo(*physicalDisplayInfo);
4396         WinInfo info = { .windowPid = touchWindow->pid, .windowId = touchWindow->id };
4397         CursorDrawingComponent::GetInstance().OnWindowInfo(info);
4398     }
4399 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
4400 #ifdef OHOS_BUILD_EMULATOR
4401     if (!CursorDrawingComponent::GetInstance().GetMouseDisplayState() &&
4402         pointerItem.GetMoveFlag() != POINTER_MOVEFLAG) {
4403         CursorDrawingComponent::GetInstance().SetMouseDisplayState(true);
4404     }
4405 #endif
4406     GetPointerStyle(touchWindow->pid, touchWindow->id, pointerStyle);
4407     if (isUiExtension_) {
4408         MMI_HILOGD("updatemouse target in uiextension");
4409         GetPointerStyle(uiExtensionPid_, uiExtensionWindowId_, pointerStyle, isUiExtension_);
4410         dragPointerStyle_ = pointerStyle;
4411     } else {
4412         GetPointerStyle(touchWindow->pid, touchWindow->id, pointerStyle);
4413     }
4414     if (!isDragBorder_ && !isUiExtension_) {
4415         GetPointerStyle(touchWindow->pid, touchWindow->id, pointerStyle);
4416         dragPointerStyle_ = pointerStyle;
4417     }
4418     WindowInfo window = *touchWindow;
4419     if (!dragFlag_) {
4420         isDragBorder_ = SelectPointerChangeArea(window, pointerStyle, logicalX, logicalY);
4421         dragPointerStyle_ = pointerStyle;
4422         MMI_HILOGD("pointerStyle is :%{public}d, windowId is :%{public}d, logicalX is :%{private}d,"
4423             "logicalY is :%{private}d", pointerStyle.id, window.id, logicalX, logicalY);
4424     }
4425     if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
4426         SetMouseFlag(true);
4427         dragFlag_ = true;
4428         MMI_HILOGD("Is in drag scene");
4429     }
4430     if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_UP) {
4431         SetMouseFlag(false);
4432         dragFlag_ = false;
4433         isDragBorder_ = false;
4434     }
4435     Direction direction = DIRECTION0;
4436     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
4437         direction = GetDisplayDirection(physicalDisplayInfo);
4438 #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING
4439         TOUCH_DRAWING_MGR->GetOriginalTouchScreenCoordinates(direction, physicalDisplayInfo->validWidth,
4440             physicalDisplayInfo->validHeight, physicalX, physicalY);
4441 #endif // #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING
4442     }
4443 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
4444     MAGIC_POINTER_VELOCITY_TRACKER->MonitorCursorMovement(pointerEvent);
4445 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR
4446     int64_t beginTime = GetSysClockTime();
4447 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
4448     if (IsMouseDrawing(pointerEvent->GetPointerAction()) &&
4449         (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY))) {
4450         if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_HIDE_POINTER) ||
4451             pointerItem.GetMoveFlag() == POINTER_MOVEFLAG) {
4452             CursorDrawingComponent::GetInstance().SetMouseDisplayState(false);
4453         } else {
4454             CursorDrawingComponent::GetInstance().SetMouseDisplayState(true);
4455         }
4456         if (extraData_.drawCursor && pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_BUTTON_UP) {
4457             MMI_HILOGD("Cursor must be default, pointerStyle:%{public}d globalStyle:%{public}d",
4458                 dragPointerStyle_.id, globalStyle_.id);
4459             dragPointerStyle_ = globalStyle_;
4460         }
4461 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
4462         int64_t timeDT = GetTimeToMilli(GetSysClockTime() - pointerEvent->GetActionTime());
4463         if (timeDT > SIMULATE_EVENT_LATENCY) {
4464             MMI_HILOGI("simulate event latency, pointerId:%{public}d, timeDT:%{public}" PRId64,
4465                 pointerEvent->GetId(), timeDT);
4466             DfxHisyseventDevice::ReportSimulateToRsLatecyBehavior(pointerEvent->GetId(), timeDT);
4467         }
4468 #endif
4469         CursorDrawingComponent::GetInstance().DrawPointer(physicalDisplayInfo->rsId, physicalX, physicalY,
4470             dragPointerStyle_, direction);
4471     }
4472 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
4473 
4474     auto iter = cursorPosMap_.find(groupId);
4475     if (iter != cursorPosMap_.end()) {
4476         cursorPosMap_[groupId].direction = physicalDisplayInfo->direction;
4477         cursorPosMap_[groupId].displayDirection = physicalDisplayInfo->displayDirection;
4478     }
4479     int64_t endTime = GetSysClockTime();
4480     if ((endTime - beginTime) > RS_PROCESS_TIMEOUT) {
4481         MMI_HILOGW("Rs process timeout");
4482     }
4483 
4484     auto itr = captureModeInfoMap_.find(groupId);
4485     if (itr != captureModeInfoMap_.end()) {
4486         if (itr->second.isCaptureMode&& (touchWindow->id != itr->second.windowId)) {
4487             captureModeInfoMap_[groupId].isCaptureMode = false;
4488         }
4489     }
4490     SetPrivacyModeFlag(touchWindow->privacyMode, pointerEvent);
4491     pointerEvent->SetTargetWindowId(touchWindow->id);
4492     pointerEvent->SetAgentWindowId(touchWindow->agentWindowId);
4493     DispatchUIExtentionPointerEvent(logicalX, logicalY, pointerEvent);
4494     double windowX = logicalX - touchWindow->area.x;
4495     double windowY = logicalY - touchWindow->area.y;
4496     if (!(touchWindow->transform.empty())) {
4497         auto windowXY = TransformWindowXY(*touchWindow, logicalX, logicalY);
4498     }
4499     pointerItem.SetWindowX(static_cast<int32_t>(windowX));
4500     pointerItem.SetWindowY(static_cast<int32_t>(windowY));
4501     pointerItem.SetWindowXPos(windowX);
4502     pointerItem.SetWindowYPos(windowY);
4503     pointerItem.SetGlobalX(logicalX);
4504     pointerItem.SetGlobalY(logicalY);
4505     pointerEvent->UpdatePointerItem(pointerId, pointerItem);
4506     if ((extraData_.appended && (extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE)) ||
4507         (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_UP)) {
4508         pointerEvent->SetBuffer(extraData_.buffer);
4509         pointerEvent->SetPullId(extraData_.pullId);
4510         UpdatePointerAction(pointerEvent);
4511     } else {
4512         pointerEvent->ClearBuffer();
4513     }
4514     CHKPR(udsServer_, ERROR_NULL_POINTER);
4515 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
4516     UpdatePointerEvent(logicalX, logicalY, pointerEvent, *touchWindow);
4517 #elif defined(OHOS_BUILD_EMULATOR)
4518     if (CursorDrawingComponent::GetInstance().GetMouseDisplayState()) {
4519         UpdatePointerEvent(logicalX, logicalY, pointerEvent, *touchWindow);
4520     }
4521 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
4522 #ifdef OHOS_BUILD_ENABLE_ANCO
4523     if (touchWindow && IsInAncoWindow(*touchWindow, logicalX, logicalY)) {
4524         MMI_HILOGD("Process mouse event in Anco window, targetWindowId:%{public}d", touchWindow->id);
4525         pointerEvent->SetAncoDeal(true);
4526         SimulatePointerExt(pointerEvent);
4527         return RET_OK;
4528     }
4529 #endif // OHOS_BUILD_ENABLE_ANCO
4530     int32_t action = pointerEvent->GetPointerAction();
4531     if (action == PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
4532         mouseDownInfo_ = *touchWindow;
4533         mouseDownEventId_ = pointerEvent->GetId();
4534     }
4535     if ((action == PointerEvent::POINTER_ACTION_MOVE && !pointerEvent->GetPressedButtons().empty()) ||
4536         (action == PointerEvent::POINTER_ACTION_BUTTON_UP)) {
4537         if (touchWindow->id != mouseDownInfo_.id) {
4538             MMI_HILOGE("Mouse from:%{public}d move to new window:%{public}d", mouseDownInfo_.id, touchWindow->id);
4539         }
4540     }
4541     if (action == PointerEvent::POINTER_ACTION_BUTTON_UP) {
4542         mouseDownEventId_ = -1;
4543         MMI_HILOGD("Mouse up, clear mouse down info");
4544     }
4545     if (action == PointerEvent::POINTER_ACTION_CANCEL && mouseDownEventId_ > 0) {
4546         mouseDownEventId_ = -1;
4547     }
4548     if (action == PointerEvent::POINTER_ACTION_AXIS_END) {
4549         axisBeginWindowInfo_ = std::nullopt;
4550         MMI_HILOGD("Axis end, clear axis begin info");
4551     }
4552     if (EventLogHelper::IsBetaVersion() && !pointerEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
4553         MMI_HILOGD("pid:%{public}d, id:%{public}d, agentWindowId:%{public}d,"
4554             "logicalX:%{private}d, logicalY:%{private}d,"
4555             "displayX:%{private}d, displayY:%{private}d, windowX:%{private}d, windowY:%{private}d",
4556             isUiExtension_ ? uiExtensionPid_ : touchWindow->pid, isUiExtension_ ? uiExtensionWindowId_ :
4557             touchWindow->id, touchWindow->agentWindowId, logicalX, logicalY,
4558             pointerItem.GetDisplayX(), pointerItem.GetDisplayY(), pointerItem.GetWindowX(), pointerItem.GetWindowY());
4559     } else {
4560         MMI_HILOGD("pid:%{public}d, id:%{public}d, agentWindowId:%{public}d,"
4561             "logicalX:%d, logicalY:%d,displayX:%d, displayY:%d, windowX:%d, windowY:%d",
4562             isUiExtension_ ? uiExtensionPid_ : touchWindow->pid, isUiExtension_ ? uiExtensionWindowId_ :
4563             touchWindow->id, touchWindow->agentWindowId, logicalX, logicalY,
4564             pointerItem.GetDisplayX(), pointerItem.GetDisplayY(), pointerItem.GetWindowX(), pointerItem.GetWindowY());
4565     }
4566     if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_UP) {
4567         MMI_HILOGD("Clear extra data");
4568         InitMouseDownInfo();
4569         mouseDownEventId_ = -1;
4570         ClearExtraData();
4571     }
4572     if (pointerItem.GetMoveFlag() == POINTER_MOVEFLAG) {
4573         CursorDrawingComponent::GetInstance().SetMouseDisplayState(false);
4574     }
4575     return ERR_OK;
4576 }
4577 #endif // OHOS_BUILD_ENABLE_POINTER
4578 
4579 bool InputWindowsManager::IsMouseDrawing(int32_t currentAction)
4580 {
4581     if (currentAction != PointerEvent::POINTER_ACTION_LEAVE_WINDOW &&
4582         currentAction != PointerEvent::POINTER_ACTION_ENTER_WINDOW &&
4583         currentAction != PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW &&
4584         currentAction != PointerEvent::POINTER_ACTION_PULL_IN_WINDOW) {
4585         return true;
4586     }
4587     return false;
4588 }
4589 
4590 void InputWindowsManager::SetMouseFlag(bool state)
4591 {
4592     mouseFlag_ = state;
4593 }
4594 
4595 bool InputWindowsManager::GetMouseFlag()
4596 {
4597     return mouseFlag_;
4598 }
4599 
4600 #ifdef OHOS_BUILD_ENABLE_POINTER
4601 void InputWindowsManager::JudgMouseIsDownOrUp(bool dragState)
4602 {
4603     auto lastPointerEventCopy = GetlastPointerEvent();
4604     CHKPV(lastPointerEventCopy);
4605     if (!dragState && (lastPointerEventCopy->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_UP ||
4606         pointerActionFlag_ == PointerEvent::POINTER_ACTION_BUTTON_DOWN)) {
4607         SetMouseFlag(true);
4608         return;
4609     }
4610     if (lastPointerEventCopy->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
4611         SetMouseFlag(true);
4612     }
4613 }
4614 #endif // OHOS_BUILD_ENABLE_POINTER
4615 
4616 int32_t InputWindowsManager::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode)
4617 {
4618     CALL_DEBUG_ENTER;
4619     if (windowId < 0) {
4620         MMI_HILOGE("Windowid(%{public}d) is invalid", windowId);
4621         return RET_ERR;
4622     }
4623     auto itr = captureModeInfoMap_.find(MAIN_GROUPID);
4624     if (itr != captureModeInfoMap_.end()) {
4625         if (itr->second.isCaptureMode == isCaptureMode && !isCaptureMode) {
4626             MMI_HILOGE("Windowid:(%{public}d) is not capture mode", windowId);
4627             return RET_OK;
4628         }
4629         captureModeInfoMap_[MAIN_GROUPID].windowId = windowId;
4630         captureModeInfoMap_[MAIN_GROUPID].isCaptureMode = isCaptureMode;
4631     }
4632     MMI_HILOGI("Windowid:(%{public}d) is (%{public}d)", windowId, isCaptureMode);
4633     return RET_OK;
4634 }
4635 
4636 bool InputWindowsManager::GetMouseIsCaptureMode() const
4637 {
4638     CALL_DEBUG_ENTER;
4639     auto itr = captureModeInfoMap_.find(MAIN_GROUPID);
4640     if (itr != captureModeInfoMap_.end()) {
4641         return itr->second.isCaptureMode;
4642     }
4643     return false;
4644 }
4645 
4646 bool InputWindowsManager::IsNeedDrawPointer(PointerEvent::PointerItem &pointerItem) const
4647 {
4648     if (pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_PEN) {
4649         static int32_t lastDeviceId = -1;
4650         static std::shared_ptr<InputDevice> inputDevice = nullptr;
4651         auto nowId = pointerItem.GetDeviceId();
4652         if (lastDeviceId != nowId) {
4653             inputDevice = INPUT_DEV_MGR->GetInputDevice(nowId);
4654             CHKPF(inputDevice);
4655             lastDeviceId = nowId;
4656         }
4657         if (inputDevice != nullptr) {
4658             MMI_HILOGD("name:%{public}s type:%{public}d bus:%{public}d, "
4659                 "version:%{public}d product:%{public}d vendor:%{public}d, "
4660                 "phys:%{public}s uniq:%{public}s",
4661                 inputDevice->GetName().c_str(), inputDevice->GetType(), inputDevice->GetBus(),
4662                 inputDevice->GetVersion(), inputDevice->GetProduct(), inputDevice->GetVendor(),
4663                 inputDevice->GetPhys().c_str(), inputDevice->GetUniq().c_str());
4664         }
4665         if (inputDevice != nullptr && inputDevice->GetBus() == BUS_USB) {
4666             return true;
4667         }
4668     }
4669     return false;
4670 }
4671 
4672 bool InputWindowsManager::SkipPrivacyProtectionWindow(const std::shared_ptr<PointerEvent>& pointerEvent,
4673     const bool &isSkip)
4674 {
4675     CHKPF(pointerEvent);
4676     if (pointerEvent->GetDeviceId() == CAST_INPUT_DEVICEID ||
4677         pointerEvent->GetDeviceId() == CAST_SCREEN_DEVICEID) {
4678         if (!isOpenPrivacyProtectionserver_) {
4679             privacyProtection_.switchName = BUNDLE_NAME_PARSER.GetBundleName("PRIVACY_SWITCH_NAME");;
4680             CreatePrivacyProtectionObserver(privacyProtection_);
4681             isOpenPrivacyProtectionserver_ = true;
4682             SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).GetBoolValue(NAVIGATION_SWITCH_NAME,
4683                 antiMistake_.isOpen);
4684             MMI_HILOGD("Get privacy protection switch end");
4685         }
4686         if (privacyProtection_.isOpen && isSkip) {
4687             MMI_HILOGD("It's a Privacy protection window and pointer find the next window");
4688             return true;
4689         }
4690     }
4691     return false;
4692 }
4693 
4694 #ifdef OHOS_BUILD_ENABLE_TOUCH
4695 bool InputWindowsManager::SkipAnnotationWindow(uint32_t flag, int32_t toolType)
4696 {
4697     return ((flag & WindowInfo::FLAG_BIT_HANDWRITING) == WindowInfo::FLAG_BIT_HANDWRITING &&
4698             toolType == PointerEvent::TOOL_TYPE_FINGER);
4699 }
4700 
4701 bool InputWindowsManager::SkipNavigationWindow(WindowInputType windowType, int32_t toolType)
4702 {
4703     MMI_HILOGD("windowType:%{public}d, toolType:%{public}d", static_cast<int32_t>(windowType), toolType);
4704     if ((windowType != WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE &&
4705         windowType != WindowInputType::DUALTRIGGER_TOUCH &&
4706         windowType != WindowInputType::MIX_BUTTOM_ANTI_AXIS_MOVE) || toolType != PointerEvent::TOOL_TYPE_PEN) {
4707         return false;
4708     }
4709     if (!isOpenAntiMisTakeObserver_) {
4710         antiMistake_.switchName = NAVIGATION_SWITCH_NAME;
4711         CreateAntiMisTakeObserver(antiMistake_);
4712         isOpenAntiMisTakeObserver_ = true;
4713         MMI_HILOGI("Get anti mistake touch switch start");
4714         SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).GetBoolValue(NAVIGATION_SWITCH_NAME,
4715             antiMistake_.isOpen);
4716         MMI_HILOGI("Get anti mistake touch switch end");
4717     }
4718     if (antiMistake_.isOpen) {
4719         MMI_HILOGI("Anti mistake switch is open");
4720         return true;
4721     }
4722     return false;
4723 }
4724 
4725 void InputWindowsManager::GetUIExtentionWindowInfo(std::vector<WindowInfo> &uiExtentionWindowInfo, int32_t windowId,
4726     WindowInfo **touchWindow, bool &isUiExtentionWindow)
4727 {
4728     auto iter = std::find_if(uiExtentionWindowInfo.begin(), uiExtentionWindowInfo.end(),
4729         [windowId](const auto &windowInfo) {
4730             return windowId == windowInfo.id;
4731         }
4732     );
4733     if (iter != uiExtentionWindowInfo.end()) {
4734         *touchWindow = &(*iter);
4735         isUiExtentionWindow = true;
4736     }
4737 }
4738 #endif // OHOS_BUILD_ENABLE_TOUCH
4739 
4740 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
4741 bool InputWindowsManager::IsValidNavigationWindow(const WindowInfo& touchWindow, double physicalX, double physicalY)
4742 {
4743     return (touchWindow.windowInputType == WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE ||
4744             touchWindow.windowInputType == WindowInputType::DUALTRIGGER_TOUCH ||
4745             touchWindow.windowInputType == WindowInputType::MIX_BUTTOM_ANTI_AXIS_MOVE) &&
4746             IsInHotArea(static_cast<int32_t>(physicalX), static_cast<int32_t>(physicalY),
4747             touchWindow.defaultHotAreas, touchWindow);
4748 }
4749 
4750 bool InputWindowsManager::IsNavigationWindowInjectEvent(std::shared_ptr<PointerEvent> pointerEvent)
4751 {
4752     return (pointerEvent->GetZOrder() > 0 && pointerEvent->GetTargetWindowId() == -1);
4753 }
4754 
4755 #ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE
4756 void InputWindowsManager::UpdateDisplayXYInOneHandMode(double &physicalX, double &physicalY,
4757     const OLD::DisplayInfo &displayInfo, float oneHandScale)
4758 {
4759     double virtualY = physicalY - displayInfo.oneHandY;
4760     double virtualX = physicalX - displayInfo.oneHandX;
4761 
4762     if (oneHandScale == 0) {
4763         MMI_HILOGE("The divisor cannot be 0");
4764         return;
4765     }
4766     physicalX = virtualX / oneHandScale;
4767     physicalY = virtualY / oneHandScale;
4768 }
4769 
4770 void InputWindowsManager::HandleOneHandMode(const OLD::DisplayInfo &displayInfo,
4771     std::shared_ptr<PointerEvent> &pointerEvent, PointerEvent::PointerItem &pointerItem)
4772 {
4773     pointerEvent->SetFixedMode(PointerEvent::FixedMode::AUTO);
4774     MMI_HILOG_DISPATCHD("displayInfo.oneHandX=%{private}d, displayInfo.oneHandY=%{private}d, "
4775         "expandHeight=%{public}d,scalePercent=%{public}d, fixedModeStr=%{public}s",
4776         displayInfo.oneHandX, displayInfo.oneHandY, displayInfo.expandHeight, displayInfo.scalePercent,
4777         pointerEvent->GetFixedModeStr().c_str());
4778     double fixedDisplayX = pointerItem.GetDisplayXPos();
4779     double fixedDisplayY = pointerItem.GetDisplayYPos();
4780     float oneHandScale = displayInfo.scalePercent * 1.0 / 100;
4781     if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE)) {
4782         bool autoToVirtualScreen = pointerEvent->GetAutoToVirtualScreen();
4783         MMI_HILOG_DISPATCHD("autoToVirtualScreen=%{public}s", autoToVirtualScreen ? "true" : "false");
4784         if (autoToVirtualScreen) {
4785             UpdateDisplayXYInOneHandMode(fixedDisplayX, fixedDisplayY, displayInfo, oneHandScale);
4786         }
4787     } else {
4788         UpdateDisplayXYInOneHandMode(fixedDisplayX, fixedDisplayY, displayInfo, oneHandScale);
4789     }
4790     pointerItem.SetFixedDisplayXPos(fixedDisplayX);
4791     pointerItem.SetFixedDisplayYPos(fixedDisplayY);
4792 }
4793 
4794 void InputWindowsManager::UpdatePointerItemInOneHandMode(const OLD::DisplayInfo &displayInfo,
4795     std::shared_ptr<PointerEvent> &pointerEvent)
4796 {
4797     int32_t pointerId = pointerEvent->GetPointerId();
4798     PointerEvent::PointerItem pointerItem;
4799     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
4800         MMI_HILOG_DISPATCHE("Can't find pointer item, pointer:%{public}d", pointerId);
4801         return;
4802     }
4803     double physicalX = pointerItem.GetDisplayXPos();
4804     double physicalY = pointerItem.GetDisplayYPos();
4805     if (displayInfo.height == 0 || displayInfo.height == displayInfo.oneHandY) {
4806         MMI_HILOG_DISPATCHE("displayInfo.height=%{private}d, displayInfo.oneHandY=%{private}d is invalid",
4807             displayInfo.height, displayInfo.oneHandY);
4808         pointerEvent->SetFixedMode(PointerEvent::FixedMode::SCREEN_MODE_UNKNOWN);
4809         pointerItem.SetFixedDisplayXPos(physicalX);
4810         pointerItem.SetFixedDisplayYPos(physicalY);
4811         pointerEvent->UpdatePointerItem(pointerId, pointerItem);
4812         return;
4813     }
4814     if (displayInfo.scalePercent > 0 && displayInfo.scalePercent < 100) {
4815         HandleOneHandMode(displayInfo, pointerEvent, pointerItem);
4816     } else {
4817         pointerEvent->SetFixedMode(PointerEvent::FixedMode::NORMAL);
4818         pointerItem.SetFixedDisplayXPos(physicalX);
4819         pointerItem.SetFixedDisplayYPos(physicalY);
4820         MMI_HILOG_DISPATCHD("displayInfo.oneHandY=%{private}d, fixedModeStr=%{public}s",
4821             displayInfo.oneHandY, pointerEvent->GetFixedModeStr().c_str());
4822     }
4823     pointerEvent->UpdatePointerItem(pointerId, pointerItem);
4824     MMI_HILOG_DISPATCHD("targetDisplayId:%{private}d, DXY:{%{private}d, %{private}d}, FDXY:{%{private}.5f, "
4825         "%{private}.5f}", pointerEvent->GetTargetDisplayId(), pointerItem.GetDisplayX(),
4826         pointerItem.GetDisplayY(), pointerItem.GetFixedDisplayXPos(), pointerItem.GetFixedDisplayYPos());
4827 }
4828 #endif // OHOS_BUILD_ENABLE_ONE_HAND_MODE
4829 
4830 void InputWindowsManager::UpdateFixedXY(const OLD::DisplayInfo& displayInfo,
4831     std::shared_ptr<PointerEvent> &pointerEvent)
4832 {
4833 #ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE
4834     UpdatePointerItemInOneHandMode(displayInfo, pointerEvent);
4835 #else
4836     int32_t pointerId = pointerEvent->GetPointerId();
4837     PointerEvent::PointerItem pointerItem;
4838     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
4839         MMI_HILOG_DISPATCHE("Can't find pointer item, pointer:%{public}d", pointerId);
4840         return;
4841     }
4842     pointerItem.SetFixedDisplayXPos(pointerItem.GetDisplayXPos());
4843     pointerItem.SetFixedDisplayYPos(pointerItem.GetDisplayYPos());
4844     pointerEvent->UpdatePointerItem(pointerId, pointerItem);
4845 #endif // OHOS_BUILD_ENABLE_ONE_HAND_MODE
4846 }
4847 
4848 void InputWindowsManager::UpdateTransformDisplayXY(std::shared_ptr<PointerEvent> pointerEvent,
4849     const std::vector<WindowInfo>& windowsInfo, const OLD::DisplayInfo& displayInfo)
4850 {
4851     CHKPV(pointerEvent);
4852     bool isNavigationWindow = false;
4853     int32_t pointerId = pointerEvent->GetPointerId();
4854     PointerEvent::PointerItem pointerItem;
4855 
4856     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
4857         MMI_HILOG_DISPATCHE("Can't find pointer item, pointer:%{public}d", pointerId);
4858         return;
4859     }
4860     double physicalX = pointerItem.GetDisplayXPos();
4861     double physicalY = pointerItem.GetDisplayYPos();
4862 
4863     for (auto &item : windowsInfo) {
4864         if (IsValidNavigationWindow(item, physicalX, physicalY) &&
4865             !pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE_NAVIGATION) && pointerEvent->GetZOrder() <= 0) {
4866             isNavigationWindow = true;
4867             break;
4868         }
4869     }
4870     if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY) ||
4871         pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE_NAVIGATION) ||
4872         IsNavigationWindowInjectEvent(pointerEvent)) {
4873         if (!displayInfo.transform.empty() &&
4874             ((pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_UP) ||
4875             pointerEvent->GetZOrder() > 0) && !isNavigationWindow) {
4876             auto displayXY = TransformDisplayXY(displayInfo, physicalX, physicalY);
4877             physicalX = displayXY.first;
4878             physicalY = displayXY.second;
4879         }
4880     }
4881     if (isNavigationWindow && pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) {
4882         pointerEvent->AddFlag(InputEvent::EVENT_FLAG_SIMULATE_NAVIGATION);
4883     }
4884 
4885     pointerItem.SetDisplayX(static_cast<int32_t>(physicalX));
4886     pointerItem.SetDisplayY(static_cast<int32_t>(physicalY));
4887     GlobalCoords globalCoords = DisplayCoords2GlobalCoords({physicalX, physicalY}, pointerEvent->GetTargetDisplayId());
4888     pointerItem.SetGlobalX(globalCoords.x);
4889     pointerItem.SetGlobalY(globalCoords.y);
4890     pointerItem.SetDisplayXPos(physicalX);
4891     pointerItem.SetDisplayYPos(physicalY);
4892     pointerEvent->UpdatePointerItem(pointerId, pointerItem);
4893     UpdateFixedXY(displayInfo, pointerEvent);
4894 }
4895 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
4896 
4897 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
4898 void InputWindowsManager::SendUIExtentionPointerEvent(double logicalX, double logicalY,
4899     const WindowInfo& windowInfo, std::shared_ptr<PointerEvent> pointerEvent)
4900 {
4901     MMI_HILOG_DISPATCHI("Dispatch uiExtention pointer Event,pid:%{public}d", windowInfo.pid);
4902     CHKPV(pointerEvent);
4903     int32_t pointerId = pointerEvent->GetPointerId();
4904     PointerEvent::PointerItem pointerItem;
4905     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
4906         MMI_HILOG_DISPATCHE("Can't find pointer item, pointer:%{public}d", pointerId);
4907         return;
4908     }
4909     double windowX = logicalX - windowInfo.area.x;
4910     double windowY = logicalY - windowInfo.area.y;
4911     if (!(windowInfo.transform.empty())) {
4912         auto windowXY = TransformWindowXY(windowInfo, logicalX, logicalY);
4913         windowX = windowXY.first;
4914         windowY = windowXY.second;
4915     }
4916     int32_t displayInfoX = GetLogicalPositionX(pointerEvent->GetTargetDisplayId());
4917     int32_t displayInfoY = GetLogicalPositionY(pointerEvent->GetTargetDisplayId());
4918     double physicalX = logicalX - displayInfoX;
4919     double physicalY = logicalY - displayInfoY;
4920     pointerItem.SetDisplayX(static_cast<int32_t>(physicalX));
4921     pointerItem.SetDisplayY(static_cast<int32_t>(physicalY));
4922     GlobalCoords globalCoords = DisplayCoords2GlobalCoords({physicalX, physicalY}, pointerEvent->GetTargetDisplayId());
4923     pointerItem.SetGlobalX(globalCoords.x);
4924     pointerItem.SetGlobalY(globalCoords.y);
4925     pointerItem.SetDisplayXPos(physicalX);
4926     pointerItem.SetDisplayYPos(physicalY);
4927     pointerItem.SetWindowX(static_cast<int32_t>(windowX));
4928     pointerItem.SetWindowY(static_cast<int32_t>(windowY));
4929     pointerItem.SetWindowXPos(windowX);
4930     pointerItem.SetWindowYPos(windowY);
4931     pointerItem.SetTargetWindowId(windowInfo.id);
4932     pointerEvent->UpdatePointerItem(pointerId, pointerItem);
4933     CHKPV(udsServer_);
4934     auto fd = udsServer_->GetClientFd(windowInfo.pid);
4935     auto sess = udsServer_->GetSession(fd);
4936     CHKPRV(sess, "The window has disappeared");
4937     NetPacket pkt(MmiMessageId::ON_POINTER_EVENT);
4938     InputEventDataTransformation::Marshalling(pointerEvent, pkt);
4939     if (!sess->SendMsg(pkt)) {
4940         MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL);
4941         return;
4942     }
4943 }
4944 
4945 void InputWindowsManager::DispatchUIExtentionPointerEvent(double logicalX, double logicalY,
4946     std::shared_ptr<PointerEvent> pointerEvent)
4947 {
4948     auto displayId = pointerEvent->GetTargetDisplayId();
4949     const std::vector<WindowInfo> &windowsInfo = GetWindowGroupInfoByDisplayId(displayId);
4950     auto windowId = pointerEvent->GetTargetWindowId();
4951     for (const auto& item : windowsInfo) {
4952         if (windowId == item.id) {
4953             return;
4954         }
4955         for (const auto& windowInfo : item.uiExtentionWindowInfo) {
4956             if (windowInfo.id == windowId) {
4957                 MMI_HILOG_DISPATCHI("Dispatch uiExtention pointer Event,windowId:%{public}d", item.id);
4958                 // If the event is sent to the security sub window, then a copy needs to be sent to the host window
4959                 pointerEvent->SetAgentWindowId(item.agentWindowId);
4960                 pointerEvent->SetTargetWindowId(item.id);
4961                 SendUIExtentionPointerEvent(logicalX, logicalY, item, pointerEvent);
4962                 pointerEvent->SetAgentWindowId(windowInfo.agentWindowId);
4963                 pointerEvent->SetTargetWindowId(windowInfo.id);
4964                 return;
4965             }
4966         }
4967     }
4968 }
4969 
4970 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
4971 
4972 #ifdef OHOS_BUILD_ENABLE_TOUCH
4973 void InputWindowsManager::HandleGestureInjection(bool gestureInject) {
4974     if (!gestureInject) {
4975         CursorDrawingComponent::GetInstance().SetMouseDisplayState(false);
4976     }
4977 }
4978 
4979 void InputWindowsManager::ProcessInjectEventGlobalXY(std::shared_ptr<PointerEvent> pointerEvent, int32_t useCoordinate)
4980 {
4981     if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE)) {
4982         return;
4983     }
4984     if (useCoordinate != PointerEvent::GLOBAL_COORDINATE) {
4985         return;
4986     }
4987     int32_t pointerId = pointerEvent->GetPointerId();
4988     PointerEvent::PointerItem pointerItem;
4989 
4990     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
4991         MMI_HILOG_DISPATCHE("Can't find pointer item, pointer:%{public}d", pointerId);
4992         return;
4993     }
4994     double globalX = pointerItem.GetGlobalX();
4995     double globalY = pointerItem.GetGlobalY();
4996     if (globalX == DBL_MAX || globalY == DBL_MAX) {
4997         return;
4998     }
4999     const auto& mainGroup = GetDefaultDisplayGroupInfo();
5000     for (const auto& display : mainGroup.displaysInfo) {
5001         if (globalX >= display.x && globalX <= display.x + display.width &&
5002             globalY >= display.y && globalY <= display.y + display.height) {
5003             pointerEvent->SetTargetDisplayId(display.id);
5004             pointerItem.SetDisplayX(static_cast<int32_t>(globalX - display.x));
5005             pointerItem.SetDisplayY(static_cast<int32_t>(globalY - display.y));
5006             pointerItem.SetDisplayXPos(globalX - display.x);
5007             pointerItem.SetDisplayYPos(globalY - display.y);
5008             pointerEvent->UpdatePointerItem(pointerId, pointerItem);
5009             return;
5010         }
5011     }
5012 }
5013 
5014 int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptr<PointerEvent> pointerEvent)
5015 {
5016     CHKPR(pointerEvent, ERROR_NULL_POINTER);
5017     RemoveActiveWindow(pointerEvent);
5018 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
5019     if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_CANCEL) {
5020         MMI_HILOG_DISPATCHD("Abort UpdateTouchScreenTarget due to POINTER_ACTION_CANCEL");
5021         return RET_OK;
5022     }
5023 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
5024     auto displayId = pointerEvent->GetTargetDisplayId();
5025     if (!UpdateDisplayId(displayId)) {
5026         MMI_HILOG_DISPATCHE("This display is not existent");
5027         return RET_ERR;
5028     }
5029     pointerEvent->SetTargetDisplayId(displayId);
5030     int32_t groupId = FindDisplayGroupId(displayId);
5031     auto physicDisplayInfo = GetPhysicalDisplay(displayId);
5032     CHKPR(physicDisplayInfo, ERROR_NULL_POINTER);
5033     const std::vector<WindowInfo> &windowsInfo = GetWindowGroupInfoByDisplayId(displayId);
5034     UpdateTransformDisplayXY(pointerEvent, windowsInfo, *physicDisplayInfo);
5035     int32_t pointerId = pointerEvent->GetPointerId();
5036     PointerEvent::PointerItem pointerItem;
5037     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
5038         MMI_HILOG_DISPATCHE("Can't find pointer item, pointer:%{public}d", pointerId);
5039         return RET_ERR;
5040     }
5041     double physicalX = pointerItem.GetDisplayXPos();
5042     double physicalY = pointerItem.GetDisplayYPos();
5043 
5044     if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE)) {
5045         AdjustDisplayCoordinate(*physicDisplayInfo, physicalX, physicalY);
5046     }
5047     int32_t logicalX1 = 0;
5048     int32_t logicalY1 = 0;
5049 
5050     int32_t displayInfoX = GetLogicalPositionX(displayId);
5051     int32_t displayInfoY = GetLogicalPositionY(displayId);
5052     if (!AddInt32(static_cast<int32_t>(physicalX), displayInfoX, logicalX1)) {
5053         MMI_HILOG_DISPATCHE("The addition of logicalX overflows");
5054         return RET_ERR;
5055     }
5056     if (!AddInt32(static_cast<int32_t>(physicalY), displayInfoY, logicalY1)) {
5057         MMI_HILOG_DISPATCHE("The addition of logicalY overflows");
5058         return RET_ERR;
5059     }
5060     double logicalX = physicalX + displayInfoX;
5061     double logicalY = physicalY + displayInfoY;
5062     const WindowInfo *touchWindow = nullptr;
5063     auto targetWindowId = (NeedTouchTracking(*pointerEvent)? GLOBAL_WINDOW_ID : pointerItem.GetTargetWindowId());
5064     bool isHotArea = false;
5065     bool isFirstSpecialWindow = false;
5066     static std::unordered_map<int32_t, WindowInfo> winMap;
5067     if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) {
5068         ClearTargetWindowId(pointerId);
5069         if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE) && pointerEvent->GetPointerCount() == 1) {
5070             ClearActiveWindow();
5071         }
5072     }
5073     for (auto &item : windowsInfo) {
5074         bool checkWindow = (item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) == WindowInfo::FLAG_BIT_UNTOUCHABLE ||
5075             !IsValidZorderWindow(item, pointerEvent);
5076         if (checkWindow) {
5077             MMI_HILOG_DISPATCHD("Skip the untouchable or invalid zOrder window to continue searching,"
5078                 "window:%{public}d, flags:%{public}d", item.id, item.flags);
5079             winMap.insert({item.id, item});
5080             continue;
5081         }
5082         if (SkipPrivacyProtectionWindow(pointerEvent, item.isSkipSelfWhenShowOnVirtualScreen)) {
5083             winMap.insert({item.id, item});
5084             continue;
5085         }
5086         if (SkipAnnotationWindow(item.flags, pointerItem.GetToolType())) {
5087             winMap.insert({item.id, item});
5088             continue;
5089         }
5090         if (SkipNavigationWindow(item.windowInputType, pointerItem.GetToolType())) {
5091             winMap.insert({item.id, item});
5092             continue;
5093         }
5094         if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE) && item.windowType == SCREEN_CONTROL_WINDOW_TYPE) {
5095             winMap.insert({item.id, item});
5096             continue;
5097         }
5098         if (IsAccessibilityEventWithZorderInjected(pointerEvent) && pointerEvent->GetZOrder() <= item.zOrder) {
5099             winMap.insert({item.id, item});
5100             continue;
5101         }
5102 
5103         bool checkToolType = extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN &&
5104             ((pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_FINGER && extraData_.pointerId == pointerId) ||
5105             pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_PEN);
5106         checkToolType = checkToolType || (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_UP);
5107         if (checkToolType) {
5108             MMI_HILOG_DISPATCHD("Enter checkToolType");
5109             if (transparentWins_.find(item.id) != transparentWins_.end()) {
5110                 if (IsTransparentWin(transparentWins_[item.id], logicalX - item.area.x, logicalY - item.area.y)) {
5111                     MMI_HILOG_DISPATCHE("It's an abnormal window:%{public}d and touchscreen find the next window",
5112                         item.id);
5113                     winMap.insert({item.id, item});
5114                     continue;
5115                 }
5116             }
5117             if (IsInHotArea(static_cast<int32_t>(logicalX), static_cast<int32_t>(logicalY),
5118                 item.defaultHotAreas, item)) {
5119                 if (item.windowInputType == WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE) {
5120                     continue;
5121                 }
5122                 UpdateTargetTouchWinIds(item, pointerItem, pointerEvent, pointerId, displayId);
5123                 touchWindow = &item;
5124                 break;
5125             } else {
5126                 winMap.insert({item.id, item});
5127                 continue;
5128             }
5129         }
5130 #ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE
5131         bool isSlidTouch = (pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_FINGER  &&
5132             pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN &&
5133             pointerEvent->GetAllPointerItems().size() == 1 && !checkToolType &&
5134             pointerEvent->GetFixedMode() == PointerEvent::FixedMode::AUTO) ||
5135             (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_UP);
5136         if (isSlidTouch && lockWindowInfo_.windowInputType == WindowInputType::SLID_TOUCH_WINDOW) {
5137             if (IsInHotArea(static_cast<int32_t>(logicalX), static_cast<int32_t>(logicalY),
5138                 item.defaultHotAreas, item)) {
5139                 UpdateTargetTouchWinIds(item, pointerItem, pointerEvent, pointerId, displayId);
5140                 touchWindow = &item;
5141                 break;
5142             }
5143         }
5144 #endif // OHOS_BUILD_ENABLE_ONE_HAND_MODE
5145         if (targetWindowId >= 0 && pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_DOWN &&
5146             (pointerItem.GetToolType() != PointerEvent::TOOL_TYPE_PEN || pointerItem.GetPressure() > 0)) {
5147             bool isUiExtentionWindow = false;
5148             for (auto &windowinfo : item.uiExtentionWindowInfo) {
5149                 if (windowinfo.id == targetWindowId) {
5150                     touchWindow = &windowinfo;
5151                     isUiExtentionWindow = true;
5152                     break;
5153                 }
5154             }
5155             if (isUiExtentionWindow) {
5156                 break;
5157             }
5158             if (item.id == targetWindowId) {
5159                 touchWindow = &item;
5160                 break;
5161             }
5162         } else if (IsInHotArea(static_cast<int32_t>(logicalX), static_cast<int32_t>(logicalY),
5163             item.defaultHotAreas, item)) {
5164             if (transparentWins_.find(item.id) != transparentWins_.end()) {
5165                 if (IsTransparentWin(transparentWins_[item.id], logicalX - item.area.x, logicalY - item.area.y)) {
5166                     MMI_HILOG_DISPATCHE("It's an abnormal window:%{public}d and touchscreen find the next window",
5167                         item.id);
5168                     winMap.insert({item.id, item});
5169                     continue;
5170                 }
5171             }
5172             touchWindow = &item;
5173             AddActiveWindow(touchWindow->id, pointerEvent->GetPointerId());
5174             bool isSpecialWindow = HandleWindowInputType(item, pointerEvent);
5175             if (!isFirstSpecialWindow) {
5176                 isFirstSpecialWindow = isSpecialWindow;
5177                 if (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_MOVE &&
5178                     pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_MOVE &&
5179                     pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_HOVER_MOVE &&
5180                     pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_AXIS_UPDATE &&
5181                     pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_SWIPE_UPDATE &&
5182                     pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_ROTATE_UPDATE &&
5183                     pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE) {
5184                     MMI_HILOG_DISPATCHD("the first special window status:%{public}d", isFirstSpecialWindow);
5185                 }
5186             }
5187             std::pair<int32_t, int32_t> logicalXY(std::make_pair(static_cast<int32_t>(logicalX),
5188                 static_cast<int32_t>(logicalY)));
5189             // Determine whether the landing point is a safety sub window
5190             CheckUIExtentionWindowDefaultHotArea(logicalXY, isHotArea, pointerEvent, item.uiExtentionWindowInfo,
5191                 &touchWindow);
5192             if (isSpecialWindow) {
5193                 AddTargetWindowIds(pointerEvent->GetPointerId(), pointerEvent->GetSourceType(), item.id);
5194                 isHotArea = true;
5195                 continue;
5196             }
5197             break;
5198         } else {
5199             winMap.insert({item.id, item});
5200         }
5201     }
5202     if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) {
5203         std::ostringstream oss;
5204         for (auto iter = winMap.begin(); iter != winMap.end(); iter++) {
5205             oss << iter->first << "|" << iter->second.zOrder << "|";
5206             int32_t searchHotAreaCount = 0;
5207             int32_t searchHotAreaMaxCount = 4;
5208             for (auto &hotArea : iter->second.defaultHotAreas) {
5209                 searchHotAreaCount++;
5210                 oss << hotArea.x << "|" << hotArea.y << "|" << hotArea.width << "|" << hotArea.height << "|";
5211                 if (searchHotAreaCount >= searchHotAreaMaxCount) {
5212                     break;
5213                 }
5214             }
5215             oss << iter->second.pid << " ";
5216         }
5217         if (!oss.str().empty()) {
5218             MMI_HILOG_DISPATCHI("Pre search window %{public}d %{public}s", targetWindowId, oss.str().c_str());
5219         }
5220     }
5221     if (touchWindow == nullptr) {
5222         auto it = touchItemDownInfos_.find(pointerId);
5223         if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
5224             if (it == touchItemDownInfos_.end() ||
5225                 pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) {
5226                 int32_t originPointerAction = pointerEvent->GetPointerAction();
5227                 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
5228                 pointerEvent->SetOriginPointerAction(originPointerAction);
5229                 pointerItem.SetCanceled(true);
5230                 pointerEvent->UpdatePointerItem(pointerId, pointerItem);
5231                 MMI_HILOG_DISPATCHE("The touchWindow is nullptr, logicalX:%{private}f,"
5232                     "logicalY:%{private}f, pointerId:%{public}d", logicalX, logicalY, pointerId);
5233                 return RET_ERR;
5234             }
5235         }
5236         touchWindow = &it->second.window;
5237         if (it->second.flag) {
5238             if (IsAccessibilityFocusEvent(pointerEvent)) {
5239                 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_CANCEL);
5240             } else {
5241                 int32_t originPointerAction = pointerEvent->GetPointerAction();
5242                 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
5243                 pointerEvent->SetOriginPointerAction(originPointerAction);
5244             }
5245             MMI_HILOG_DISPATCHI("Not found event down target window, maybe this window was untouchable,"
5246                 "need send cancel event, windowId:%{public}d pointerId:%{public}d", touchWindow->id, pointerId);
5247         }
5248     }
5249     winMap.clear();
5250     ProcessTouchTracking(pointerEvent, *touchWindow);
5251     if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) {
5252         lockWindowInfo_ = *touchWindow;
5253         MMI_HILOG_DISPATCHD("lockWid:%{public}d, lockPid:%{public}d", lockWindowInfo_.id, lockWindowInfo_.pid);
5254     }
5255     pointerEvent->SetTargetWindowId(touchWindow->id);
5256     pointerItem.SetTargetWindowId(touchWindow->id);
5257 #ifdef OHOS_BUILD_ENABLE_ANCO
5258     bool isInAnco = touchWindow && IsInAncoWindow(*touchWindow, logicalX, logicalY);
5259     if (isInAnco) {
5260         MMI_HILOG_DISPATCHD("Process touch screen event in Anco window, targetWindowId:%{public}d", touchWindow->id);
5261         std::vector<int32_t> windowIds;
5262         GetTargetWindowIds(pointerId, pointerEvent->GetSourceType(), windowIds);
5263         if (windowIds.size() <= 1) {
5264             pointerEvent->SetAncoDeal(true);
5265         } else {
5266             for (int32_t windowId : windowIds) {
5267                 auto windowInfo = GetWindowAndDisplayInfo(windowId, pointerEvent->GetTargetDisplayId());
5268                 if (!windowInfo) {
5269                     continue;
5270                 }
5271                 isFirstSpecialWindow = isFirstSpecialWindow || HandleWindowInputType(*windowInfo, pointerEvent);
5272             }
5273         }
5274         pointerEvent->UpdatePointerItem(pointerId, pointerItem);
5275         // Simulate uinput automated injection operations (MMI_GE(pointerEvent->GetZOrder(), 0.0f))
5276         bool isCompensatePointer = (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE) &&
5277             !pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) ||
5278             (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY) &&
5279             !pointerEvent->HasFlag(InputEvent::EVENT_FLAG_GENERATE_FROM_REAL));
5280         if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) {
5281             MMI_HILOG_DISPATCHI("In Anco, WI:%{public}d, SI:%{public}d SW:%{public}d",
5282                 touchWindow->id, isCompensatePointer, isFirstSpecialWindow);
5283         }
5284         if (isCompensatePointer || isFirstSpecialWindow) {
5285             if (!(IsAncoGameActive() && MMI_GE(pointerEvent->GetZOrder(), 0.0f))) {
5286                 SimulatePointerExt(pointerEvent);
5287             } else {
5288                 MMI_HILOG_DISPATCHD("In the anco game scene, events from gestureNav are not allowed");
5289             }
5290             isFirstSpecialWindow = false;
5291         } else {
5292             if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) {
5293                 std::unordered_map<std::string, std::string> mapPayload;
5294                 mapPayload["msg"] = "";
5295                 constexpr int32_t touchDownBoost = 1006;
5296                 auto begin = std::chrono::high_resolution_clock::now();
5297                 OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(
5298                     OHOS::ResourceSchedule::ResType::RES_TYPE_SOCPERF_CUST_ACTION, touchDownBoost, mapPayload);
5299                 auto durationMS = std::chrono::duration_cast<std::chrono::milliseconds>(
5300                     std::chrono::high_resolution_clock::now() - begin).count();
5301 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
5302                 DfxHisysevent::ReportApiCallTimes(ApiDurationStatistics::Api::RESOURCE_SCHEDULE_REPORT_DATA,
5303                     durationMS);
5304 #endif // OHOS_BUILD_ENABLE_DFX_RADAR
5305             } else if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_UP) {
5306                 constexpr int32_t touchUpBoost = 1007;
5307                 std::unordered_map<std::string, std::string> mapPayload;
5308                 mapPayload["msg"] = "";
5309                 auto begin = std::chrono::high_resolution_clock::now();
5310                 OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(
5311                     OHOS::ResourceSchedule::ResType::RES_TYPE_SOCPERF_CUST_ACTION, touchUpBoost, mapPayload);
5312                 auto durationMS = std::chrono::duration_cast<std::chrono::milliseconds>(
5313                     std::chrono::high_resolution_clock::now() - begin).count();
5314 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
5315                 DfxHisysevent::ReportApiCallTimes(ApiDurationStatistics::Api::RESOURCE_SCHEDULE_REPORT_DATA,
5316                     durationMS);
5317 #endif // OHOS_BUILD_ENABLE_DFX_RADAR
5318             }
5319         }
5320         int32_t focusWindowId = GetFocusWindowId(groupId);
5321         if (focusWindowId == touchWindow->id) {
5322             pointerEvent->SetAgentWindowId(touchWindow->agentWindowId);
5323             return RET_OK;
5324         }
5325         pointerEvent->SetAncoDeal(false);
5326     }
5327 #endif // OHOS_BUILD_ENABLE_ANCO
5328     if (touchWindow->windowInputType == WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE) {
5329         if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) {
5330             lastTouchEventOnBackGesture_ = std::make_shared<PointerEvent>(*pointerEvent);
5331         }
5332         if (lastTouchEventOnBackGesture_ != nullptr &&
5333             lastTouchEventOnBackGesture_->GetPointerAction() != PointerEvent::POINTER_ACTION_CANCEL) {
5334             lastTouchEventOnBackGesture_ = std::make_shared<PointerEvent>(*pointerEvent);
5335         }
5336     }
5337     double windowX = logicalX - touchWindow->area.x;
5338     double windowY = logicalY - touchWindow->area.y;
5339     if (!(touchWindow->transform.empty())) {
5340         auto windowXY = TransformWindowXY(*touchWindow, logicalX, logicalY);
5341         windowX = windowXY.first;
5342         windowY = windowXY.second;
5343     }
5344     SetPrivacyModeFlag(touchWindow->privacyMode, pointerEvent);
5345     pointerEvent->SetAgentWindowId(touchWindow->agentWindowId);
5346     DispatchUIExtentionPointerEvent(logicalX, logicalY, pointerEvent);
5347     pointerItem.SetDisplayX(static_cast<int32_t>(physicalX));
5348     pointerItem.SetDisplayY(static_cast<int32_t>(physicalY));
5349     pointerItem.SetGlobalX(physicalX + physicDisplayInfo->x);
5350     pointerItem.SetGlobalY(physicalY + physicDisplayInfo->y);
5351     pointerItem.SetWindowX(static_cast<int32_t>(windowX));
5352     pointerItem.SetWindowY(static_cast<int32_t>(windowY));
5353     pointerItem.SetDisplayXPos(physicalX);
5354     pointerItem.SetDisplayYPos(physicalY);
5355     pointerItem.SetWindowXPos(windowX);
5356     pointerItem.SetWindowYPos(windowY);
5357     pointerItem.SetToolWindowX(pointerItem.GetToolDisplayX() + physicDisplayInfo->x - touchWindow->area.x);
5358     pointerItem.SetToolWindowY(pointerItem.GetToolDisplayY() + physicDisplayInfo->y - touchWindow->area.y);
5359     pointerEvent->UpdatePointerItem(pointerId, pointerItem);
5360     if (pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_THP_FEATURE) {
5361         return ERR_OK;
5362     }
5363     bool checkExtraData = extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN &&
5364         ((pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_FINGER && extraData_.pointerId == pointerId) ||
5365         pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_PEN);
5366     checkExtraData = checkExtraData || (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_UP);
5367     int32_t pointerAction = pointerEvent->GetPointerAction();
5368     if ((pointerAction == PointerEvent::POINTER_ACTION_DOWN) && !checkExtraData) {
5369         lastTouchLogicX_ = logicalX;
5370         lastTouchLogicY_ = logicalY;
5371         lastTouchEvent_ = pointerEvent;
5372         lastTouchWindowInfo_ = *touchWindow;
5373     }
5374     if (checkExtraData) {
5375         pointerEvent->SetBuffer(extraData_.buffer);
5376         pointerEvent->SetPullId(extraData_.pullId);
5377         UpdatePointerAction(pointerEvent);
5378         if (pointerAction != PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW &&
5379             pointerAction != PointerEvent::POINTER_ACTION_PULL_IN_WINDOW) {
5380             PullEnterLeaveEvent(logicalX, logicalY, pointerEvent, touchWindow);
5381         }
5382     }
5383 #ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE
5384     bool isSlidData = (pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_FINGER  &&
5385         pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN &&
5386         pointerEvent->GetAllPointerItems().size() == 1 && !checkExtraData &&
5387         pointerEvent->GetFixedMode() == PointerEvent::FixedMode::AUTO) ||
5388         (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_UP);
5389     if (isSlidData) {
5390         TouchEnterLeaveEvent(logicalX, logicalY, pointerEvent, touchWindow);
5391     }
5392 #endif // OHOS_BUILD_ENABLE_ONE_HAND_MODE
5393     isFoldPC_ = PRODUCT_TYPE_HYM == DEVICE_TYPE_FOLD_PC;
5394     if (isFoldPC_ && pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_UP) {
5395         PULL_THROW_EVENT_HANDLER->HandleFingerGesturePullUpEvent(pointerEvent);
5396     }
5397     // pointerAction:PA, targetWindowId:TWI, foucsWindowId:FWI, eventId:EID,
5398     // logicalX:LX, logicalY:LY, displayX:DX, displayX:DY, windowX:WX, windowY:WY,
5399     // width:W, height:H, area.x:AX, area.y:AY, displayId:DID, AgentWindowId: AWI
5400     if ((pointerAction != PointerEvent::POINTER_ACTION_MOVE &&
5401         pointerAction != PointerEvent::POINTER_ACTION_PULL_MOVE &&
5402         pointerAction != PointerEvent::POINTER_ACTION_HOVER_MOVE &&
5403         pointerAction != PointerEvent::POINTER_ACTION_AXIS_UPDATE &&
5404         pointerAction != PointerEvent::POINTER_ACTION_SWIPE_UPDATE &&
5405         pointerAction != PointerEvent::POINTER_ACTION_ROTATE_UPDATE &&
5406         pointerAction != PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE)) {
5407         int32_t focusWindowId = GetFocusWindowId(groupId);
5408         if (!EventLogHelper::IsBetaVersion()) {
5409             MMI_HILOG_FREEZEI("PA:%{public}s,Pid:%{public}d,TWI:%{public}d,"
5410                 "FWI:%{public}d,EID:%{public}d, flags:%{public}d,DID:%{public}d"
5411                 "AWI:%{public}d,zOrder:%{public}1f",
5412                 pointerEvent->DumpPointerAction(), touchWindow->pid, touchWindow->id,
5413                 focusWindowId, pointerEvent->GetId(), touchWindow->flags,
5414                 displayId, pointerEvent->GetAgentWindowId(), touchWindow->zOrder);
5415         } else {
5416             MMI_HILOGD("PA:%{public}s,LX:%{private}1f,LY:%{private}1f,"
5417                 "DX:%{private}1f,DY:%{private}1f,WX:%{private}1f,WY:%{private}1f,"
5418                 "AX:%{private}d,AY:%{private}d,flags:%{public}d,",
5419                 pointerEvent->DumpPointerAction(), logicalX, logicalY, physicalX, physicalY,
5420                 windowX, windowY, touchWindow->area.x, touchWindow->area.y, touchWindow->flags);
5421             MMI_HILOG_FREEZEI("%{public}d|%{public}d|%{public}d|%{public}d|%{public}d|"
5422                 "%{public}d|%{public}d|%{public}1f",
5423                 touchWindow->pid, touchWindow->id, focusWindowId,
5424                 touchWindow->area.width, touchWindow->area.height, displayId,
5425                 pointerEvent->GetAgentWindowId(), touchWindow->zOrder);
5426         }
5427     }
5428     bool gestureInject = false;
5429     if ((pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE)) && MMI_GNE(pointerEvent->GetZOrder(), 0.0f)) {
5430         gestureInject = true;
5431     }
5432 #if defined(OHOS_BUILD_ENABLE_POINTER) && (defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) || defined(OHOS_BUILD_EMULATOR))
5433     if (IsNeedDrawPointer(pointerItem)) {
5434         if (!CursorDrawingComponent::GetInstance().GetMouseDisplayState()) {
5435             CursorDrawingComponent::GetInstance().SetMouseDisplayState(true);
5436             if (touchWindow->id != lastWindowInfo_.id) {
5437                 lastWindowInfo_ = *touchWindow;
5438             }
5439             DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW, lastWindowInfo_.id);
5440         }
5441         PointerStyle pointerStyle;
5442         GetPointerStyle(touchWindow->pid, touchWindow->id, pointerStyle);
5443         CursorDrawingComponent::GetInstance().UpdateDisplayInfo(*physicDisplayInfo);
5444         WinInfo info = { .windowPid = touchWindow->pid, .windowId = touchWindow->id };
5445         CursorDrawingComponent::GetInstance().OnWindowInfo(info);
5446         CursorDrawingComponent::GetInstance().DrawPointer(physicDisplayInfo->rsId,
5447             pointerItem.GetDisplayX(), pointerItem.GetDisplayY(), pointerStyle, physicDisplayInfo->direction);
5448     } else if (CursorDrawingComponent::GetInstance().GetMouseDisplayState()) {
5449         if ((!checkExtraData) && (!(extraData_.appended &&
5450             extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE))) {
5451             MMI_HILOG_DISPATCHD("PointerAction is to leave the window");
5452             if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SHOW_CUSOR_WITH_TOUCH) && timerId_ == DEFAULT_VALUE) {
5453                 timerId_ = TimerMgr->AddTimer(REPEAT_COOLING_TIME, REPEAT_ONCE, [this, gestureInject]() {
5454                     DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
5455                     HandleGestureInjection(gestureInject);
5456                     timerId_ = DEFAULT_VALUE;
5457                 }, "InputWindowsManager");
5458             }
5459         }
5460     }
5461 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
5462     int32_t curGroupId = FindDisplayGroupId(pointerEvent->GetTargetDisplayId());
5463     lastPointerEventforWindowChangeMap_[curGroupId] = pointerEvent;
5464     lastPointerEventforGesture_ = pointerEvent;
5465     pointerAction = pointerEvent->GetPointerAction();
5466     if (pointerAction == PointerEvent::POINTER_ACTION_DOWN ||
5467         pointerAction == PointerEvent::POINTER_ACTION_HOVER_ENTER) {
5468         WindowInfoEX windowInfoEX;
5469         windowInfoEX.window = *touchWindow;
5470         windowInfoEX.flag = true;
5471         touchItemDownInfos_[pointerId] = windowInfoEX;
5472         MMI_HILOG_FREEZEI("PointerId:%{public}d, touchWindow:%{public}d", pointerId, touchWindow->id);
5473     } else if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_UP) {
5474         MMI_HILOG_DISPATCHD("Clear extra data");
5475         pointerEvent->ClearBuffer();
5476         lastTouchEvent_ = nullptr;
5477         lastTouchWindowInfo_.id = -1;
5478         ClearExtraData();
5479     }
5480     return ERR_OK;
5481 }
5482 
5483 void InputWindowsManager::UpdateTargetTouchWinIds(const WindowInfo &item, PointerEvent::PointerItem &pointerItem,
5484     std::shared_ptr<PointerEvent> pointerEvent, int32_t pointerId, int32_t displayId) {
5485     if (item.windowInputType != WindowInputType::TRANSMIT_ALL) {
5486         WIN_MGR->GetTargetWindowIds(pointerItem.GetPointerId(), pointerEvent->GetSourceType(),
5487             targetTouchWinIds_[pointerId]);
5488         if (!targetTouchWinIds_[pointerId].empty()) {
5489             ClearMismatchTypeWinIds(pointerId, displayId);
5490             targetTouchWinIds_[pointerId].push_back(item.id);
5491         }
5492     }
5493 }
5494 
5495 void InputWindowsManager::ClearMismatchTypeWinIds(int32_t pointerId, int32_t displayId) {
5496     for (int32_t windowId : targetTouchWinIds_[pointerId]) {
5497         auto windowInfo = WIN_MGR->GetWindowAndDisplayInfo(windowId, displayId);
5498         CHKCC(windowInfo);
5499         if (windowInfo->windowInputType != WindowInputType::TRANSMIT_ALL) {
5500             auto it = std::find(targetTouchWinIds_[pointerId].begin(), targetTouchWinIds_[pointerId].end(), windowId);
5501             if (it != targetTouchWinIds_[pointerId].end()) {
5502                 targetTouchWinIds_[pointerId].erase(it);
5503             }
5504         }
5505     }
5506 }
5507 
5508 void InputWindowsManager::CheckUIExtentionWindowDefaultHotArea(std::pair<int32_t, int32_t> logicalXY,
5509     bool isHotArea, const std::shared_ptr<PointerEvent> pointerEvent, const std::vector<WindowInfo>& windowInfos,
5510     const WindowInfo** touchWindow)
5511 {
5512     CHKPV(pointerEvent);
5513     CHKPV(touchWindow);
5514     CHKPV(*touchWindow);
5515     int32_t uiExtentionWindowId = 0;
5516     int32_t windowId = (*touchWindow)->id;
5517     int32_t logicalX = logicalXY.first;
5518     int32_t logicalY = logicalXY.second;
5519     for (const auto& it : windowInfos) {
5520         if (IsInHotArea(logicalX, logicalY, it.defaultHotAreas, it)) {
5521             uiExtentionWindowId = it.id;
5522             break;
5523         }
5524     }
5525     if (uiExtentionWindowId > 0) {
5526         for (auto &windowinfo : windowInfos) {
5527             if (windowinfo.id == uiExtentionWindowId) {
5528                 *touchWindow = &windowinfo;
5529                 MMI_HILOG_DISPATCHD("uiExtentionWindowid:%{public}d", uiExtentionWindowId);
5530                 AddActiveWindow(windowinfo.id, pointerEvent->GetPointerId());
5531                 AddTargetWindowIds(pointerEvent->GetPointerId(), pointerEvent->GetSourceType(), uiExtentionWindowId);
5532                 break;
5533             }
5534         }
5535     }
5536     if (isHotArea) {
5537         AddTargetWindowIds(pointerEvent->GetPointerId(), pointerEvent->GetSourceType(), windowId);
5538     }
5539 }
5540 
5541 void InputWindowsManager::PullEnterLeaveEvent(int32_t logicalX, int32_t logicalY,
5542     const std::shared_ptr<PointerEvent> pointerEvent, const WindowInfo* touchWindow)
5543 {
5544     CHKPV(pointerEvent);
5545     CHKPV(touchWindow);
5546     MMI_HILOG_DISPATCHD("LastTouchWindowInfo:%{public}d, touchWindow:%{public}d",
5547         lastTouchWindowInfo_.id, touchWindow->id);
5548     if (lastTouchWindowInfo_.id != touchWindow->id) {
5549         if (lastTouchWindowInfo_.id != -1) {
5550             DispatchTouch(PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW, pointerEvent->GetTargetDisplayId());
5551         }
5552         lastTouchLogicX_ = logicalX;
5553         lastTouchLogicY_ = logicalY;
5554         lastTouchEvent_ = pointerEvent;
5555         lastTouchWindowInfo_ = *touchWindow;
5556         DispatchTouch(PointerEvent::POINTER_ACTION_PULL_IN_WINDOW, pointerEvent->GetTargetDisplayId());
5557         return;
5558     }
5559     lastTouchLogicX_ = logicalX;
5560     lastTouchLogicY_ = logicalY;
5561     lastTouchEvent_ = pointerEvent;
5562     lastTouchWindowInfo_ = *touchWindow;
5563 }
5564 
5565 void InputWindowsManager::DispatchTouch(int32_t pointerAction, int32_t groupId)
5566 {
5567     CALL_INFO_TRACE;
5568     CHKPV(udsServer_);
5569     CHKPV(lastTouchEvent_);
5570     if (pointerAction == PointerEvent::POINTER_ACTION_PULL_IN_WINDOW) {
5571         WindowInfo touchWindow;
5572         bool isChanged { false };
5573         auto &WindowsInfo = GetWindowInfoVector(groupId);
5574         for (const auto &item : WindowsInfo) {
5575             if ((item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) == WindowInfo::FLAG_BIT_UNTOUCHABLE) {
5576                 MMI_HILOGD("Skip the untouchable window to continue searching, "
5577                     "window:%{public}d, flags:%{public}d", item.id, item.flags);
5578                 continue;
5579             }
5580             if (item.windowInputType == WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE) {
5581                 continue;
5582             }
5583             if (IsInHotArea(lastTouchLogicX_, lastTouchLogicY_, item.defaultHotAreas, item)) {
5584                 touchWindow = item;
5585                 isChanged = true;
5586                 break;
5587             }
5588         }
5589         if (!isChanged) {
5590             MMI_HILOGE("touchWindow is not init");
5591             return;
5592         }
5593         if (touchWindow.id != lastTouchWindowInfo_.id) {
5594             lastTouchWindowInfo_ = touchWindow;
5595         }
5596     }
5597     auto pointerEvent = PointerEvent::Create();
5598     CHKPV(pointerEvent);
5599     PointerEvent::PointerItem lastPointerItem;
5600     int32_t lastPointerId = lastTouchEvent_->GetPointerId();
5601     if (!lastTouchEvent_->GetPointerItem(lastPointerId, lastPointerItem)) {
5602         MMI_HILOGE("GetPointerItem:%{public}d fail", lastPointerId);
5603         return;
5604     }
5605     PointerEvent::PointerItem currentPointerItem;
5606     bool isOneHand = lastTouchEvent_->GetFixedMode() == PointerEvent::FixedMode::AUTO;
5607     double windowX = isOneHand ? lastWinX_ : (lastTouchLogicX_ - lastTouchWindowInfo_.area.x);
5608     double windowY = isOneHand ? lastWinY_ : (lastTouchLogicY_ - lastTouchWindowInfo_.area.y);
5609     if (isOneHand) {
5610         WindowInputType windowInputType = lastTouchWindowInfo_.windowInputType;
5611         if (windowInputType != WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE &&
5612             windowInputType != WindowInputType::DUALTRIGGER_TOUCH &&
5613             windowInputType != WindowInputType::MIX_BUTTOM_ANTI_AXIS_MOVE) {
5614             if (!(lastTouchWindowInfo_.transform.empty())) {
5615                 auto windowXY = TransformWindowXY(lastTouchWindowInfo_, lastTouchLogicX_, lastTouchLogicY_);
5616                 windowX = windowXY.first;
5617                 windowY = windowXY.second;
5618             }
5619             currentPointerItem.SetFixedDisplayXPos(lastPointerItem.GetFixedDisplayXPos());
5620             currentPointerItem.SetFixedDisplayYPos(lastPointerItem.GetFixedDisplayYPos());
5621             pointerEvent->SetFixedMode(PointerEvent::FixedMode::AUTO);
5622         }
5623     }
5624     currentPointerItem.SetWindowX(static_cast<int32_t>(windowX));
5625     currentPointerItem.SetWindowY(static_cast<int32_t>(windowY));
5626     currentPointerItem.SetWindowXPos(windowX);
5627     currentPointerItem.SetWindowYPos(windowY);
5628     currentPointerItem.SetDisplayX(lastPointerItem.GetDisplayX());
5629     currentPointerItem.SetDisplayY(lastPointerItem.GetDisplayY());
5630     currentPointerItem.SetGlobalX(lastPointerItem.GetGlobalX());
5631     currentPointerItem.SetGlobalY(lastPointerItem.GetGlobalY());
5632     currentPointerItem.SetDisplayXPos(lastPointerItem.GetDisplayXPos());
5633     currentPointerItem.SetDisplayYPos(lastPointerItem.GetDisplayYPos());
5634     currentPointerItem.SetPressed(lastPointerItem.IsPressed());
5635     currentPointerItem.SetPointerId(lastPointerId);
5636 
5637     pointerEvent->UpdateId();
5638     LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction());
5639     pointerEvent->SetTargetDisplayId(lastTouchEvent_->GetTargetDisplayId());
5640     SetPrivacyModeFlag(lastTouchWindowInfo_.privacyMode, pointerEvent);
5641     pointerEvent->SetTargetWindowId(lastTouchWindowInfo_.id);
5642     pointerEvent->SetAgentWindowId(lastTouchWindowInfo_.agentWindowId);
5643     pointerEvent->SetPointerId(lastPointerId);
5644     pointerEvent->AddPointerItem(currentPointerItem);
5645     pointerEvent->SetPointerAction(pointerAction);
5646     pointerEvent->SetBuffer(extraData_.buffer);
5647     pointerEvent->SetPullId(extraData_.pullId);
5648     pointerEvent->SetSourceType(lastTouchEvent_->GetSourceType());
5649     int64_t time = GetSysClockTime();
5650     pointerEvent->SetActionTime(time);
5651     pointerEvent->SetActionStartTime(time);
5652     pointerEvent->SetDeviceId(lastTouchEvent_->GetDeviceId());
5653     if (lastTouchEvent_->HasFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT)) {
5654         pointerEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
5655     }
5656 
5657     EventLogHelper::PrintEventData(pointerEvent, MMI_LOG_FREEZE);
5658     auto filter = InputHandler->GetFilterHandler();
5659     CHKPV(filter);
5660     filter->HandlePointerEvent(pointerEvent);
5661 }
5662 #endif // OHOS_BUILD_ENABLE_TOUCH
5663 
5664 #ifdef OHOS_BUILD_ENABLE_POINTER
5665 int32_t InputWindowsManager::UpdateTouchPadTarget(std::shared_ptr<PointerEvent> pointerEvent)
5666 {
5667     CALL_DEBUG_ENTER;
5668     int32_t pointerAction = pointerEvent->GetPointerAction();
5669     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
5670     switch (pointerAction) {
5671         case PointerEvent::POINTER_ACTION_BUTTON_DOWN:
5672         case PointerEvent::POINTER_ACTION_BUTTON_UP:
5673         case PointerEvent::POINTER_ACTION_MOVE: {
5674             return UpdateMouseTarget(pointerEvent);
5675         }
5676         case PointerEvent::POINTER_ACTION_DOWN: {
5677             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
5678             pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
5679             pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
5680             return UpdateMouseTarget(pointerEvent);
5681         }
5682         case PointerEvent::POINTER_ACTION_UP: {
5683             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP);
5684             pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
5685             pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
5686             return UpdateMouseTarget(pointerEvent);
5687         }
5688         default: {
5689             MMI_HILOG_DISPATCHE("pointer action is unknown, pointerAction:%{public}d", pointerAction);
5690             return RET_ERR;
5691         }
5692     }
5693     return RET_OK;
5694 }
5695 #endif // OHOS_BUILD_ENABLE_POINTER
5696 
5697 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
5698 int32_t InputWindowsManager::UpdateJoystickTarget(std::shared_ptr<PointerEvent> pointerEvent)
5699 {
5700     CALL_DEBUG_ENTER;
5701     CHKPR(pointerEvent, ERROR_NULL_POINTER);
5702     int32_t groupId = FindDisplayGroupId(pointerEvent->GetTargetDisplayId());
5703     int32_t focusWindowId = GetFocusWindowId(groupId);
5704     const WindowInfo* windowInfo = nullptr;
5705     std::vector<WindowInfo> windowsInfo = GetWindowGroupInfoByDisplayId(pointerEvent->GetTargetDisplayId());
5706     for (const auto &item : windowsInfo) {
5707         if (item.id == focusWindowId) {
5708             windowInfo = &item;
5709             break;
5710         }
5711     }
5712     CHKPR(windowInfo, ERROR_NULL_POINTER);
5713     SetPrivacyModeFlag(windowInfo->privacyMode, pointerEvent);
5714     pointerEvent->SetTargetDisplayId(windowInfo->displayId);
5715     pointerEvent->SetTargetWindowId(windowInfo->id);
5716     pointerEvent->SetAgentWindowId(windowInfo->agentWindowId);
5717     MMI_HILOG_DISPATCHD("focusWindow:%{public}d, pid:%{public}d", focusWindowId, windowInfo->pid);
5718     return RET_OK;
5719 }
5720 #endif // OHOS_BUILD_ENABLE_JOYSTICK
5721 
5722 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_CROWN)
5723 int32_t InputWindowsManager::UpdateCrownTarget(std::shared_ptr<PointerEvent> pointerEvent)
5724 {
5725     CALL_DEBUG_ENTER;
5726     CHKPR(pointerEvent, ERROR_NULL_POINTER);
5727     return UpdateMouseTarget(pointerEvent);
5728 }
5729 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_CROWN
5730 
5731 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
5732 void InputWindowsManager::DrawTouchGraphic(std::shared_ptr<PointerEvent> pointerEvent)
5733 {
5734     CALL_DEBUG_ENTER;
5735     CHKPV(pointerEvent);
5736     auto displayId = pointerEvent->GetTargetDisplayId();
5737     if (!UpdateDisplayId(displayId)) {
5738         MMI_HILOGE("This display is not exist");
5739         return;
5740     }
5741     auto physicDisplayInfo = GetPhysicalDisplay(displayId);
5742     CHKPV(physicDisplayInfo);
5743 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_COMBINATION_KEY) && \
5744     defined(OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER)
5745     std::shared_ptr<OHOS::MMI::InputEventHandler> inputHandler = InputHandler;
5746     CHKPV(InputHandler->GetKeyCommandHandler());
5747     auto isInMethodWindow = InputHandler->GetKeyCommandHandler()->CheckInputMethodArea(pointerEvent);
5748     if (isInMethodWindow) {
5749         int32_t pointerId = pointerEvent->GetPointerId();
5750         PointerEvent::PointerItem item;
5751         if (!pointerEvent->GetPointerItem(pointerId, item)) {
5752             MMI_HILOGE("Invalid pointer:%{public}d", pointerId);
5753             return;
5754         }
5755         if (item.GetToolType() == PointerEvent::TOOL_TYPE_KNUCKLE) {
5756             item.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
5757             pointerEvent->UpdatePointerItem(pointerId, item);
5758         }
5759     }
5760     if (!isInMethodWindow) {
5761         KnuckleDrawingComponent::GetInstance().Draw(*physicDisplayInfo, pointerEvent);
5762     }
5763 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_COMBINATION_KEY && OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER
5764 
5765 #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING
5766     TOUCH_DRAWING_MGR->UpdateDisplayInfo(*physicDisplayInfo);
5767     TOUCH_DRAWING_MGR->TouchDrawHandler(pointerEvent);
5768 #endif // #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING
5769 }
5770 
5771 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
5772 
5773 template <class T>
5774 void InputWindowsManager::CreateAntiMisTakeObserver(T& item)
5775 {
5776     CALL_INFO_TRACE;
5777     SettingObserver::UpdateFunc updateFunc = [&item](const std::string& key) {
5778         if (SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).GetBoolValue(key, item.isOpen) != RET_OK) {
5779             MMI_HILOGE("Get settingdata failed, key:%{public}s", key.c_str());
5780         }
5781         MMI_HILOGI("Anti mistake observer key:%{public}s, statusValue:%{public}d", key.c_str(), item.isOpen);
5782     };
5783     sptr<SettingObserver> statusObserver = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID)
5784         .CreateObserver(item.switchName, updateFunc);
5785     CHKPV(statusObserver);
5786     ErrCode ret = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).RegisterObserver(statusObserver);
5787     if (ret != ERR_OK) {
5788         MMI_HILOGE("Register setting observer failed, ret:%{public}d", ret);
5789         statusObserver = nullptr;
5790     }
5791 }
5792 
5793 template <class T>
5794 void InputWindowsManager::CreatePrivacyProtectionObserver(T& item)
5795 {
5796     CALL_INFO_TRACE;
5797     SettingObserver::UpdateFunc updateFunc = [&item](const std::string& key) {
5798         if (SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).GetBoolValue(key, item.isOpen) != RET_OK) {
5799             MMI_HILOGE("Get settingdata failed, key:%{public}s", key.c_str());
5800         }
5801         MMI_HILOGI("privacy protection key:%{public}s, statusValue:%{public}d", key.c_str(), item.isOpen);
5802     };
5803     sptr<SettingObserver> statusObserver = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID)
5804         .CreateObserver(item.switchName, updateFunc);
5805     CHKPV(statusObserver);
5806     ErrCode ret = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).RegisterObserver(statusObserver);
5807     if (ret != ERR_OK) {
5808         MMI_HILOGE("Register setting observer failed, ret:%{public}d", ret);
5809         statusObserver = nullptr;
5810     }
5811 }
5812 
5813 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
5814 int32_t InputWindowsManager::UpdateTargetPointer(std::shared_ptr<PointerEvent> pointerEvent)
5815 {
5816     CALL_DEBUG_ENTER;
5817     CHKPR(pointerEvent, ERROR_NULL_POINTER);
5818     auto source = pointerEvent->GetSourceType();
5819     pointerActionFlag_ = pointerEvent->GetPointerAction();
5820 #ifdef OHOS_BUILD_ENABLE_ANCO
5821     pointerEvent->SetAncoDeal(false);
5822 #endif // OHOS_BUILD_ENABLE_ANCO
5823     if (IsFoldable_ && IgnoreTouchEvent(pointerEvent)) {
5824         MMI_HILOG_DISPATCHD("Ignore touch event, pointerAction:%{public}d", pointerActionFlag_);
5825         return RET_OK;
5826     };
5827     int32_t ret { RET_ERR };
5828     switch (source) {
5829 #ifdef OHOS_BUILD_ENABLE_TOUCH
5830         case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: {
5831             ret = UpdateTouchScreenTarget(pointerEvent);
5832             break;
5833         }
5834 #endif // OHOS_BUILD_ENABLE_TOUCH
5835 #ifdef OHOS_BUILD_ENABLE_POINTER
5836         case PointerEvent::SOURCE_TYPE_MOUSE: {
5837             ret =  UpdateMouseTarget(pointerEvent);
5838             break;
5839         }
5840         case PointerEvent::SOURCE_TYPE_TOUCHPAD: {
5841             ret = UpdateTouchPadTarget(pointerEvent);
5842             break;
5843         }
5844 #endif // OHOS_BUILD_ENABLE_POINTER
5845 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
5846         case PointerEvent::SOURCE_TYPE_JOYSTICK: {
5847             ret = UpdateJoystickTarget(pointerEvent);
5848             break;
5849         }
5850 #endif // OHOS_BUILD_ENABLE_JOYSTICK
5851 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_CROWN)
5852         case PointerEvent::SOURCE_TYPE_CROWN: {
5853             ret = UpdateCrownTarget(pointerEvent);
5854             break;
5855         }
5856 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_CROWN
5857         default: {
5858             MMI_HILOG_DISPATCHE("Source type is unknown, source:%{public}d", source);
5859             return ret;
5860         }
5861     }
5862 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
5863     HandlePullEvent(pointerEvent);
5864 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
5865     return ret;
5866 }
5867 
5868 bool InputWindowsManager::IsInsideDisplay(const OLD::DisplayInfo& displayInfo, double physicalX, double physicalY)
5869 {
5870     auto displayDirection = GetDisplayDirection(&displayInfo);
5871     auto physicalRect = RotateRect<int32_t>(displayDirection, { displayInfo.validWidth, displayInfo.validHeight });
5872     bool isInside = (physicalX >= 0 && physicalX < physicalRect.x) && (physicalY >= 0 && physicalY < physicalRect.y);
5873     PrintDisplayInfo(displayInfo);
5874     MMI_HILOGD("isInside:%{public}d physicalXY={%{private}f %{private}f} "
5875         "physicalRect={%{public}d %{public}d} useDirection:%{public}d}",
5876         static_cast<int32_t>(isInside),
5877         physicalX,
5878         physicalY,
5879         physicalRect.x,
5880         physicalRect.y,
5881         displayDirection);
5882     return isInside;
5883 }
5884 
5885 bool InputWindowsManager::CalculateLayout(const OLD::DisplayInfo &displayInfo, const Vector2D<double> &physical,
5886     Vector2D<double> &layout)
5887 {
5888     Direction direction = GetDisplayDirection(&displayInfo);
5889     Vector2D<double> logical = physical;
5890     if (GetHardCursorEnabled()) {
5891         auto screenRect = RotateRect<double>(direction, {displayInfo.width, displayInfo.height});
5892         auto transforms = RotateAndFitScreen(direction, screenRect);
5893         logical = MMI::ApplyTransformSteps(transforms, physical);
5894     }
5895     layout.x = logical.x + displayInfo.x;
5896     layout.y = logical.y + displayInfo.y;
5897 
5898     MMI_HILOGD("calculated layout point, id:%{public}d, d:%{public}d, dd:%{public}d, ddd:%{public}d, "
5899         "dx:%{private}d, dy:%{private}d, px:%{private}f, py:%{private}f, "
5900         "lx:%{private}f, ly:%{private}f, lax:%{private}f, lay:%{private}f ",
5901         displayInfo.id, direction, displayInfo.direction, displayInfo.displayDirection,
5902         displayInfo.x, displayInfo.y, physical.x, physical.y,
5903         logical.x, logical.y, layout.x, layout.y);
5904     return true;
5905 }
5906 
5907 AcrossDirection InputWindowsManager::CalculateAcrossDirection(const OLD::DisplayInfo &displayInfo,
5908     const Vector2D<double> &layout)
5909 {
5910     Vector2D<int32_t> layoutMax;
5911 
5912     if (!AddInt32(displayInfo.x, displayInfo.validWidth, layoutMax.x)) {
5913         MMI_HILOGE("The addition of layoutMax.x overflows");
5914         return AcrossDirection::ACROSS_ERROR;
5915     }
5916     if (!AddInt32(displayInfo.y, displayInfo.validHeight, layoutMax.y)) {
5917         MMI_HILOGE("The addition of layoutMax.y overflows");
5918         return AcrossDirection::ACROSS_ERROR;
5919     }
5920 
5921     if (layout.x < displayInfo.x) {
5922         return AcrossDirection::LEFTWARDS;
5923     } else if (layout.x >= layoutMax.x) {
5924         return AcrossDirection::RIGHTWARDS;
5925     }
5926     if (layout.y < displayInfo.y) {
5927         return AcrossDirection::UPWARDS;
5928     } else if (layout.y >= layoutMax.y) {
5929         return AcrossDirection::DOWNWARDS;
5930     }
5931 
5932     return AcrossDirection::ACROSS_ERROR;
5933 }
5934 
5935 bool InputWindowsManager::AcrossDisplay(const OLD::DisplayInfo &displayInfoDes, const OLD::DisplayInfo &displayInfoOri,
5936     Vector2D<double> &logical, Vector2D<double> &layout, const AcrossDirection &acrossDirection)
5937 {
5938     Vector2D<int32_t> layoutMax;
5939     double layoutX, layoutY;
5940     int32_t pointerWidth = 0, pointerHeight = 0;
5941     bool re = false;
5942     layoutX = layout.x;
5943     layoutY = layout.y;
5944     CursorDrawingComponent::GetInstance().GetPointerImageSize(pointerWidth, pointerHeight);
5945     if (!AddInt32(displayInfoDes.x, displayInfoDes.validWidth, layoutMax.x)) {
5946         MMI_HILOGE("The addition of layoutMax.x overflows");
5947         return false;
5948     }
5949     if (!AddInt32(displayInfoDes.y, displayInfoDes.validHeight, layoutMax.y)) {
5950         MMI_HILOGE("The addition of layoutMax.y overflows");
5951         return false;
5952     }
5953 
5954     re |= (acrossDirection == RIGHTWARDS && displayInfoDes.x == displayInfoOri.x + displayInfoOri.validWidth);
5955     re |= (acrossDirection == LEFTWARDS && displayInfoDes.x + displayInfoDes.validWidth == displayInfoOri.x);
5956     re |= (acrossDirection == DOWNWARDS && displayInfoDes.y == displayInfoOri.y + displayInfoOri.validHeight);
5957     re |= (acrossDirection == UPWARDS && displayInfoDes.y + displayInfoDes.validHeight == displayInfoOri.y);
5958     if (!re) {
5959         MMI_HILOGI("the display is not in across direction.");
5960         return re;
5961     }
5962 
5963     if (layout.x < displayInfoDes.x) {
5964         layoutX = displayInfoDes.x;
5965     } else if (layout.x >= layoutMax.x) {
5966         layoutX = layoutMax.x - pointerWidth;
5967     }
5968     if (layout.y < displayInfoDes.y) {
5969         layoutY = displayInfoDes.y;
5970     } else if (layout.y >= layoutMax.y) {
5971         layoutY = layoutMax.y - pointerHeight;
5972     }
5973     logical = { layoutX - displayInfoDes.x, layoutY - displayInfoDes.y };
5974     return re;
5975 }
5976 
5977 void InputWindowsManager::FindPhysicalDisplay(const OLD::DisplayInfo& displayInfo, double& physicalX,
5978     double& physicalY, int32_t& displayId)
5979 {
5980     CALL_DEBUG_ENTER;
5981     Vector2D<double> physical = { physicalX, physicalY };
5982     Vector2D<double> logical = physical;
5983     Vector2D<double> layout = { 0, 0 };
5984     AcrossDirection acrossDirection;
5985     if (!CalculateLayout(displayInfo, physical, layout)) {
5986         return;
5987     }
5988     int32_t groupId = FindDisplayGroupId(displayId);
5989     auto &displaysInfoVector = GetDisplayInfoVector(groupId);
5990     for (const auto &item : displaysInfoVector) {
5991         if (item.id == displayInfo.id) {
5992             continue;
5993         }
5994         acrossDirection = CalculateAcrossDirection(displayInfo, layout);
5995         MMI_HILOGI("acrossDirection :%{public}d, current displayId:%{public}d, target displayId:%{public}d",
5996             acrossDirection, displayInfo.id, item.id);
5997         if (acrossDirection == AcrossDirection::ACROSS_ERROR) {
5998             return;
5999         }
6000         if (!AcrossDisplay(item, displayInfo, logical, layout, acrossDirection)) {
6001             continue;
6002         }
6003         physical = logical;
6004         Direction direction = GetDisplayDirection(&item);
6005         if (GetHardCursorEnabled()) {
6006             auto screenRect = RotateRect<double>(direction, { item.width, item.height });
6007             auto transforms = RotateAndFitScreen(direction, screenRect);
6008             physical = ResetTransformSteps(transforms, logical);
6009         }
6010         physicalX = physical.x;
6011         physicalY = physical.y;
6012         displayId = item.id;
6013         MMI_HILOGD("switched into display, id:%{public}d, d:%{public}d, dd:%{public}d, ddd:%{public}d, "
6014             "dx:%{private}d, dy:%{private}d, dw:%{private}d, dh:%{private}d, "
6015             "lx:%{private}f, ly:%{private}f, px:%{private}f, py:%{private}f",
6016             displayId, direction, item.direction, item.displayDirection,
6017             item.x, item.y, item.width, item.height,
6018             logical.x, logical.y, physicalX, physicalY);
6019         break;
6020     }
6021 }
6022 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
6023 
6024 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
6025 void InputWindowsManager::CoordinateCorrection(int32_t width, int32_t height, int32_t &integerX, int32_t &integerY)
6026 {
6027     if (integerX < 0) {
6028         integerX = 0;
6029     }
6030     if (integerX >= width) {
6031         integerX = width - 1;
6032     }
6033     if (integerY < 0) {
6034         integerY = 0;
6035     }
6036     if (integerY >= height) {
6037         integerY = height - 1;
6038     }
6039 }
6040 
6041 Direction InputWindowsManager::GetDisplayDirection(const OLD::DisplayInfo *displayInfo)
6042 {
6043     CHKPR(displayInfo, DIRECTION0);
6044     Direction displayDirection = static_cast<Direction>((
6045         ((displayInfo->direction - displayInfo->displayDirection) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90);
6046     if (GetHardCursorEnabled()) {
6047         if (TOUCH_DRAWING_MGR->IsWindowRotation()) {
6048             displayDirection = static_cast<Direction>((((displayInfo->direction - displayInfo->displayDirection) *
6049                 ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90);
6050         } else {
6051             displayDirection = displayInfo->direction;
6052         }
6053     }
6054     if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
6055         displayDirection = displayInfo->direction;
6056     }
6057     return displayDirection;
6058 }
6059 
6060 void InputWindowsManager::GetWidthAndHeight(const OLD::DisplayInfo* displayInfo, int32_t &width, int32_t &height,
6061     bool isRealData)
6062 {
6063     auto displayDirection = GetDisplayDirection(displayInfo);
6064     if (displayDirection == DIRECTION0 || displayDirection == DIRECTION180) {
6065         width = displayInfo->validWidth;
6066         height = displayInfo->validHeight;
6067     } else {
6068         if (!isRealData) {
6069             width = displayInfo->validWidth;
6070             height = displayInfo->validHeight;
6071             return;
6072         }
6073         height = displayInfo->validWidth;
6074         width = displayInfo->validHeight;
6075     }
6076 }
6077 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
6078 
6079 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
6080 void InputWindowsManager::ReverseRotateScreen(const OLD::DisplayInfo& info, const double x, const double y,
6081     Coordinate2D& cursorPos) const
6082 {
6083     const Direction direction = info.direction;
6084     MMI_HILOGD("X:%{private}.2f, Y:%{private}.2f, offsetXY={%{private}d %{private}d},"
6085         "info.WH:{%{private}d %{private}d} info.validWH:{%{private}d %{private}d}",
6086         x,
6087         y,
6088         info.offsetX,
6089         info.offsetY,
6090         info.width,
6091         info.height,
6092         info.validWidth,
6093         info.validHeight);
6094     switch (direction) {
6095         case DIRECTION0: {
6096             cursorPos.x = x;
6097             cursorPos.y = y;
6098             MMI_HILOGD("DIRECTION0, physicalX:%{private}.2f, physicalY:%{private}.2f", cursorPos.x, cursorPos.y);
6099             break;
6100         }
6101         case DIRECTION90: {
6102             cursorPos.y = static_cast<double>(info.validWidth) - 1 - x;
6103             cursorPos.x = y;
6104             MMI_HILOGD("DIRECTION90, physicalX:%{private}.2f, physicalY:%{private}.2f", cursorPos.x, cursorPos.y);
6105             break;
6106         }
6107         case DIRECTION180: {
6108             cursorPos.x = static_cast<double>(info.validWidth) - 1 - x;
6109             cursorPos.y = static_cast<double>(info.validHeight) - 1 - y;
6110             MMI_HILOGD("DIRECTION180, physicalX:%{private}.2f, physicalY:%{private}.2f", cursorPos.x, cursorPos.y);
6111             break;
6112         }
6113         case DIRECTION270: {
6114             cursorPos.x = static_cast<double>(info.validHeight) - 1 - y;
6115             cursorPos.y = x;
6116             MMI_HILOGD("DIRECTION270, physicalX:%{private}.2f, physicalY:%{private}.2f", cursorPos.x, cursorPos.y);
6117             break;
6118         }
6119         default: {
6120             MMI_HILOGE("direction is invalid, direction:%{private}d", direction);
6121             break;
6122         }
6123     }
6124 }
6125 
6126 void InputWindowsManager::ReverseRotateDisplayScreen(const OLD::DisplayInfo& info, const double x, const double y,
6127     Coordinate2D& cursorPos) const
6128 {
6129     Direction displayDirection = WIN_MGR->GetDisplayDirection(&info);
6130     MMI_HILOGD(
6131         "X:%{private}.2f, Y:%{private}.2f, info.WH:{%{private}d %{private}d}, info.validWH:{%{private}d %{private}d}",
6132         x,
6133         y,
6134         info.width,
6135         info.height,
6136         info.validWidth,
6137         info.validHeight);
6138     switch (displayDirection) {
6139         case DIRECTION0: {
6140             cursorPos.x = x;
6141             cursorPos.y = y;
6142             MMI_HILOGD("DIRECTION0, physicalX:%{private}.2f, physicalY:%{private}.2f", cursorPos.x, cursorPos.y);
6143             break;
6144         }
6145         case DIRECTION90: {
6146             cursorPos.y = static_cast<double>(info.validWidth) - 1 - x;
6147             cursorPos.x = y;
6148             MMI_HILOGD("DIRECTION90, physicalX:%{private}.2f, physicalY:%{private}.2f", cursorPos.x, cursorPos.y);
6149             break;
6150         }
6151         case DIRECTION180: {
6152             cursorPos.x = static_cast<double>(info.validWidth) - 1 - x;
6153             cursorPos.y = static_cast<double>(info.validHeight) - 1 - y;
6154             MMI_HILOGD("DIRECTION180, physicalX:%{private}.2f, physicalY:%{private}.2f", cursorPos.x, cursorPos.y);
6155             break;
6156         }
6157         case DIRECTION270: {
6158             cursorPos.x = static_cast<double>(info.validHeight) - 1 - y;
6159             cursorPos.y = x;
6160             MMI_HILOGD("DIRECTION270, physicalX:%{private}.2f, physicalY:%{private}.2f", cursorPos.x, cursorPos.y);
6161             break;
6162         }
6163         default: {
6164             MMI_HILOGE("displayDirection is invalid, displayDirection:%{private}d", displayDirection);
6165             break;
6166         }
6167     }
6168 }
6169 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
6170 
6171 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
6172 void InputWindowsManager::UpdateAndAdjustMouseLocation(int32_t& displayId, double& x, double& y, bool isRealData)
6173 {
6174     int32_t groupId = FindDisplayGroupId(displayId);
6175     auto displayInfo = GetPhysicalDisplay(displayId);
6176     CHKPV(displayInfo);
6177     double oldX = x;
6178     double oldY = y;
6179     int32_t lastDisplayId = displayId;
6180     if (!IsInsideDisplay(*displayInfo, x, y)) {
6181         FindPhysicalDisplay(*displayInfo, x, y, displayId);
6182         MMI_HILOGI("Not IsInsideDisplay, cursorXY:{%{private}f, %{private}f}->{%{private}f, %{private}f}",
6183             oldX, oldY, x, y);
6184     }
6185     if (displayId != lastDisplayId) {
6186         displayInfo = GetPhysicalDisplay(displayId);
6187         CHKPV(displayInfo);
6188     }
6189     int32_t width = 0;
6190     int32_t height = 0;
6191     GetWidthAndHeight(displayInfo, width, height, isRealData);
6192     int32_t integerX = static_cast<int32_t>(x);
6193     int32_t integerY = static_cast<int32_t>(y);
6194 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
6195     if (IsPointerActiveRectValid(*displayInfo)) {
6196         width = displayInfo->pointerActiveWidth;
6197         height = displayInfo->pointerActiveHeight;
6198         MMI_HILOGD("vtp cursor active area w:%{private}d, h:%{private}d", width, height);
6199     }
6200 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
6201     CoordinateCorrection(width, height, integerX, integerY);
6202     x = static_cast<double>(integerX) + (x - floor(x));
6203     y = static_cast<double>(integerY) + (y - floor(y));
6204     const auto iter = mouseLocationMap_.find(groupId);
6205     if (iter != mouseLocationMap_.end()) {
6206         mouseLocationMap_[groupId].displayId = displayId;
6207     }
6208     const auto it = cursorPosMap_.find(groupId);
6209     if (it != cursorPosMap_.end()) {
6210         cursorPosMap_[groupId].displayId = displayId;
6211     }
6212     if (isRealData) {
6213         PhysicalCoordinate coord {
6214             .x = integerX,
6215             .y = integerY,
6216         };
6217         RotateDisplayScreen(*displayInfo, coord);
6218         const auto iter = mouseLocationMap_.find(groupId);
6219         if (iter != mouseLocationMap_.end()) {
6220             mouseLocationMap_[groupId].physicalX = coord.x;
6221             mouseLocationMap_[groupId].physicalY = coord.y;
6222         }
6223         const auto it = cursorPosMap_.find(groupId);
6224         if (it != cursorPosMap_.end()) {
6225             cursorPosMap_[groupId].cursorPos.x = x;
6226             cursorPosMap_[groupId].cursorPos.y = y;
6227         }
6228     } else {
6229         const auto iter = mouseLocationMap_.find(groupId);
6230         if (iter != mouseLocationMap_.end()) {
6231             mouseLocationMap_[groupId].physicalX = integerX;
6232             mouseLocationMap_[groupId].physicalY = integerY;
6233         }
6234         CursorPosition cursorPosCur = {};
6235 
6236         const auto it = cursorPosMap_.find(groupId);
6237         if (it != cursorPosMap_.end()) {
6238             cursorPosCur = it->second;
6239         }
6240         ReverseRotateDisplayScreen(*displayInfo, x, y, cursorPosCur.cursorPos);
6241         cursorPosMap_[groupId] = cursorPosCur;
6242     }
6243     MouseLocation mouseLocationTmp;
6244     double physicalX = 0.0;
6245     double physicalY = 0.0;
6246     const auto& locationMap = mouseLocationMap_.find(groupId);
6247     if (locationMap != mouseLocationMap_.end()) {
6248         mouseLocationTmp = locationMap->second;
6249     }
6250     const auto& posMap = cursorPosMap_.find(groupId);
6251     if (posMap != cursorPosMap_.end()) {
6252         physicalX = posMap->second.cursorPos.x;
6253         physicalY = posMap->second.cursorPos.y;
6254     }
6255     MMI_HILOGD("Mouse Data: isRealData=%{public}d, displayId:%{public}d, mousePhysicalXY={%{private}d, %{private}d}, "
6256         "cursorPosXY: {%{private}.2f, %{private}.2f} -> {%{private}.2f %{private}.2f}",
6257         static_cast<int32_t>(isRealData), displayId, mouseLocationTmp.physicalX,
6258         mouseLocationTmp.physicalY, oldX, oldY, physicalX, physicalY);
6259 }
6260 
6261 MouseLocation InputWindowsManager::GetMouseInfo()
6262 {
6263     auto &displaysInfoVector = GetDisplayInfoVector(MAIN_GROUPID);
6264     MouseLocation curMouseLocation;
6265     const auto iter = mouseLocationMap_.find(MAIN_GROUPID);
6266     if (iter != mouseLocationMap_.end()) {
6267         curMouseLocation = iter->second;
6268     }
6269     MMI_HILOGD("Mouselocation start: displayId:%{public}d, X:%{private}d, Y:%{private}d",
6270         curMouseLocation.displayId, curMouseLocation.physicalX, curMouseLocation.physicalY);
6271     if ((curMouseLocation.displayId < 0) && !displaysInfoVector.empty()) {
6272         OLD::DisplayInfo displayInfo = displaysInfoVector[0];
6273         if (GetHardCursorEnabled()) {
6274             (void)GetMainScreenDisplayInfo(displaysInfoVector, displayInfo);
6275         }
6276         const auto iter = mouseLocationMap_.find(MAIN_GROUPID);
6277         if (iter != mouseLocationMap_.end()) {
6278             mouseLocationMap_[MAIN_GROUPID].displayId = displayInfo.id;
6279             mouseLocationMap_[MAIN_GROUPID].physicalX = displayInfo.validWidth / TWOFOLD;
6280             mouseLocationMap_[MAIN_GROUPID].physicalY = displayInfo.validHeight / TWOFOLD;
6281             curMouseLocation = iter->second;
6282         }
6283         MMI_HILOGD("Mouselocation displayinfo: displayId:%{public}d, W:%{public}d, H:%{public}d",
6284             displayInfo.id, displayInfo.validWidth, displayInfo.validHeight);
6285         return curMouseLocation;
6286     }
6287     MMI_HILOGD("Mouselocation next: displayId:%{public}d, X:%{private}d, Y:%{private}d",
6288         curMouseLocation.displayId, curMouseLocation.physicalX, curMouseLocation.physicalY);
6289     return curMouseLocation;
6290 }
6291 
6292 CursorPosition InputWindowsManager::GetCursorPos()
6293 {
6294     CALL_DEBUG_ENTER;
6295     auto &displaysInfoVector = GetDisplayInfoVector(MAIN_GROUPID);
6296     CursorPosition cursorPos;
6297     const auto iter = cursorPosMap_.find(MAIN_GROUPID);
6298     if (iter != cursorPosMap_.end()) {
6299         cursorPos = iter->second;
6300     }
6301     if ((cursorPos.displayId < 0) && !displaysInfoVector.empty()) {
6302         OLD::DisplayInfo displayInfo = displaysInfoVector[0];
6303         if (GetHardCursorEnabled()) {
6304             (void)GetMainScreenDisplayInfo(displaysInfoVector, displayInfo);
6305         }
6306         const auto iter = cursorPosMap_.find(MAIN_GROUPID);
6307         if (iter != cursorPosMap_.end()) {
6308             cursorPosMap_[MAIN_GROUPID].displayId = displayInfo.id;
6309             cursorPosMap_[MAIN_GROUPID].cursorPos.x = displayInfo.validWidth * HALF_RATIO;
6310             cursorPosMap_[MAIN_GROUPID].cursorPos.y = displayInfo.validHeight * HALF_RATIO;
6311         }
6312     }
6313     return cursorPos;
6314 }
6315 
6316 CursorPosition InputWindowsManager::ResetCursorPos()
6317 {
6318     CALL_DEBUG_ENTER;
6319     auto &displaysInfoVector = GetDisplayInfoVector(MAIN_GROUPID);
6320     if (!displaysInfoVector.empty()) {
6321         OLD::DisplayInfo displayInfo = displaysInfoVector[0];
6322         int32_t x = displayInfo.validWidth * HALF_RATIO;
6323         int32_t y = displayInfo.validHeight * HALF_RATIO;
6324         if (GetHardCursorEnabled()) {
6325             (void)GetMainScreenDisplayInfo(displaysInfoVector, displayInfo);
6326             x = displayInfo.validWidth * HALF_RATIO;
6327             y = displayInfo.validHeight * HALF_RATIO;
6328             Direction displayDirection = GetDisplayDirection(&displayInfo);
6329             if (displayDirection == DIRECTION90 || displayDirection == DIRECTION270) {
6330                 std::swap(x, y);
6331             }
6332         }
6333         const auto iter = cursorPosMap_.find(MAIN_GROUPID);
6334         if (iter != cursorPosMap_.end()) {
6335             cursorPosMap_[MAIN_GROUPID].displayId = displayInfo.id;
6336             cursorPosMap_[MAIN_GROUPID].cursorPos.x = x;
6337             cursorPosMap_[MAIN_GROUPID].cursorPos.y = y;
6338         }
6339     } else {
6340         const auto iter = cursorPosMap_.find(MAIN_GROUPID);
6341         if (iter != cursorPosMap_.end()) {
6342             cursorPosMap_[MAIN_GROUPID].displayId = -1;
6343             cursorPosMap_[MAIN_GROUPID].cursorPos.x = 0;
6344             cursorPosMap_[MAIN_GROUPID].cursorPos.y = 0;
6345         }
6346     }
6347     CursorPosition cursorPos;
6348     const auto iter = cursorPosMap_.find(MAIN_GROUPID);
6349     if (iter != cursorPosMap_.end()) {
6350         cursorPos = iter->second;
6351     }
6352     MMI_HILOGI("ResetCursorPos cursorPosMap_[mainGroupId].displayId:%{public}d",
6353         cursorPos.displayId);
6354     return cursorPos;
6355 }
6356 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
6357 
6358 int32_t InputWindowsManager::AppendExtraData(const ExtraData& extraData)
6359 {
6360     CALL_DEBUG_ENTER;
6361     extraData_.appended = extraData.appended;
6362     extraData_.buffer = extraData.buffer;
6363     extraData_.sourceType = extraData.sourceType;
6364     extraData_.pointerId = extraData.pointerId;
6365     extraData_.pullId = extraData.pullId;
6366     extraData_.eventId = extraData.eventId;
6367     extraData_.drawCursor = extraData.drawCursor;
6368     if ((extraData_.eventId > 0) && (extraData.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) &&
6369         (mouseDownEventId_ < 0 || extraData.eventId < mouseDownEventId_)) {
6370         MMI_HILOGE("Mouse drag failed, PI:%{public}d, EI:%{public}d, DEI:%{public}d",
6371             extraData.pointerId, extraData.eventId, mouseDownEventId_);
6372         ClearExtraData();
6373         return RET_ERR;
6374     }
6375     return RET_OK;
6376 }
6377 
6378 void InputWindowsManager::ClearExtraData()
6379 {
6380     CALL_DEBUG_ENTER;
6381     extraData_.appended = false;
6382     extraData_.buffer.clear();
6383     extraData_.sourceType = -1;
6384     extraData_.pointerId = -1;
6385     extraData_.pullId = -1;
6386     extraData_.eventId = -1;
6387     extraData_.drawCursor = false;
6388 }
6389 
6390 ExtraData InputWindowsManager::GetExtraData() const
6391 {
6392     CALL_DEBUG_ENTER;
6393     return extraData_;
6394 }
6395 
6396 bool InputWindowsManager::IsWindowVisible(int32_t pid)
6397 {
6398     CALL_DEBUG_ENTER;
6399     if (pid < 0) {
6400         MMI_HILOGE("pid is invalid");
6401         return true;
6402     }
6403     std::vector<sptr<Rosen::WindowVisibilityInfo>> infos;
6404     BytraceAdapter::StartWindowVisible(pid);
6405     Rosen::WindowManagerLite::GetInstance().GetVisibilityWindowInfo(infos);
6406     BytraceAdapter::StopWindowVisible();
6407     for (const auto &it: infos) {
6408         CHKPC(it);
6409         if (pid == it->pid_ &&
6410             it->visibilityState_ < Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION) {
6411             MMI_HILOGD("pid:%{public}d has visible window", pid);
6412             return true;
6413         }
6414     }
6415     MMI_HILOGD("pid:%{public}d doesn't have visible window", pid);
6416     return false;
6417 }
6418 
6419 void InputWindowsManager::UpdatePointerAction(std::shared_ptr<PointerEvent> pointerEvent)
6420 {
6421     CALL_DEBUG_ENTER;
6422     int32_t action = pointerEvent->GetPointerAction();
6423     switch (action) {
6424         case PointerEvent::POINTER_ACTION_MOVE: {
6425             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_MOVE);
6426             break;
6427         }
6428         case PointerEvent::POINTER_ACTION_BUTTON_UP:
6429         case PointerEvent::POINTER_ACTION_UP: {
6430             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_UP);
6431             break;
6432         }
6433         case PointerEvent::POINTER_ACTION_ENTER_WINDOW: {
6434             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_IN_WINDOW);
6435             break;
6436         }
6437         case PointerEvent::POINTER_ACTION_LEAVE_WINDOW: {
6438             pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW);
6439             break;
6440         }
6441         default: {
6442             MMI_HILOG_DISPATCHI("Action is:%{public}d, no need change", action);
6443             break;
6444         }
6445     }
6446     MMI_HILOG_DISPATCHD("pointerAction:%{public}s", pointerEvent->DumpPointerAction());
6447 }
6448 
6449 void InputWindowsManager::DumpDisplayInfo(int32_t fd, const std::vector<OLD::DisplayInfo>& displaysInfo)
6450 {
6451     mprintf(fd, "Displays information:\t");
6452     mprintf(fd, "displayInfos,num:%zu", displaysInfo.size());
6453     for (const auto &item : displaysInfo) {
6454         mprintf(fd, "\t displayInfos: rsId:%" PRIu64 " | displaySourceMode:%d id:%d | x:%d"
6455                     "| y:%d | width:%d | height:%d | name:%s | uniq:%s | direction:%d"
6456                     "| displayDirection:%d | displayMode:%u | offsetX:%d | offsetY:%d"
6457                     "| validWidth:%d | validHeight:%d | pointerActiveWidth:%d | pointerActiveHeight:%d\t",
6458                     item.rsId, item.displaySourceMode, item.id, item.x, item.y, item.width,
6459                     item.height, item.name.c_str(), item.uniq.c_str(), item.direction,
6460                     item.displayDirection, item.displayMode, item.offsetX, item.offsetY,
6461                     item.validWidth, item.validHeight, item.pointerActiveWidth, item.pointerActiveHeight);
6462         if (item.transform.size() == MATRIX3_SIZE) {
6463             mprintf(fd, "\t transform: scaleX:%f | scaleY:%f | anchorPointX:%f | anchorPointY:%f \t",
6464                 item.transform[SCALE_X], item.transform[SCALE_Y], item.transform[ANCHOR_POINT_X],
6465                 item.transform[ANCHOR_POINT_Y]);
6466         }
6467     }
6468 }
6469 
6470 void InputWindowsManager::Dump(int32_t fd, const std::vector<std::string> &args)
6471 {
6472     CALL_DEBUG_ENTER;
6473     std::shared_ptr<DelegateInterface> delegateProxy =
6474         CursorDrawingComponent::GetInstance().GetDelegateProxy();
6475     CHKPV(delegateProxy);
6476     std::vector<OLD::DisplayInfo> displaysInfo;
6477     std::vector<WindowInfo> windowsInfo;
6478     delegateProxy->OnPostSyncTask([this, &displaysInfo, &windowsInfo] {
6479         const auto& iter = displayGroupInfoMap_.find(MAIN_GROUPID);
6480         if (iter != displayGroupInfoMap_.end()) {
6481             displaysInfo = iter->second.displaysInfo;
6482             windowsInfo = iter->second.windowsInfo;
6483             return RET_OK;
6484         }
6485         displaysInfo = displayGroupInfo_.displaysInfo;
6486         windowsInfo = displayGroupInfo_.windowsInfo;
6487         return RET_OK;
6488     });
6489     mprintf(fd, "Windows information:\t");
6490     mprintf(fd, "windowsInfos,num:%zu", windowsInfo.size());
6491     for (const auto &item : windowsInfo) {
6492         mprintf(fd, "  windowsInfos: id:%d | pid:%d | uid:%d | area.x:%d | area.y:%d "
6493             "| area.width:%d | area.height:%d | defaultHotAreas.size:%zu "
6494             "| pointerHotAreas.size:%zu | agentWindowId:%d | flags:%u "
6495             "| action:%d | displayId:%d | zOrder:%f | Privacy:%d | Type:%d \t",
6496             item.id, item.pid, item.uid, item.area.x, item.area.y, item.area.width,
6497             item.area.height, item.defaultHotAreas.size(), item.pointerHotAreas.size(),
6498             item.agentWindowId, item.flags, item.action, item.displayId, item.zOrder,
6499             item.isSkipSelfWhenShowOnVirtualScreen, static_cast<int32_t>(item.windowInputType));
6500         for (const auto &win : item.defaultHotAreas) {
6501             mprintf(fd, "\t defaultHotAreas: x:%d | y:%d | width:%d | height:%d \t",
6502                 win.x, win.y, win.width, win.height);
6503         }
6504         for (const auto &pointer : item.pointerHotAreas) {
6505             mprintf(fd, "\t pointerHotAreas: x:%d | y:%d | width:%d | height:%d \t",
6506                 pointer.x, pointer.y, pointer.width, pointer.height);
6507         }
6508 
6509         std::string dump;
6510         dump += StringPrintf("\t pointerChangeAreas: ");
6511         for (const auto &it : item.pointerChangeAreas) {
6512             dump += StringPrintf("%d | ", it);
6513         }
6514         dump += StringPrintf("\n\t transform: ");
6515         for (const auto &it : item.transform) {
6516             dump += StringPrintf("%f | ", it);
6517         }
6518         std::istringstream stream(dump);
6519         std::string line;
6520         while (std::getline(stream, line, '\n')) {
6521             mprintf(fd, "%s", line.c_str());
6522         }
6523     }
6524     DumpDisplayInfo(fd, displaysInfo);
6525     mprintf(fd, "Input device and display bind info:\n%s", bindInfo_.Dumps().c_str());
6526 #ifdef OHOS_BUILD_ENABLE_ANCO
6527     std::string ancoWindows;
6528     DumpAncoWindows(ancoWindows);
6529     mprintf(fd, "%s\n", ancoWindows.c_str());
6530 #endif // OHOS_BUILD_ENABLE_ANCO
6531 }
6532 
6533 std::pair<double, double> InputWindowsManager::TransformWindowXY(const WindowInfo &window,
6534     double logicX, double logicY) const
6535 {
6536     UpdateCurrentDisplay(window.displayId);
6537     double currX = logicX - currentDisplayXY_.first;
6538     double currY = logicY - currentDisplayXY_.second;
6539     Matrix3f transform(window.transform);
6540     if (window.transform.size() != MATRIX3_SIZE || transform.IsIdentity()) {
6541         return {currX, currY};
6542     }
6543     Vector3f logicXY(currX, currY, 1.0);
6544     Vector3f windowXY = transform * logicXY;
6545     return { windowXY[0], windowXY[1] };
6546 }
6547 
6548 std::pair<double, double> InputWindowsManager::TransformDisplayXY(const OLD::DisplayInfo &info,
6549     double logicX, double logicY) const
6550 {
6551     Matrix3f transform(info.transform);
6552     if (info.transform.size() != MATRIX3_SIZE || transform.IsIdentity()) {
6553         return {logicX, logicY};
6554     }
6555     Vector3f logicXY(logicX, logicY, 1.0);
6556     Vector3f displayXY = transform * logicXY;
6557     return {round(displayXY[0]), round(displayXY[1])};
6558 }
6559 
6560 bool InputWindowsManager::IsValidZorderWindow(const WindowInfo &window,
6561     const std::shared_ptr<PointerEvent>& pointerEvent)
6562 {
6563     CHKPF(pointerEvent);
6564     if (!(pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE)) || MMI_LE(pointerEvent->GetZOrder(), 0.0f)) {
6565         return true;
6566     }
6567     if (MMI_GE(window.zOrder, pointerEvent->GetZOrder())) {
6568         MMI_HILOGE("Current window zorder:%{public}f greater than the simulate target zOrder:%{public}f, "
6569             "ignore this window::%{public}d", window.zOrder, pointerEvent->GetZOrder(), window.id);
6570         return false;
6571     }
6572     return true;
6573 }
6574 
6575 bool InputWindowsManager::HandleWindowInputType(const WindowInfo &window, std::shared_ptr<PointerEvent> pointerEvent)
6576 {
6577     CALL_DEBUG_ENTER;
6578     int32_t pointerId = pointerEvent->GetPointerId();
6579     PointerEvent::PointerItem item;
6580     if (!pointerEvent->GetPointerItem(pointerId, item)) {
6581         MMI_HILOG_WINDOWE("Invalid pointer:%{public}d", pointerId);
6582         return false;
6583     }
6584     int32_t sourceType = pointerEvent->GetSourceType();
6585     WindowInputType windowTypeTemp = window.windowInputType;
6586     if (sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
6587         GetActiveWindowTypeById(window.id, windowTypeTemp);
6588     }
6589     switch (windowTypeTemp)
6590     {
6591         case WindowInputType::NORMAL:
6592             return false;
6593         case WindowInputType::TRANSMIT_ALL:
6594             return true;
6595         case WindowInputType::DUALTRIGGER_TOUCH:
6596             return true;
6597         case WindowInputType::TRANSMIT_EXCEPT_MOVE: {
6598             auto pointerAction = pointerEvent->GetPointerAction();
6599             return (pointerAction == PointerEvent::POINTER_ACTION_MOVE ||
6600                 pointerAction == PointerEvent::POINTER_ACTION_PULL_MOVE);
6601         }
6602         case WindowInputType::ANTI_MISTAKE_TOUCH:
6603             return false;
6604         case WindowInputType::TRANSMIT_AXIS_MOVE:
6605             return false;
6606         case WindowInputType::TRANSMIT_MOUSE_MOVE:
6607             return false;
6608         case WindowInputType::TRANSMIT_LEFT_RIGHT:
6609             return false;
6610         case WindowInputType::TRANSMIT_BUTTOM:
6611             return false;
6612         case WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE:
6613             return false;
6614         case WindowInputType::MIX_BUTTOM_ANTI_AXIS_MOVE:
6615             return false;
6616         default:
6617             return false;
6618     }
6619 }
6620 
6621 std::optional<WindowInfo> InputWindowsManager::GetWindowAndDisplayInfo(int32_t windowId, int32_t displayId)
6622 {
6623     CALL_DEBUG_ENTER;
6624     const std::vector<WindowInfo> &windowInfos = GetWindowGroupInfoByDisplayId(displayId);
6625     for (const auto &item : windowInfos) {
6626         if (windowId == item.id) {
6627             return std::make_optional(item);
6628         }
6629         for (const auto &uiExtentionWindow : item.uiExtentionWindowInfo) {
6630             if (windowId == uiExtentionWindow.id) {
6631                 return std::make_optional(uiExtentionWindow);
6632             }
6633         }
6634     }
6635     return std::nullopt;
6636 }
6637 
6638 void InputWindowsManager::GetTargetWindowIds(int32_t pointerItemId, int32_t sourceType,
6639     std::vector<int32_t> &windowIds)
6640 {
6641     CALL_DEBUG_ENTER;
6642     if (sourceType == PointerEvent::SOURCE_TYPE_MOUSE) {
6643         if (targetMouseWinIds_.find(pointerItemId) != targetMouseWinIds_.end()) {
6644             windowIds = targetMouseWinIds_[pointerItemId];
6645         }
6646         return;
6647     } else if (sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
6648         if (targetTouchWinIds_.find(pointerItemId) != targetTouchWinIds_.end()) {
6649             windowIds = targetTouchWinIds_[pointerItemId];
6650         }
6651     }
6652 }
6653 
6654 void InputWindowsManager::AddTargetWindowIds(int32_t pointerItemId, int32_t sourceType, int32_t windowId)
6655 {
6656     CALL_DEBUG_ENTER;
6657     if (sourceType == PointerEvent::SOURCE_TYPE_MOUSE) {
6658         if (targetMouseWinIds_.find(pointerItemId) != targetMouseWinIds_.end()) {
6659             targetMouseWinIds_[pointerItemId].push_back(windowId);
6660         } else {
6661             std::vector<int32_t> windowIds;
6662             windowIds.push_back(windowId);
6663             targetMouseWinIds_.emplace(pointerItemId, windowIds);
6664         }
6665         return;
6666     } else if (sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
6667         if (targetTouchWinIds_.find(pointerItemId) != targetTouchWinIds_.end()) {
6668             targetTouchWinIds_[pointerItemId].push_back(windowId);
6669         } else {
6670             std::vector<int32_t> windowIds;
6671             windowIds.push_back(windowId);
6672             targetTouchWinIds_.emplace(pointerItemId, windowIds);
6673         }
6674     }
6675 }
6676 
6677 void InputWindowsManager::ClearTargetWindowId(int32_t pointerId)
6678 {
6679     CALL_DEBUG_ENTER;
6680     if (targetTouchWinIds_.find(pointerId) == targetTouchWinIds_.end()) {
6681         MMI_HILOGD("Clear target windowId fail, pointerId:%{public}d", pointerId);
6682         return;
6683     }
6684     targetTouchWinIds_.erase(pointerId);
6685 }
6686 
6687 void InputWindowsManager::SetPrivacyModeFlag(SecureFlag privacyMode, std::shared_ptr<InputEvent> event)
6688 {
6689     if (privacyMode == SecureFlag::PRIVACY_MODE) {
6690         MMI_HILOGD("Window security mode is privacy");
6691         event->AddFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE);
6692     } else {
6693         event->ClearFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE);
6694     }
6695 }
6696 
6697 int32_t InputWindowsManager::CheckWindowIdPermissionByPid(int32_t windowId, int32_t pid)
6698 {
6699     CALL_DEBUG_ENTER;
6700     int32_t checkingPid = GetWindowPid(windowId);
6701     if (checkingPid != pid) {
6702         MMI_HILOGE("check windowId failed, windowId is %{public}d, pid is %{public}d", windowId, pid);
6703         return RET_ERR;
6704     }
6705     return RET_OK;
6706 }
6707 
6708 #ifdef OHOS_BUILD_ENABLE_TOUCH
6709 void InputWindowsManager::ReverseXY(int32_t &x, int32_t &y)
6710 {
6711     CALL_DEBUG_ENTER;
6712     auto &DisplaysInfo = GetDisplayInfoVector(MAIN_GROUPID);
6713     if (DisplaysInfo.empty()) {
6714         MMI_HILOGE("DisplaysInfo is empty");
6715         return;
6716     }
6717     const Direction direction = DisplaysInfo.front().direction;
6718     if (direction < Direction::DIRECTION0 || direction > Direction::DIRECTION270) {
6719         MMI_HILOGE("direction is invalid, direction:%{public}d", direction);
6720         return;
6721     }
6722     Coordinate2D matrix { 0.0, 0.0 };
6723     ReverseRotateScreen(DisplaysInfo.front(), x, y, matrix);
6724     x = static_cast<int32_t>(matrix.x);
6725     y = static_cast<int32_t>(matrix.y);
6726 }
6727 
6728 void InputWindowsManager::SendCancelEventWhenLock()
6729 {
6730     CALL_INFO_TRACE;
6731     CHKPV(lastTouchEventOnBackGesture_);
6732     if (lastTouchEventOnBackGesture_->GetPointerAction() != PointerEvent::POINTER_ACTION_MOVE &&
6733         lastTouchEventOnBackGesture_->GetPointerAction() != PointerEvent::POINTER_ACTION_DOWN) {
6734             return;
6735     }
6736     lastTouchEventOnBackGesture_->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
6737     lastTouchEventOnBackGesture_->SetActionTime(GetSysClockTime());
6738     lastTouchEventOnBackGesture_->UpdateId();
6739     lastTouchEventOnBackGesture_->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT | InputEvent::EVENT_FLAG_NO_MONITOR);
6740     auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler();
6741     CHKPV(inputEventNormalizeHandler);
6742     MMI_HILOGI("Screen locked, Send cancel event");
6743     inputEventNormalizeHandler->HandleTouchEvent(lastTouchEventOnBackGesture_);
6744     auto iter = touchItemDownInfos_.find(lastTouchEventOnBackGesture_->GetPointerId());
6745     if (iter != touchItemDownInfos_.end()) {
6746         iter->second.flag = false;
6747     }
6748 }
6749 #endif // OHOS_BUILD_ENABLE_TOUCH
6750 
6751 bool InputWindowsManager::IsTransparentWin(
6752     std::unique_ptr<Media::PixelMap> &pixelMap, int32_t logicalX, int32_t logicalY)
6753     __attribute__((no_sanitize("cfi")))
6754 {
6755     CALL_DEBUG_ENTER;
6756     if (pixelMap == nullptr) {
6757         return false;
6758     }
6759 
6760     uint32_t dst = 0;
6761     OHOS::Media::Position pos { logicalX, logicalY };
6762     uint32_t result = pixelMap->ReadPixel(pos, dst);
6763     if (result != RET_OK) {
6764         MMI_HILOGE("Failed to read pixelmap");
6765         return false;
6766     }
6767     MMI_HILOGD("dst:%{public}d, byteCount:%{public}d, width:%{public}d, height:%{public}d",
6768         dst, pixelMap->GetByteCount(), pixelMap->GetWidth(), pixelMap->GetHeight());
6769     return dst == RET_OK;
6770 }
6771 
6772 int32_t InputWindowsManager::SetCurrentUser(int32_t userId)
6773 {
6774     CALL_DEBUG_ENTER;
6775     currentUserId_ = userId;
6776     return RET_OK;
6777 }
6778 
6779 void InputWindowsManager::PrintChangedWindowByEvent(int32_t eventType, const WindowInfo &newWindowInfo)
6780 {
6781     auto iter = lastMatchedWindow_.find(eventType);
6782     if (iter != lastMatchedWindow_.end() && iter->second.id != newWindowInfo.id) {
6783         MMI_HILOGI("Target window changed %{public}d %{public}d %{public}d %{public}f "
6784             "%{public}d %{public}d %{public}f", eventType, iter->second.id, iter->second.pid,
6785             iter->second.zOrder, newWindowInfo.id, newWindowInfo.pid, newWindowInfo.zOrder);
6786     }
6787     lastMatchedWindow_[eventType] = newWindowInfo;
6788 }
6789 
6790 void InputWindowsManager::PrintChangedWindowBySync(const OLD::DisplayGroupInfo &newDisplayInfo)
6791 {
6792     auto &WindowsInfo = GetWindowInfoVector(newDisplayInfo.groupId);
6793     auto &oldWindows = WindowsInfo;
6794     auto &newWindows = newDisplayInfo.windowsInfo;
6795     if (!oldWindows.empty() && !newWindows.empty()) {
6796         if (oldWindows[0].id != newWindows[0].id) {
6797             MMI_HILOGI("Window sync changed %{public}d %{public}d %{public}f %{public}d %{public}d %{public}f",
6798                 oldWindows[0].id, oldWindows[0].pid, oldWindows[0].zOrder, newWindows[0].id,
6799                 newWindows[0].pid, newWindows[0].zOrder);
6800         }
6801     }
6802     auto &DisplaysInfo = GetDisplayInfoVector(newDisplayInfo.groupId);
6803     if (newDisplayInfo.displaysInfo.empty() || DisplaysInfo.empty()) {
6804         MMI_HILOGE("displayGroupInfo.displaysInfo is empty");
6805         return;
6806     }
6807     for (const auto &item : newDisplayInfo.displaysInfo) {
6808         int32_t displayId = item.id;
6809         auto iter = std::find_if(DisplaysInfo.begin(), DisplaysInfo.end(),
6810             [displayId](const auto& displayInfo) {
6811             return displayId == displayInfo.id;
6812         });
6813         if (iter == DisplaysInfo.end()) {
6814             continue;
6815         }
6816         if (item.direction != iter->direction || item.displayDirection != iter->displayDirection) {
6817             MMI_HILOGI("displayInfos,id:%{public}d,x:%{private}d,y:%{private}d,width:%{public}d,height:%{public}d,"
6818                 "name:%{public}s,uniq:%{public}s,direction:%{public}d,displayDirection:%{public}d,"
6819                 "oldDirection:%{public}d,oldDisplayDirection:%{public}d", item.id, item.x, item.y, item.width,
6820                 item.height, item.name.c_str(), item.uniq.c_str(), item.direction, item.displayDirection,
6821                 iter->direction, iter->displayDirection);
6822         }
6823     }
6824 }
6825 
6826 bool InputWindowsManager::ParseConfig()
6827 {
6828     std::string defaultConfig = "/system/etc/multimodalinput/white_list_config.json";
6829     return ParseJson(defaultConfig);
6830 }
6831 
6832 bool InputWindowsManager::ParseJson(const std::string &configFile)
6833 {
6834     CALL_DEBUG_ENTER;
6835     std::string jsonStr = ReadJsonFile(configFile);
6836     if (jsonStr.empty()) {
6837         MMI_HILOGE("Read configFile failed");
6838         return false;
6839     }
6840     JsonParser jsonData(jsonStr.c_str());
6841     if (!cJSON_IsObject(jsonData.Get())) {
6842         MMI_HILOGE("The json data is not object");
6843         return false;
6844     }
6845     cJSON* whiteList = cJSON_GetObjectItemCaseSensitive(jsonData.Get(), "whiteList");
6846     if (!cJSON_IsArray(whiteList)) {
6847         MMI_HILOGE("White list number must be array");
6848         return false;
6849     }
6850     int32_t whiteListSize = cJSON_GetArraySize(whiteList);
6851     for (int32_t i = 0; i < whiteListSize; ++i) {
6852         cJSON *whiteListJson = cJSON_GetArrayItem(whiteList, i);
6853         if (!cJSON_IsObject(whiteListJson)) {
6854             MMI_HILOGE("White list json is not object");
6855             continue;
6856         }
6857         SwitchFocusKey switchFocusKey;
6858         cJSON *keyCodeJson = cJSON_GetObjectItemCaseSensitive(whiteListJson, "keyCode");
6859         if (!cJSON_IsNumber(keyCodeJson)) {
6860             MMI_HILOGE("Key code json is not number");
6861             continue;
6862         }
6863         switchFocusKey.keyCode = keyCodeJson->valueint;
6864         cJSON *pressedKeyJson = cJSON_GetObjectItemCaseSensitive(whiteListJson, "pressedKey");
6865         if (!cJSON_IsNumber(pressedKeyJson)) {
6866             MMI_HILOGE("Pressed key json is not number");
6867             continue;
6868         }
6869         switchFocusKey.pressedKey = pressedKeyJson->valueint;
6870         vecWhiteList_.push_back(switchFocusKey);
6871     }
6872     return true;
6873 }
6874 
6875 void InputWindowsManager::SetWindowStateNotifyPid(int32_t pid)
6876 {
6877     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
6878         windowStateNotifyPid_ = pid;
6879     }
6880 }
6881 
6882 int32_t InputWindowsManager::GetWindowStateNotifyPid()
6883 {
6884     return windowStateNotifyPid_;
6885 }
6886 
6887 int32_t InputWindowsManager::GetPidByWindowId(int32_t id)
6888 {
6889     int32_t groupId = FindDisplayGroupId(id);
6890     auto &WindowsInfo = GetWindowInfoVector(groupId);
6891     for (auto &item : WindowsInfo) {
6892         if (item.id == id) {
6893             return item.pid;
6894         }
6895         for (const auto &uiExtentionWindow : item.uiExtentionWindowInfo) {
6896             if (uiExtentionWindow.id == id) {
6897                 return uiExtentionWindow.pid;
6898             }
6899         }
6900     }
6901     return RET_ERR;
6902 }
6903 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
6904 bool InputWindowsManager::IsKeyPressed(int32_t pressedKey, std::vector<KeyEvent::KeyItem> &keyItems)
6905 {
6906     CALL_DEBUG_ENTER;
6907     for (const auto &item : keyItems) {
6908         if (item.GetKeyCode() == pressedKey && item.IsPressed()) {
6909             return true;
6910         }
6911     }
6912     return false;
6913 }
6914 
6915 bool InputWindowsManager::IsOnTheWhitelist(std::shared_ptr<KeyEvent> keyEvent)
6916 {
6917     CALL_DEBUG_ENTER;
6918     CHKPF(keyEvent);
6919     for (const auto &item : vecWhiteList_) {
6920         if (item.keyCode == keyEvent->GetKeyCode()) {
6921             auto keyItems = keyEvent->GetKeyItems();
6922             if (item.pressedKey == -1 && keyItems.size() == 1) {
6923                 return true;
6924             }
6925             bool flag = ((item.pressedKey != -1) && (keyEvent->GetKeyAction() == KeyEvent::KEY_ACTION_DOWN) &&
6926                 (keyItems.size() == 2) && IsKeyPressed(item.pressedKey, keyItems));
6927             if (flag) {
6928                 return true;
6929             }
6930         }
6931     }
6932     return false;
6933 }
6934 #endif // OHOS_BUILD_ENABLE_KEYBOARD
6935 
6936 int32_t InputWindowsManager::SetPixelMapData(int32_t infoId, void *pixelMap)
6937     __attribute__((no_sanitize("cfi")))
6938 {
6939     CALL_DEBUG_ENTER;
6940     if (infoId < 0 || pixelMap == nullptr) {
6941         MMI_HILOGE("The infoId is invalid or pixelMap is nullptr");
6942         return ERR_INVALID_VALUE;
6943     }
6944     std::unique_ptr<OHOS::Media::PixelMap> pixelMapSource(
6945         static_cast<OHOS::Media::PixelMap*>(pixelMap));
6946     Media::InitializationOptions opts;
6947     auto pixelMapPtr = OHOS::Media::PixelMap::Create(*pixelMapSource, opts);
6948     CHKPR(pixelMapPtr, RET_ERR);
6949     MMI_HILOGD("The byteCount:%{public}d, width:%{public}d, height:%{public}d",
6950         pixelMapPtr->GetByteCount(), pixelMapPtr->GetWidth(), pixelMapPtr->GetHeight());
6951     transparentWins_.insert_or_assign(infoId, std::move(pixelMapPtr));
6952     return RET_OK;
6953 }
6954 
6955 void InputWindowsManager::CleanInvalidPiexMap(int32_t groupId)
6956 {
6957     auto &WindowInfo = GetWindowInfoVector(groupId);
6958     for (auto it = transparentWins_.begin(); it != transparentWins_.end();) {
6959         int32_t windowId = it->first;
6960         auto iter = std::find_if(WindowInfo.begin(), WindowInfo.end(),
6961             [windowId](const auto &window) {
6962                 return window.id == windowId;
6963         });
6964         if (iter == WindowInfo.end()) {
6965             it = transparentWins_.erase(it);
6966         } else {
6967             ++it;
6968         }
6969     }
6970 }
6971 
6972 #ifdef OHOS_BUILD_ENABLE_ANCO
6973 bool InputWindowsManager::IsKnuckleOnAncoWindow(std::shared_ptr<PointerEvent> pointerEvent)
6974 {
6975     CALL_DEBUG_ENTER;
6976     CHKPF(pointerEvent);
6977     PointerEvent::PointerItem pointerItem {};
6978     int32_t pointerId = pointerEvent->GetPointerId();
6979     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
6980         MMI_HILOGE("Get pointer item failed, pointer:%{public}d", pointerId);
6981         return false;
6982     }
6983 
6984     if (pointerItem.GetToolType() != PointerEvent::TOOL_TYPE_KNUCKLE) {
6985         return false;
6986     }
6987 
6988     int32_t groupId = FindDisplayGroupId(pointerEvent->GetTargetDisplayId());
6989     const int32_t focusWindowId = GetFocusWindowId(groupId);
6990     WindowInfo *windowInfo = nullptr;
6991     std::vector<WindowInfo> windowInfos = GetWindowGroupInfoByDisplayId(pointerEvent->GetTargetDisplayId());
6992     auto iter = find_if(windowInfos.begin(), windowInfos.end(),
6993         [&](const auto &item) { return item.id == focusWindowId; });
6994     if (iter != windowInfos.end()) {
6995         windowInfo = &(*iter);
6996     }
6997 
6998     if (windowInfo == nullptr) {
6999         MMI_HILOGE("windowInfo is nullptr");
7000         return false;
7001     }
7002 
7003     return IsAncoWindowFocus(*windowInfo);
7004 }
7005 #endif // OHOS_BUILD_ENABLE_ANCO
7006 
7007 void InputWindowsManager::UpdateKeyEventDisplayId(std::shared_ptr<KeyEvent> keyEvent,
7008     int32_t focusWindowId, int32_t groupId)
7009 {
7010     CHKPV(keyEvent);
7011     bool hasFound = false;
7012     std::map<int32_t, WindowGroupInfo> windowsPerDisplayTmp = windowsPerDisplay_;
7013     const auto iter = windowsPerDisplayMap_.find(groupId);
7014     if (iter != windowsPerDisplayMap_.end()) {
7015         windowsPerDisplayTmp = iter->second;
7016     }
7017     for (const auto &item : windowsPerDisplayTmp) {
7018 
7019         if (item.second.focusWindowId == focusWindowId) {
7020             keyEvent->SetTargetDisplayId(item.second.displayId);
7021             hasFound = true;
7022         }
7023     }
7024     auto &DisplaysInfo = GetDisplayInfoVector(groupId);
7025     if (!hasFound && !DisplaysInfo.empty()) {
7026         keyEvent->SetTargetDisplayId(DisplaysInfo[0].id);
7027     }
7028 }
7029 
7030 bool InputWindowsManager::OnDisplayRemovedOrCombinationChanged(const OLD::DisplayGroupInfo &displayGroupInfo)
7031 {
7032     auto &displaysInfoVector = GetDisplayInfoVector(displayGroupInfo.groupId);
7033     if (displayGroupInfo.displaysInfo.empty() || displaysInfoVector.empty()) {
7034         return false;
7035     }
7036     if (displayGroupInfo.displaysInfo.size() < displaysInfoVector.size()) {
7037         MMI_HILOGD("display has been removed");
7038         return true;
7039     }
7040     OLD::DisplayInfo newMainDisplayInfo;
7041     OLD::DisplayInfo oldMainDisplayInfo;
7042     (void)GetMainScreenDisplayInfo(displayGroupInfo.displaysInfo, newMainDisplayInfo);
7043     (void)GetMainScreenDisplayInfo(displaysInfoVector, oldMainDisplayInfo);
7044     MMI_HILOGI("newMainDisplayInfo:%{public}" PRIu64 ", oldMainDisplayInfo:%{public}" PRIu64,
7045         newMainDisplayInfo.rsId, oldMainDisplayInfo.rsId);
7046     if (displayGroupInfo.displaysInfo.size() == displaysInfoVector.size() &&
7047         newMainDisplayInfo.rsId != oldMainDisplayInfo.rsId) {
7048         MMI_HILOGD("current mainScreenDisplayId changed");
7049         return true;
7050     }
7051     return false;
7052 }
7053 
7054 bool InputWindowsManager::GetHardCursorEnabled()
7055 {
7056     return CursorDrawingComponent::GetInstance().GetHardCursorEnabled();
7057 }
7058 
7059 int32_t InputWindowsManager::GetCurrentUserId()
7060 {
7061     return currentUserId_;
7062 }
7063 
7064 void InputWindowsManager::SetFoldState()
7065 {
7066     BytraceAdapter::StartFoldState(Rosen::DisplayManagerLite::GetInstance().IsFoldable());
7067     auto begin = std::chrono::high_resolution_clock::now();
7068     IsFoldable_ = Rosen::DisplayManagerLite::GetInstance().IsFoldable();
7069     auto durationMS = std::chrono::duration_cast<std::chrono::milliseconds>(
7070         std::chrono::high_resolution_clock::now() - begin).count();
7071 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
7072     DfxHisysevent::ReportApiCallTimes(ApiDurationStatistics::Api::IS_FOLDABLE, durationMS);
7073 #endif // OHOS_BUILD_ENABLE_DFX_RADAR
7074     BytraceAdapter::StopFoldState();
7075 }
7076 
7077 const OLD::DisplayInfo *InputWindowsManager::GetPhysicalDisplay(int32_t id,
7078     const OLD::DisplayGroupInfo &displayGroupInfo) const
7079 {
7080     for (const auto &it : displayGroupInfo.displaysInfo) {
7081         if (it.id == id) {
7082             return &it;
7083         }
7084     }
7085     MMI_HILOGW("Failed to obtain physical(%{public}d) display", id);
7086     return nullptr;
7087 }
7088 
7089 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
7090 std::optional<WindowInfo> InputWindowsManager::GetWindowInfoById(int32_t windowId) const
7091 {
7092     for (const auto &it : windowsPerDisplayMap_) {
7093         for (auto iter = it.second.begin(); iter != it.second.end(); ++iter) {
7094             int32_t displayId = iter->first;
7095             if (displayId < 0) {
7096                 MMI_HILOGE("windowsPerDisplay_ contain invalid displayId:%{public}d", displayId);
7097                 continue;
7098             }
7099             for (const auto& item : iter->second.windowsInfo) {
7100                 CHKCC(item.id == windowId &&
7101                     (item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) != WindowInfo::FLAG_BIT_UNTOUCHABLE &&
7102                     transparentWins_.find(item.id) == transparentWins_.end());
7103                 return std::make_optional(item);
7104             }
7105         }
7106     }
7107     return std::nullopt;
7108 }
7109 
7110 int32_t InputWindowsManager::ShiftAppMousePointerEvent(const ShiftWindowInfo &shiftWindowInfo, bool autoGenDown)
7111 {
7112     auto lastPointerEventCopy = GetlastPointerEvent();
7113     if (!lastPointerEventCopy || !lastPointerEventCopy->IsButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT)) {
7114         MMI_HILOGE("Failed shift pointerEvent, left mouse button is not pressed");
7115         return RET_ERR;
7116     }
7117     const WindowInfo &sourceWindowInfo = shiftWindowInfo.sourceWindowInfo;
7118     const WindowInfo &targetWindowInfo = shiftWindowInfo.targetWindowInfo;
7119     std::shared_ptr<PointerEvent> pointerEvent = std::make_shared<PointerEvent>(*lastPointerEventCopy);
7120     pointerEvent->ClearButtonPressed();
7121 
7122     int32_t pointerId = pointerEvent->GetPointerId();
7123     PointerEvent::PointerItem item;
7124     pointerEvent->GetPointerItem(pointerId, item);
7125     item.SetWindowX(lastLogicX_ - sourceWindowInfo.area.x);
7126     item.SetWindowY(lastLogicY_ - sourceWindowInfo.area.y);
7127     item.SetWindowXPos(lastLogicX_ - sourceWindowInfo.area.x);
7128     item.SetWindowYPos(lastLogicY_ - sourceWindowInfo.area.y);
7129     item.SetPressed(false);
7130     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
7131     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP);
7132     pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
7133     pointerEvent->SetTargetDisplayId(sourceWindowInfo.displayId);
7134     pointerEvent->SetTargetWindowId(sourceWindowInfo.id);
7135     pointerEvent->SetAgentWindowId(sourceWindowInfo.agentWindowId);
7136     ClearTargetWindowId(pointerId);
7137     pointerEvent->UpdatePointerItem(pointerId, item);
7138     auto filter = InputHandler->GetFilterHandler();
7139     CHKPR(filter, RET_ERR);
7140     filter->HandlePointerEvent(pointerEvent);
7141     if (autoGenDown) {
7142         item.SetWindowX(shiftWindowInfo.x);
7143         item.SetWindowY(shiftWindowInfo.y);
7144         item.SetWindowXPos(shiftWindowInfo.x);
7145         item.SetWindowYPos(shiftWindowInfo.y);
7146         if (shiftWindowInfo.x == -1 && shiftWindowInfo.y == -1) {
7147             item.SetWindowX(lastLogicX_ - targetWindowInfo.area.x);
7148             item.SetWindowY(lastLogicY_ - targetWindowInfo.area.y);
7149             item.SetWindowXPos(lastLogicX_ - targetWindowInfo.area.x);
7150             item.SetWindowYPos(lastLogicY_ - targetWindowInfo.area.y);
7151         }
7152         item.SetPressed(true);
7153         pointerEvent->ClearButtonPressed();
7154         pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
7155         pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
7156         pointerEvent->UpdatePointerItem(pointerId, item);
7157         pointerEvent->SetTargetDisplayId(targetWindowInfo.displayId);
7158         pointerEvent->SetTargetWindowId(targetWindowInfo.id);
7159         pointerEvent->SetAgentWindowId(targetWindowInfo.agentWindowId);
7160         HITRACE_METER_NAME(HITRACE_TAG_MULTIMODALINPUT, "shift pointer event dispatch down event");
7161         filter->HandlePointerEvent(pointerEvent);
7162     }
7163     firstBtnDownWindowInfo_.first = targetWindowInfo.id;
7164     firstBtnDownWindowInfo_.second = targetWindowInfo.displayId;
7165     mouseDownInfo_ = targetWindowInfo;
7166     MMI_HILOGI("shift pointer event success for mouse");
7167     return RET_OK;
7168 }
7169 
7170 int32_t InputWindowsManager::ShiftAppSimulateTouchPointerEvent(const ShiftWindowInfo &shiftWindowInfo)
7171 {
7172     CHKPR(lastTouchEvent_, RET_ERR);
7173     const WindowInfo &sourceWindowInfo = shiftWindowInfo.sourceWindowInfo;
7174     const WindowInfo &targetWindowInfo = shiftWindowInfo.targetWindowInfo;
7175     PointerEvent::PointerItem item;
7176     if (!lastTouchEvent_->GetPointerItem(shiftWindowInfo.fingerId, item) &&
7177         !lastTouchEvent_->GetOriginPointerItem(shiftWindowInfo.fingerId, item)) {
7178         MMI_HILOGE("Get pointer item failed");
7179         return RET_ERR;
7180     }
7181     if (!item.IsPressed()) {
7182         MMI_HILOGE("Failed shift pointerEvent, fingerId:%{public}d is not pressed", shiftWindowInfo.fingerId);
7183         return RET_ERR;
7184     }
7185     item.SetWindowX(lastTouchLogicX_ - sourceWindowInfo.area.x);
7186     item.SetWindowY(lastTouchLogicY_ - sourceWindowInfo.area.y);
7187     item.SetWindowXPos(lastTouchLogicX_ - sourceWindowInfo.area.x);
7188     item.SetWindowYPos(lastTouchLogicY_ - sourceWindowInfo.area.y);
7189     item.SetPressed(false);
7190     item.SetTargetWindowId(sourceWindowInfo.id);
7191     item.SetPointerId(shiftWindowInfo.fingerId);
7192     lastTouchEvent_->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
7193     lastTouchEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
7194     lastTouchEvent_->SetPointerId(shiftWindowInfo.fingerId);
7195     lastTouchEvent_->SetTargetDisplayId(sourceWindowInfo.displayId);
7196     lastTouchEvent_->SetTargetWindowId(sourceWindowInfo.id);
7197     lastTouchEvent_->SetAgentWindowId(sourceWindowInfo.agentWindowId);
7198     lastTouchEvent_->UpdateId();
7199     ClearTargetWindowId(shiftWindowInfo.fingerId);
7200     lastTouchEvent_->UpdatePointerItem(shiftWindowInfo.fingerId, item);
7201     auto filter = InputHandler->GetFilterHandler();
7202     CHKPR(filter, RET_ERR);
7203     filter->HandlePointerEvent(lastTouchEvent_);
7204     item.SetWindowX(shiftWindowInfo.x);
7205     item.SetWindowY(shiftWindowInfo.y);
7206     item.SetWindowXPos(shiftWindowInfo.x);
7207     item.SetWindowYPos(shiftWindowInfo.y);
7208     if (shiftWindowInfo.x == -1 && shiftWindowInfo.y == -1) {
7209         item.SetWindowX(lastTouchLogicX_ - targetWindowInfo.area.x);
7210         item.SetWindowY(lastTouchLogicY_ - targetWindowInfo.area.y);
7211         item.SetWindowXPos(lastTouchLogicX_ - targetWindowInfo.area.x);
7212         item.SetWindowYPos(lastTouchLogicY_ - targetWindowInfo.area.y);
7213     }
7214     item.SetPressed(true);
7215     item.SetTargetWindowId(targetWindowInfo.id);
7216     item.SetPointerId(shiftWindowInfo.fingerId);
7217     lastTouchEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
7218     lastTouchEvent_->SetTargetDisplayId(targetWindowInfo.displayId);
7219     lastTouchEvent_->SetPointerId(shiftWindowInfo.fingerId);
7220     lastTouchEvent_->SetTargetWindowId(targetWindowInfo.id);
7221     lastTouchEvent_->SetAgentWindowId(targetWindowInfo.agentWindowId);
7222     lastTouchEvent_->UpdatePointerItem(shiftWindowInfo.fingerId, item);
7223     HITRACE_METER_NAME(HITRACE_TAG_MULTIMODALINPUT, "shift touch event dispatch down event");
7224     filter->HandlePointerEvent(lastTouchEvent_);
7225     return RET_OK;
7226 }
7227 
7228 int32_t InputWindowsManager::ShiftAppTouchPointerEvent(const ShiftWindowInfo &shiftWindowInfo)
7229 {
7230     if (shiftWindowInfo.fingerId == -1) {
7231         MMI_HILOGE("Failed shift touchpointerEvent, fingerId is invalid");
7232         return RET_ERR;
7233     }
7234     if (ShiftAppSimulateTouchPointerEvent(shiftWindowInfo) != RET_OK) {
7235         MMI_HILOGE("Failed shift touchPointerEvent");
7236         return RET_ERR;
7237     }
7238     WindowInfoEX windowInfoEX;
7239     windowInfoEX.window = shiftWindowInfo.targetWindowInfo;
7240     windowInfoEX.flag = true;
7241     touchItemDownInfos_[shiftWindowInfo.fingerId] = windowInfoEX;
7242     MMI_HILOGI("Shift pointer event success for touch");
7243     return RET_OK;
7244 }
7245 
7246 int32_t InputWindowsManager::ShiftAppPointerEvent(const ShiftWindowParam &param, bool autoGenDown)
7247 {
7248     MMI_HILOGI("Start shift pointer event, sourceWindowId:%{public}d, targetWindowId:%{public}d,"
7249         "x:%{private}d, y:%{private}d, autoGenDown:%{public}d",
7250         param.sourceWindowId, param.targetWindowId, param.x, param.y, static_cast<int32_t>(autoGenDown));
7251     std::optional<WindowInfo> sourceWindowInfo = GetWindowInfoById(param.sourceWindowId);
7252     std::optional<WindowInfo> targetWindowInfo = GetWindowInfoById(param.targetWindowId);
7253     if (!sourceWindowInfo || !targetWindowInfo) {
7254         MMI_HILOGE("Failed shift pointerEvent, get null sourceWindowInfo, source:%{public}d, target:%{public}d",
7255         static_cast<int32_t>(!!sourceWindowInfo), static_cast<int32_t>(!!targetWindowInfo));
7256         return RET_ERR;
7257     }
7258     ShiftWindowInfo shiftWindowInfo;
7259     shiftWindowInfo.sourceWindowInfo = *sourceWindowInfo;
7260     shiftWindowInfo.targetWindowInfo = *targetWindowInfo;
7261     shiftWindowInfo.x = param.x;
7262     shiftWindowInfo.y = param.y;
7263     shiftWindowInfo.fingerId = param.fingerId;
7264     shiftWindowInfo.sourceType = param.sourceType;
7265     if (shiftWindowInfo.sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
7266         return ShiftAppTouchPointerEvent(shiftWindowInfo);
7267     }
7268     else {
7269         return ShiftAppMousePointerEvent(shiftWindowInfo, autoGenDown);
7270     }
7271 }
7272 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
7273 
7274 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
7275 bool InputWindowsManager::CancelTouch(int32_t touch)
7276 {
7277     auto iter = touchItemDownInfos_.find(touch);
7278     if ((iter != touchItemDownInfos_.end()) && iter->second.flag) {
7279         iter->second.flag = false;
7280         return true;
7281     }
7282     return false;
7283 }
7284 
7285 void InputWindowsManager::AttachTouchGestureMgr(std::shared_ptr<TouchGestureManager> touchGestureMgr)
7286 {
7287     touchGestureMgr_ = touchGestureMgr;
7288 }
7289 
7290 void InputWindowsManager::CancelAllTouches(std::shared_ptr<PointerEvent> event, bool isDisplayChanged)
7291 {
7292     CHKPV(event);
7293     auto pointerEvent = std::make_shared<PointerEvent>(*event);
7294     int32_t originAction = pointerEvent->GetPointerAction();
7295     pointerEvent->SetOriginPointerAction(originAction);
7296     auto items = event->GetAllPointerItems();
7297     for (const auto &item : items) {
7298         if (!item.IsPressed()) {
7299             continue;
7300         }
7301         int32_t pointerId = item.GetPointerId();
7302         int32_t action = PointerEvent::POINTER_ACTION_CANCEL;
7303         bool isDragging = extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN &&
7304                           (item.GetToolType() == PointerEvent::TOOL_TYPE_FINGER && extraData_.pointerId == pointerId);
7305         if (isDragging) {
7306             action = PointerEvent::POINTER_ACTION_PULL_CANCEL;
7307         }
7308         pointerEvent->SetPointerAction(action);
7309         if (isDisplayChanged) {
7310             pointerEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
7311         } else {
7312             pointerEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT | InputEvent::EVENT_FLAG_NO_MONITOR);
7313         }
7314         pointerEvent->SetPointerId(pointerId);
7315 
7316         if (AdjustFingerFlag(pointerEvent)) {
7317             continue;
7318         }
7319         MMI_HILOGI("Cancel touch, pointerId:%{public}d, action:%{public}d", pointerId, action);
7320         auto now = GetSysClockTime();
7321         pointerEvent->SetActionTime(now);
7322         pointerEvent->SetTargetWindowId(item.GetTargetWindowId());
7323         auto winOpt = GetWindowAndDisplayInfo(item.GetTargetWindowId(), pointerEvent->GetTargetDisplayId());
7324         if (winOpt) {
7325             pointerEvent->SetAgentWindowId(winOpt->agentWindowId);
7326         }
7327         pointerEvent->UpdateId();
7328         auto filter = InputHandler->GetFilterHandler();
7329         CHKPV(filter);
7330         filter->HandleTouchEvent(pointerEvent);
7331         CancelTouch(item.GetPointerId());
7332     }
7333 }
7334 
7335 #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
7336 
7337 std::shared_ptr<PointerEvent> InputWindowsManager::GetlastPointerEvent()
7338 {
7339     std::lock_guard<std::mutex> guard(mtx_);
7340     return lastPointerEvent_;
7341 }
7342 
7343 std::pair<int32_t, int32_t> InputWindowsManager::CalcDrawCoordinate(const OLD::DisplayInfo& displayInfo,
7344     PointerEvent::PointerItem pointerItem)
7345 {
7346     CALL_DEBUG_ENTER;
7347     double physicalX = pointerItem.GetRawDisplayX();
7348     double physicalY = pointerItem.GetRawDisplayY();
7349     if (!displayInfo.transform.empty()) {
7350         auto displayXY = TransformDisplayXY(displayInfo, physicalX, physicalY);
7351         physicalX = displayXY.first;
7352         physicalY = displayXY.second;
7353     }
7354     return {static_cast<int32_t>(physicalX), static_cast<int32_t>(physicalY)};
7355 }
7356 
7357 void InputWindowsManager::SetDragFlagByPointer(std::shared_ptr<PointerEvent> lastPointerEvent)
7358 {
7359     if (lastPointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
7360         dragFlag_ = true;
7361         MMI_HILOGD("Is in drag scene");
7362     }
7363     if (lastPointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_UP) {
7364         dragFlag_ = false;
7365         isDragBorder_ = false;
7366     }
7367 }
7368 
7369 #ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE
7370 void InputWindowsManager::TouchEnterLeaveEvent(int32_t logicalX, int32_t logicalY,
7371     const std::shared_ptr<PointerEvent> pointerEvent, const WindowInfo* touchWindow)
7372 {
7373     CALL_DEBUG_ENTER;
7374     CHKPV(pointerEvent);
7375     CHKPV(touchWindow);
7376     PointerEvent::PointerItem pointerItem;
7377     int32_t pointerId = pointerEvent->GetPointerId();
7378     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
7379         MMI_HILOGE("GetPointerItem:%{public}d fail", pointerId);
7380         return;
7381     }
7382     int32_t windowX = pointerItem.GetWindowX();
7383     int32_t windowY = pointerItem.GetWindowY();
7384     windowX = std::max(currentDisplayXY_.first, std::min(windowX, touchWindow->area.width));
7385     windowY = std::max(currentDisplayXY_.second, std::min(windowY, touchWindow->area.height));
7386     if (touchWindow->windowInputType == WindowInputType::MIX_LEFT_RIGHT_ANTI_AXIS_MOVE) {
7387         pointerItem.SetWindowX(windowX);
7388         pointerItem.SetWindowY(windowY);
7389         pointerItem.SetWindowXPos(windowX);
7390         pointerItem.SetWindowYPos(windowY);
7391         pointerEvent->UpdatePointerItem(pointerId, pointerItem);
7392     }
7393     if (lastTouchWindowInfo_.id != touchWindow->id) {
7394         if (lastTouchWindowInfo_.id != -1 &&
7395             lastTouchWindowInfo_.windowInputType == WindowInputType::SLID_TOUCH_WINDOW) {
7396             MMI_HILOG_DISPATCHI("Send cancel to slid touch window, "
7397                 "lastWindowType:%{public}d, nowWindowType:%{public}d",
7398                 static_cast<int32_t>(lastTouchWindowInfo_.windowInputType),
7399                 static_cast<int32_t>(touchWindow->windowInputType));
7400             DispatchTouch(PointerEvent::POINTER_ACTION_CANCEL);
7401             MMI_HILOG_DISPATCHI("Send down-action to the new window, (lastWId:%{public}d, LastPId:%{public}d), "
7402                 "(newWId:%{public}d, newWId:%{public}d)",
7403                 lastTouchWindowInfo_.id, lastTouchWindowInfo_.pid, touchWindow->id, touchWindow->pid);
7404             lastTouchLogicX_ = logicalX;
7405             lastTouchLogicY_ = logicalY;
7406             lastTouchEvent_ = pointerEvent;
7407             lastTouchWindowInfo_ = *touchWindow;
7408             lockWindowInfo_ = *touchWindow;
7409             DispatchTouch(PointerEvent::POINTER_ACTION_DOWN);
7410             return;
7411         }
7412     }
7413     lastTouchLogicX_ = logicalX;
7414     lastTouchLogicY_ = logicalY;
7415     lastTouchEvent_ = pointerEvent;
7416     lastTouchWindowInfo_ = *touchWindow;
7417 }
7418 #endif // OHOS_BUILD_ENABLE_ONE_HAND_MODE
7419 
7420 bool InputWindowsManager::IsAccessibilityFocusEvent(std::shared_ptr<PointerEvent> pointerEvent)
7421 {
7422     CHKPF(pointerEvent);
7423     static std::unordered_set<int32_t> accessibilityEventAction {
7424         PointerEvent::POINTER_ACTION_HOVER_MOVE,
7425         PointerEvent::POINTER_ACTION_HOVER_ENTER,
7426         PointerEvent::POINTER_ACTION_HOVER_EXIT,
7427         PointerEvent::POINTER_ACTION_HOVER_CANCEL
7428     };
7429     auto pointerAction = pointerEvent->GetPointerAction();
7430     return accessibilityEventAction.find(pointerAction) != accessibilityEventAction.end();
7431 }
7432 
7433 bool InputWindowsManager::IsAccessibilityEventWithZorderInjected(std::shared_ptr<PointerEvent> pointerEvent)
7434 {
7435     CHKPF(pointerEvent);
7436     if (IsAccessibilityFocusEvent(pointerEvent) && pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE) &&
7437         pointerEvent->GetZOrder() > 0) {
7438         return true;
7439     }
7440     return false;
7441 }
7442 
7443 bool InputWindowsManager::NeedTouchTracking(PointerEvent &event) const
7444 {
7445     if (!event.HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) {
7446         return false;
7447     }
7448     if (event.GetPointerAction() != PointerEvent::POINTER_ACTION_HOVER_MOVE) {
7449         return false;
7450     }
7451     return (event.GetPointerCount() == SINGLE_TOUCH);
7452 }
7453 
7454 void InputWindowsManager::ProcessTouchTracking(std::shared_ptr<PointerEvent> event, const WindowInfo &targetWindow)
7455 {
7456     if (!NeedTouchTracking(*event)) {
7457         return;
7458     }
7459     if (event->GetTargetWindowId() == targetWindow.id) {
7460         return;
7461     }
7462     PointerEvent::PointerItem pointerItem {};
7463     if (!event->GetPointerItem(event->GetPointerId(), pointerItem)) {
7464         MMI_HILOGE("Corrupted pointer event, No:%{public}d,PI:%{public}d", event->GetId(), event->GetPointerId());
7465         return;
7466     }
7467     pointerItem.SetPressed(false);
7468     event->UpdatePointerItem(event->GetPointerId(), pointerItem);
7469     event->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_CANCEL);
7470 
7471     auto normalizeHandler = InputHandler->GetEventNormalizeHandler();
7472     CHKPV(normalizeHandler);
7473     normalizeHandler->HandleTouchEvent(event);
7474 
7475     pointerItem.SetPressed(true);
7476     event->UpdatePointerItem(event->GetPointerId(), pointerItem);
7477     event->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_ENTER);
7478 }
7479 
7480 int32_t InputWindowsManager::ClearMouseHideFlag(int32_t eventId)
7481 {
7482     auto pointerEvent = GetlastPointerEvent();
7483     CHKPR(pointerEvent, ERROR_NULL_POINTER);
7484     int32_t lastEventId = pointerEvent->GetId();
7485     MMI_HILOGI("eventId=%{public}d, lastEventId=%{public}d", eventId, lastEventId);
7486     if (lastEventId == eventId) {
7487         DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
7488         pointerEvent->ClearFlag(InputEvent::EVENT_FLAG_HIDE_POINTER);
7489         MMI_HILOGI("clear hide flag succ.");
7490         return RET_OK;
7491     }
7492     return RET_ERR;
7493 }
7494 
7495 void InputWindowsManager::GetActiveWindowTypeById(int32_t windowId, WindowInputType &windowTypeTemp)
7496 {
7497     auto it = activeTouchWinTypes_.find(windowId);
7498     if (it != activeTouchWinTypes_.end()) {
7499         windowTypeTemp = it->second.windowInputType;
7500         MMI_HILOGD("GetActiveWindowTypeById success: windowId:%{public}d, windowTypeTemp:%{public}hhu",
7501             windowId,
7502             it->second.windowInputType);
7503     }
7504 }
7505 
7506 void InputWindowsManager::AddActiveWindow(int32_t windowId, int32_t pointerId)
7507 {
7508     auto it = activeTouchWinTypes_.find(windowId);
7509     if (it != activeTouchWinTypes_.end()) {
7510         it->second.pointerSet.emplace(pointerId);
7511         MMI_HILOGD("AddActiveWindow success: windowId:%{public}d, windowType:%{public}hhu, "
7512                    "pointerId:%{public}d, pointerSet:%{public}zu",
7513             windowId,
7514             it->second.windowInputType,
7515             pointerId,
7516             it->second.pointerSet.size());
7517     } else {
7518         std::optional<WindowInfo> info = GetWindowInfoById(windowId);
7519         if (!info) {
7520             MMI_HILOGE("Failed to add active window: windowInfo with windowId:%{public}d not found", windowId);
7521             return;
7522         }
7523         activeTouchWinTypes_.emplace(windowId, ActiveTouchWin{(*info).windowInputType, { pointerId }});
7524     }
7525 }
7526 
7527 void InputWindowsManager::RemoveActiveWindow(std::shared_ptr<PointerEvent> pointerEvent)
7528 {
7529     auto pointerAc = pointerEvent->GetPointerAction();
7530     if (pointerAc != PointerEvent::POINTER_ACTION_UP && pointerAc != PointerEvent::POINTER_ACTION_PULL_UP &&
7531         pointerAc != PointerEvent::POINTER_ACTION_CANCEL && pointerAc != PointerEvent::POINTER_ACTION_PULL_THROW) {
7532         return;
7533     }
7534     auto pointerId = pointerEvent->GetPointerId();
7535     for (auto it = activeTouchWinTypes_.begin(); it != activeTouchWinTypes_.end();) {
7536         auto pointerIter = it->second.pointerSet.find(pointerId);
7537         if (pointerIter != it->second.pointerSet.end()) {
7538             it->second.pointerSet.erase(pointerIter);
7539             MMI_HILOGD("RemoveActiveWindow success: windowId:%{public}d, windowType:%{public}hhu, "
7540                        "pointerId:%{public}d, pointerSet:%{public}zu, isInject:%{public}d",
7541                 it->first,
7542                 it->second.windowInputType,
7543                 pointerId,
7544                 it->second.pointerSet.size(),
7545                 pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE));
7546         }
7547         if (it->second.pointerSet.empty()) {
7548             MMI_HILOGD("RemoveActiveWindow success: erase windowId:%{public}d, windowType:%{public}hhu",
7549                 it->first,
7550                 it->second.windowInputType);
7551             it = activeTouchWinTypes_.erase(it);
7552         } else {
7553             ++it;
7554         }
7555     }
7556 }
7557 
7558 void InputWindowsManager::ClearActiveWindow()
7559 {
7560     activeTouchWinTypes_.clear();
7561     MMI_HILOGD("ClearActiveWindow success");
7562 }
7563 } // namespace MMI
7564 } // namespace OHOS
7565