diff --git a/service/device_manager/include/input_device_manager.h b/service/device_manager/include/input_device_manager.h index 86e08f897e3fb400258ccf3b7f9137fb532f70a9..3eec661df17f48d9e3bb663ec4cb0f5aa46ba740 100644 --- a/service/device_manager/include/input_device_manager.h +++ b/service/device_manager/include/input_device_manager.h @@ -27,6 +27,7 @@ #include "key_map_manager.h" #include "msg_handler.h" #include "nocopyable.h" +#include "pointer_drawing_manager.h" #include "singleton.h" #include "util.h" @@ -36,10 +37,11 @@ class InputDeviceManager final : public IDeviceObject { DECLARE_DELAYED_SINGLETON(InputDeviceManager); struct InputDeviceInfo { - struct libinput_device *inputDeviceOrigin_ { nullptr }; - std::string networkIdOrigin_; - bool isRemote_ { false }; - std::string dhid_; + struct libinput_device *inputDeviceOrigin { nullptr }; + std::string networkIdOrigin; + bool isRemote { false }; + bool isTouchableDevice { false }; + std::string dhid; }; public: DISALLOW_COPY_AND_MOVE(InputDeviceManager); @@ -73,10 +75,12 @@ public: #endif // OHOS_BUILD_ENABLE_COOPERATE bool IsKeyboardDevice(struct libinput_device* device) const; bool IsPointerDevice(struct libinput_device* device) const; + bool IsTouchDevice(struct libinput_device* device) const; struct libinput_device* GetKeyboardDevice() const; #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING bool HasPointerDevice(); #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING + bool HasTouchDevice(); int32_t SetInputDevice(const std::string& dhid, const std::string& screenId); const std::string& GetScreenId(int32_t deviceId) const; diff --git a/service/device_manager/src/input_device_manager.cpp b/service/device_manager/src/input_device_manager.cpp index edaa73b92465b1cf5ea318dcdbd6807bd4b32978..5b63494d52ed437560999bc33dd1154aa6c95378 100644 --- a/service/device_manager/src/input_device_manager.cpp +++ b/service/device_manager/src/input_device_manager.cpp @@ -76,7 +76,7 @@ std::shared_ptr InputDeviceManager::GetInputDevice(int32_t id) cons std::shared_ptr inputDevice = std::make_shared(); CHKPP(inputDevice); inputDevice->SetId(iter->first); - struct libinput_device *inputDeviceOrigin = iter->second.inputDeviceOrigin_; + struct libinput_device *inputDeviceOrigin = iter->second.inputDeviceOrigin; inputDevice->SetType(static_cast(libinput_device_get_tags(inputDeviceOrigin))); const char* name = libinput_device_get_name(inputDeviceOrigin); inputDevice->SetName((name == nullptr) ? ("null") : (name)); @@ -134,7 +134,7 @@ std::vector InputDeviceManager::SupportKeys(int32_t deviceId, std::vector< for (const auto &item : keyCodes) { bool ret = false; for (const auto &it : KeyMapMgr->InputTransferKeyValue(deviceId, item)) { - ret |= libinput_device_has_key(iter->second.inputDeviceOrigin_, it) == SUPPORT_KEY; + ret |= libinput_device_has_key(iter->second.inputDeviceOrigin, it) == SUPPORT_KEY; } keystrokeAbility.push_back(ret); } @@ -256,7 +256,7 @@ void InputDeviceManager::RemoveDevListener(SessionPtr sess) bool InputDeviceManager::HasPointerDevice() { for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { - if (IsPointerDevice(it->second.inputDeviceOrigin_)) { + if (IsPointerDevice(it->second.inputDeviceOrigin)) { return true; } } @@ -264,18 +264,29 @@ bool InputDeviceManager::HasPointerDevice() } #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING +bool InputDeviceManager::HasTouchDevice() +{ + CALL_DEBUG_ENTER; + for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { + if (it->second.isTouchableDevice) { + return true; + } + } + return false; +} + void InputDeviceManager::OnInputDeviceAdded(struct libinput_device *inputDevice) { CALL_DEBUG_ENTER; CHKPV(inputDevice); bool hasLocalPointer = false; for (const auto &item : inputDevice_) { - if (item.second.inputDeviceOrigin_ == inputDevice) { + if (item.second.inputDeviceOrigin == inputDevice) { MMI_HILOGI("The device is already existent"); DfxHisysevent::OnDeviceConnect(item.first, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); return; } - if (!item.second.isRemote_ && IsPointerDevice(item.second.inputDeviceOrigin_)) { + if (!item.second.isRemote && IsPointerDevice(item.second.inputDeviceOrigin)) { hasLocalPointer = true; } } @@ -284,13 +295,7 @@ void InputDeviceManager::OnInputDeviceAdded(struct libinput_device *inputDevice) DfxHisysevent::OnDeviceConnect(INT32_MAX, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); return; } -#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING - if (IsPointerDevice(inputDevice) && !HasPointerDevice()) { -#ifdef OHOS_BUILD_ENABLE_POINTER - WinMgr->DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW); -#endif // OHOS_BUILD_ENABLE_POINTER - } -#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING + struct InputDeviceInfo info; MakeDeviceInfo(inputDevice, info); inputDevice_[nextId_] = info; @@ -301,27 +306,39 @@ void InputDeviceManager::OnInputDeviceAdded(struct libinput_device *inputDevice) ++nextId_; #ifdef OHOS_BUILD_ENABLE_COOPERATE if (IsKeyboardDevice(inputDevice)) { - InputDevCooSM->OnKeyboardOnline(info.dhid_); + InputDevCooSM->OnKeyboardOnline(info.dhid); } #endif // OHOS_BUILD_ENABLE_COOPERATE if (IsPointerDevice(inputDevice)) { - bool visible = !info.isRemote_ || hasLocalPointer; + bool visible = !info.isRemote || hasLocalPointer; + if (HasTouchDevice()) { + IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false); + } NotifyPointerDevice(true, visible); OHOS::system::SetParameter(INPUT_POINTER_DEVICE, "true"); MMI_HILOGI("Set para input.pointer.device true"); } +#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING + if (IsPointerDevice(inputDevice) && !HasPointerDevice() && + IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) { +#ifdef OHOS_BUILD_ENABLE_POINTER + WinMgr->DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW); +#endif // OHOS_BUILD_ENABLE_POINTER + } +#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING DfxHisysevent::OnDeviceConnect(nextId_ - 1, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR); } void InputDeviceManager::MakeDeviceInfo(struct libinput_device *inputDevice, struct InputDeviceInfo& info) { - info.inputDeviceOrigin_ = inputDevice; + info.inputDeviceOrigin = inputDevice; + info.isTouchableDevice = IsTouchDevice(inputDevice); #ifdef OHOS_BUILD_ENABLE_COOPERATE - info.isRemote_ = IsRemote(inputDevice); - if (info.isRemote_) { - info.networkIdOrigin_ = MakeNetworkId(libinput_device_get_phys(inputDevice)); + info.isRemote = IsRemote(inputDevice); + if (info.isRemote) { + info.networkIdOrigin = MakeNetworkId(libinput_device_get_phys(inputDevice)); } - info.dhid_ = GenerateDescriptor(inputDevice, info.isRemote_); + info.dhid = GenerateDescriptor(inputDevice, info.isRemote); #endif // OHOS_BUILD_ENABLE_COOPERATE } @@ -335,7 +352,7 @@ void InputDeviceManager::OnInputDeviceRemoved(struct libinput_device *inputDevic std::vector dhids; #endif // OHOS_BUILD_ENABLE_COOPERATE for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { - if (it->second.inputDeviceOrigin_ == inputDevice) { + if (it->second.inputDeviceOrigin == inputDevice) { deviceId = it->first; #ifdef OHOS_BUILD_ENABLE_COOPERATE removedInfo = it->second; @@ -347,7 +364,8 @@ void InputDeviceManager::OnInputDeviceRemoved(struct libinput_device *inputDevic } } #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING - if (IsPointerDevice(inputDevice) && !HasPointerDevice()) { + if (IsPointerDevice(inputDevice) && !HasPointerDevice() && + IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) { #ifdef OHOS_BUILD_ENABLE_POINTER WinMgr->DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW); #endif // OHOS_BUILD_ENABLE_POINTER @@ -360,7 +378,7 @@ void InputDeviceManager::OnInputDeviceRemoved(struct libinput_device *inputDevic ScanPointerDevice(); #ifdef OHOS_BUILD_ENABLE_COOPERATE if (IsPointerDevice(inputDevice)) { - InputDevCooSM->OnPointerOffline(removedInfo.dhid_, removedInfo.networkIdOrigin_, dhids); + InputDevCooSM->OnPointerOffline(removedInfo.dhid, removedInfo.networkIdOrigin, dhids); } #endif // OHOS_BUILD_ENABLE_COOPERATE if (deviceId == INVALID_DEVICE_ID) { @@ -372,7 +390,7 @@ void InputDeviceManager::ScanPointerDevice() { bool hasPointerDevice = false; for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { - if (IsPointerDevice(it->second.inputDeviceOrigin_)) { + if (IsPointerDevice(it->second.inputDeviceOrigin)) { hasPointerDevice = true; break; } @@ -401,6 +419,12 @@ bool InputDeviceManager::IsKeyboardDevice(struct libinput_device* device) const return udevTags & EVDEV_UDEV_TAG_KEYBOARD; } +bool InputDeviceManager::IsTouchDevice(struct libinput_device* device) const +{ + CHKPF(device); + return libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH); +} + void InputDeviceManager::Attach(std::shared_ptr observer) { CALL_DEBUG_ENTER; @@ -426,7 +450,7 @@ int32_t InputDeviceManager::FindInputDeviceId(struct libinput_device* inputDevic CALL_DEBUG_ENTER; CHKPR(inputDevice, INVALID_DEVICE_ID); for (const auto &item : inputDevice_) { - if (item.second.inputDeviceOrigin_ == inputDevice) { + if (item.second.inputDeviceOrigin == inputDevice) { MMI_HILOGI("Find input device id success"); return item.first; } @@ -442,7 +466,7 @@ struct libinput_device* InputDeviceManager::GetKeyboardDevice() const keyCodes.push_back(KeyEvent::KEYCODE_Q); keyCodes.push_back(KeyEvent::KEYCODE_NUMPAD_1); for (const auto &item : inputDevice_) { - const auto &device = item.second.inputDeviceOrigin_; + const auto &device = item.second.inputDeviceOrigin; if (IsMatchKeys(device, keyCodes)) { MMI_HILOGI("Find keyboard device success"); return device; @@ -507,23 +531,23 @@ std::vector InputDeviceManager::GetCooperateDhids(int32_t deviceId) MMI_HILOGI("Find pointer id failed"); return dhids; } - if (!IsPointerDevice(iter->second.inputDeviceOrigin_)) { + if (!IsPointerDevice(iter->second.inputDeviceOrigin)) { MMI_HILOGI("Not pointer device"); return dhids; } - dhids.push_back(iter->second.dhid_); + dhids.push_back(iter->second.dhid); MMI_HILOGI("unq: %{public}s, type:%{public}s", dhids.back().c_str(), "pointer"); - auto pointerNetworkId = iter->second.networkIdOrigin_; + auto pointerNetworkId = iter->second.networkIdOrigin; std::string localNetworkId; GetLocalDeviceId(localNetworkId); - pointerNetworkId = iter->second.isRemote_ ? iter->second.networkIdOrigin_ : localNetworkId; + pointerNetworkId = iter->second.isRemote ? iter->second.networkIdOrigin : localNetworkId; for (const auto &item : inputDevice_) { - auto networkId = item.second.isRemote_ ? item.second.networkIdOrigin_ : localNetworkId; + auto networkId = item.second.isRemote ? item.second.networkIdOrigin : localNetworkId; if (networkId != pointerNetworkId) { continue; } if (GetDeviceSupportKey(item.first) == KEYBOARD_TYPE_ALPHABETICKEYBOARD) { - dhids.push_back(item.second.dhid_); + dhids.push_back(item.second.dhid); MMI_HILOGI("unq: %{public}s, type:%{public}s", dhids.back().c_str(), "supportkey"); } } @@ -534,7 +558,7 @@ std::vector InputDeviceManager::GetCooperateDhids(const std::string { int32_t pointerId = -1; for (const auto &iter : inputDevice_) { - if (iter.second.dhid_ == dhid) { + if (iter.second.dhid == dhid) { pointerId = iter.first; break; } @@ -549,7 +573,7 @@ std::string InputDeviceManager::GetOriginNetworkId(int32_t id) MMI_HILOGE("Failed to search for the device: id %{public}d", id); return ""; } - auto networkId = iter->second.networkIdOrigin_; + auto networkId = iter->second.networkIdOrigin; if (networkId.empty()) { GetLocalDeviceId(networkId); } @@ -563,8 +587,8 @@ std::string InputDeviceManager::GetOriginNetworkId(const std::string &dhid) } std::string networkId; for (const auto &iter : inputDevice_) { - if (iter.second.dhid_ == dhid) { - networkId = iter.second.networkIdOrigin_; + if (iter.second.dhid == dhid) { + networkId = iter.second.networkIdOrigin; if (networkId.empty()) { GetLocalDeviceId(networkId); break; @@ -591,7 +615,7 @@ std::string InputDeviceManager::GetDhid(int32_t deviceId) const { auto dev = inputDevice_.find(deviceId); if (dev != inputDevice_.end()) { - return dev->second.dhid_; + return dev->second.dhid; } return ""; } @@ -599,7 +623,7 @@ std::string InputDeviceManager::GetDhid(int32_t deviceId) const bool InputDeviceManager::HasLocalPointerDevice() const { for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { - if (!it->second.isRemote_ && IsPointerDevice(it->second.inputDeviceOrigin_)) { + if (!it->second.isRemote && IsPointerDevice(it->second.inputDeviceOrigin)) { return true; } } @@ -628,7 +652,7 @@ bool InputDeviceManager::IsRemote(int32_t id) const bool isRemote = false; auto device = inputDevice_.find(id); if (device != inputDevice_.end()) { - isRemote = device->second.isRemote_; + isRemote = device->second.isRemote; } MMI_HILOGD("isRemote: %{public}s", isRemote == true ? "true" : "false"); return isRemote; @@ -728,7 +752,7 @@ const std::string& InputDeviceManager::GetScreenId(int32_t deviceId) const #ifdef OHOS_BUILD_ENABLE_COOPERATE auto item = inputDevice_.find(deviceId); if (item != inputDevice_.end()) { - auto iter = inputDeviceScreens_.find(item->second.dhid_); + auto iter = inputDeviceScreens_.find(item->second.dhid); if (iter != inputDeviceScreens_.end()) { return iter->second; } diff --git a/service/window_manager/include/i_pointer_drawing_manager.h b/service/window_manager/include/i_pointer_drawing_manager.h index 448bcb2f31b539bdfc69e25940848579747cba1d..385d00325ae3bd2c1f8552709586ecce7c428e30 100644 --- a/service/window_manager/include/i_pointer_drawing_manager.h +++ b/service/window_manager/include/i_pointer_drawing_manager.h @@ -56,6 +56,11 @@ public: { return false; } + virtual void SetMouseDisplayState(bool state) {} + virtual bool GetMouseDisplayState() const + { + return true; + } virtual void SetPointerLocation(int32_t pid, int32_t x, int32_t y) {} public: static inline std::shared_ptr iPointDrawMgr_ { nullptr }; diff --git a/service/window_manager/include/pointer_drawing_manager.h b/service/window_manager/include/pointer_drawing_manager.h index fe1453104d604e7b2bac730675e651d57a097f88..4cff5e98392d6d79c727b607ef61c6aba6dd450b 100644 --- a/service/window_manager/include/pointer_drawing_manager.h +++ b/service/window_manager/include/pointer_drawing_manager.h @@ -45,20 +45,22 @@ public: DISALLOW_COPY_AND_MOVE(PointerDrawingManager); ~PointerDrawingManager() = default; void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, - const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT); - void UpdateDisplayInfo(const DisplayInfo& displayInfo); - void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo); - void OnWindowInfo(const WinInfo &info); - void UpdatePointerDevice(bool hasPointerDevicee, bool isPointerVisible); - bool Init(); - void DeletePointerVisible(int32_t pid); - int32_t SetPointerVisible(int32_t pid, bool visible); - int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle); - int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle); - void DrawPointerStyle(); - bool IsPointerVisible(); - void SetPointerLocation(int32_t pid, int32_t x, int32_t y); + const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT) override; + void UpdateDisplayInfo(const DisplayInfo& displayInfo) override; + void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) override; + void OnWindowInfo(const WinInfo &info) override; + void UpdatePointerDevice(bool hasPointerDevicee, bool isPointerVisible) override; + bool Init() override; + void DeletePointerVisible(int32_t pid) override; + int32_t SetPointerVisible(int32_t pid, bool visible) override; + int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) override; + int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) override; + void DrawPointerStyle() override; + bool IsPointerVisible() override; + void SetPointerLocation(int32_t pid, int32_t x, int32_t y) override; void AdjustMouseFocus(ICON_TYPE iconType, int32_t &physicalX, int32_t &physicalY); + void SetMouseDisplayState(bool state) override; + bool GetMouseDisplayState() const override; private: void CreatePointerWindow(int32_t displayId, int32_t physicalX, int32_t physicalY); @@ -74,7 +76,7 @@ private: void UpdatePidInfo(int32_t pid, bool visible); void InitStyle(); int32_t InitLayer(const MOUSE_ICON mouseStyle); - + private: struct PidInfo { int32_t pid { 0 }; @@ -93,6 +95,7 @@ private: int32_t imageHeight_ { 0 }; std::map mouseIcons_; std::list pidInfos_; + bool mouseDisplayState_ { false }; }; } // namespace MMI } // namespace OHOS diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index 4ce9c22feb75bd24a83f4b5ab25765469e28ec2f..65377e03ccbdaca5a5970056c4ae88f9088e0077 100644 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -824,6 +824,7 @@ int32_t InputWindowsManager::UpdateMouseTarget(std::shared_ptr poi MMI_HILOGE("Get pointer style failed, pointerStyleInfo is nullptr"); return RET_ERR; } + IPointerDrawingManager::GetInstance()->SetMouseDisplayState(true); IPointerDrawingManager::GetInstance()->UpdateDisplayInfo(*physicalDisplayInfo); int32_t mouseStyle = pointerStyleInfo.value(); WinInfo info = { .windowPid = touchWindow->pid, .windowId = touchWindow->id }; @@ -926,6 +927,7 @@ int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptrpid, logicalX, logicalY, physicalX, physicalY, windowX, windowY, displayId, pointerEvent->GetTargetWindowId(), pointerEvent->GetAgentWindowId()); + IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false); return ERR_OK; } #endif // OHOS_BUILD_ENABLE_TOUCH diff --git a/service/window_manager/src/pointer_drawing_manager.cpp b/service/window_manager/src/pointer_drawing_manager.cpp index 88fe0f40b8b0c6455d49125cbf6564ba8199e3a9..ad9c2d601907c5f8e6ccad8024189894d5125898 100644 --- a/service/window_manager/src/pointer_drawing_manager.cpp +++ b/service/window_manager/src/pointer_drawing_manager.cpp @@ -210,6 +210,20 @@ sptr PointerDrawingManager::GetLayer() return surfaceNode->GetSurface(); } +void PointerDrawingManager::SetMouseDisplayState(bool state) +{ + CALL_DEBUG_ENTER; + if (mouseDisplayState_ != state) { + mouseDisplayState_ = state; + InitLayer(MOUSE_ICON(lastMouseStyle_)); + } +} + +bool PointerDrawingManager::GetMouseDisplayState() const +{ + return mouseDisplayState_; +} + sptr PointerDrawingManager::GetSurfaceBuffer(sptr layer) const { sptr buffer; @@ -415,7 +429,7 @@ void PointerDrawingManager::UpdatePointerVisible() { CALL_DEBUG_ENTER; CHKPV(pointerWindow_); - if (IsPointerVisible()) { + if (IsPointerVisible() && mouseDisplayState_) { pointerWindow_->Show(); } else { pointerWindow_->Hide();