diff --git a/service/libinput_adapter/include/libinput_adapter.h b/service/libinput_adapter/include/libinput_adapter.h index c3f94e07fa5013067a034ccbe4d273f5041ba746..3c22639a86abb0c511b215aeeb6115fb15e65141 100644 --- a/service/libinput_adapter/include/libinput_adapter.h +++ b/service/libinput_adapter/include/libinput_adapter.h @@ -173,7 +173,10 @@ private: const std::vector& msgItem); bool HandleVKeyTrackPadPinchEnd(libinput_event_touch* touch, const std::vector& msgItem); + void InjectEventForTwoFingerOnTouchpad(libinput_event_touch* touch, + libinput_event_type eventType, int64_t frameTime); void InjectEventForCastWindow(libinput_event_touch* touch); + bool IsCursorInCastWindow(); bool HandleVKeyTrackPadPanBegin(libinput_event_touch* touch, const std::vector& msgItem); bool HandleVKeyTrackPadPanUpdate(libinput_event_touch* touch, diff --git a/service/libinput_adapter/src/libinput_adapter.cpp b/service/libinput_adapter/src/libinput_adapter.cpp index 58ac3802a20edc4ea8e7350728e538edca5e3c7b..65d42e3ca1bfeb12363c3616dcffeefc4f31e456 100644 --- a/service/libinput_adapter/src/libinput_adapter.cpp +++ b/service/libinput_adapter/src/libinput_adapter.cpp @@ -1134,18 +1134,7 @@ bool LibinputAdapter::HandleVKeyTrackPadPinchBegin(libinput_event_touch* touch, funInputEvent_((libinput_event*)lgEvent, frameTime); free(lgEvent); - event_touch tEvent; - tEvent.event_type = libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_DOWN; - tEvent.seat_slot = VKEY_PINCH_FIRST_FINGER_ID; - libinput_event_touch* ltEvent = libinput_create_touch_event(touch, tEvent); - funInputEvent_((libinput_event*)ltEvent, frameTime); - free(ltEvent); - - tEvent.event_type = libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_DOWN; - tEvent.seat_slot = VKEY_PINCH_SECOND_FINGER_ID; - ltEvent = libinput_create_touch_event(touch, tEvent); - funInputEvent_((libinput_event*)ltEvent, frameTime); - free(ltEvent); + InjectEventForTwoFingerOnTouchpad(touch, libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_DOWN, frameTime); return true; } @@ -1184,18 +1173,7 @@ bool LibinputAdapter::HandleVKeyTrackPadPinchUpdate(libinput_event_touch* touch, funInputEvent_((libinput_event*)lgEvent, frameTime); free(lgEvent); - event_touch tEvent; - tEvent.event_type = libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_MOTION; - tEvent.seat_slot = VKEY_PINCH_FIRST_FINGER_ID; - libinput_event_touch* ltEvent = libinput_create_touch_event(touch, tEvent); - funInputEvent_((libinput_event*)ltEvent, frameTime); - free(ltEvent); - - tEvent.event_type = libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_MOTION; - tEvent.seat_slot = VKEY_PINCH_SECOND_FINGER_ID; - ltEvent = libinput_create_touch_event(touch, tEvent); - funInputEvent_((libinput_event*)ltEvent, frameTime); - free(ltEvent); + InjectEventForTwoFingerOnTouchpad(touch, libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_MOTION, frameTime); return true; } @@ -1234,30 +1212,44 @@ bool LibinputAdapter::HandleVKeyTrackPadPinchEnd(libinput_event_touch* touch, funInputEvent_((libinput_event*)lgEvent, frameTime); free(lgEvent); - InjectEventForCastWindow(touch); - + if (IsCursorInCastWindow()) { + InjectEventForCastWindow(touch); + } else { + InjectEventForTwoFingerOnTouchpad(touch, libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_UP, frameTime); + } + return true; } -void LibinputAdapter::InjectEventForCastWindow(libinput_event_touch* touch) +void LibinputAdapter::InjectEventForTwoFingerOnTouchpad(libinput_event_touch* touch, + libinput_event_type eventType, int64_t frameTime) { - int64_t frameTime = GetSysClockTime(); - event_touch tEvent; - tEvent.event_type = libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_UP; + tEvent.event_type = eventType; tEvent.seat_slot = VKEY_PINCH_FIRST_FINGER_ID; libinput_event_touch* ltEvent = libinput_create_touch_event(touch, tEvent); - funInputEvent_((libinput_event*)ltEvent, frameTime); - free(ltEvent); + if (ltEvent != nullptr) { + funInputEvent_((libinput_event*)ltEvent, frameTime); + free(ltEvent); + } - tEvent.event_type = libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_UP; tEvent.seat_slot = VKEY_PINCH_SECOND_FINGER_ID; ltEvent = libinput_create_touch_event(touch, tEvent); - funInputEvent_((libinput_event*)ltEvent, frameTime); - free(ltEvent); + if (ltEvent != nullptr) { + funInputEvent_((libinput_event*)ltEvent, frameTime); + free(ltEvent); + } +} - auto mouseInfo = WIN_MGR->GetMouseInfo(); +void LibinputAdapter::InjectEventForCastWindow(libinput_event_touch* touch) +{ + int64_t frameTime = GetSysClockTime(); + InjectEventForTwoFingerOnTouchpad(touch, libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_UP, frameTime); + + event_touch tEvent; + tEvent.seat_slot = VKEY_PINCH_FIRST_FINGER_ID; + auto mouseInfo = WIN_MGR->GetMouseInfo(); tEvent.event_type = libinput_event_type::LIBINPUT_EVENT_TOUCH_DOWN; tEvent.x = mouseInfo.physicalX * VKEY_RAW_COORDINATE_RATIO; tEvent.y = mouseInfo.physicalY * VKEY_RAW_COORDINATE_RATIO; @@ -1281,6 +1273,28 @@ void LibinputAdapter::InjectEventForCastWindow(libinput_event_touch* touch) free(lpEvent); } +bool LibinputAdapter::IsCursorInCastWindow() +{ + InputWindowsManager* inputWindowsManager = static_cast(WIN_MGR.get()); + if (inputWindowsManager == nullptr) { + return false; + } + DisplayGroupInfo displayGroupInfo = inputWindowsManager->GetDisplayGroupInfo(); + for (auto &windowInfo : displayGroupInfo.windowsInfo) { + if (windowInfo.windowType == CAST_WINDOW_TYPE) { + auto mouseInfo = WIN_MGR->GetMouseInfo(); + int32_t x = mouseInfo.physicalX; + int32_t y = mouseInfo.physicalY; + if ((x > windowInfo.area.x && x < (windowInfo.area.x + windowInfo.area.width)) && + (y > windowInfo.area.y && y < (windowInfo.area.y + windowInfo.area.height))) { + return true; + } + } + } + + return false; +} + bool LibinputAdapter::HandleVKeyTrackPadPanBegin(libinput_event_touch* touch, const std::vector& msgItem) {