diff --git a/service/libinput_adapter/include/libinput_adapter.h b/service/libinput_adapter/include/libinput_adapter.h index e4716c6c392d4ff2baa6ef4221a08e4693b4c52f..aca25ceb78d68aa9bec7982d7328f93917415470 100644 --- a/service/libinput_adapter/include/libinput_adapter.h +++ b/service/libinput_adapter/include/libinput_adapter.h @@ -12,10 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + #ifndef LIBINPUT_ADAPTER_H #define LIBINPUT_ADAPTER_H +#include #include "hotplug_detector.h" #include "libinput.h" #ifdef OHOS_BUILD_ENABLE_VKEYBOARD @@ -40,21 +41,9 @@ typedef std::function& events)> GetLibinputEventForVKeyboard; typedef std::function& events)> GetLibinputEventForVTrackpad; - +typedef std::function ResetVTrackpadState; +typedef std::function StopVTrackpadTimer; #ifdef OHOS_BUILD_ENABLE_VKEYBOARD -enum VTPSwipeStateType { - SWIPE_BEGIN = 1, - SWIPE_UPDATE = 2, - SWIPE_END = 3, -}; -enum VKeyboardMessageType { - VNoMessage = -1, - VKeyPressed = 0, - VCombinationKeyPressed = 1, - VStartLongPressControl = 16, - VStopLongPressControl = 17, - VSwitchLayout = 18, -}; enum VKeyboardEventType { NoKeyboardEvent = -1, NormalKeyboardEvent = 0, @@ -68,37 +57,10 @@ enum VTrackpadEventType { NormalTrackpadEvent = 0, PinchBegin = 1, PinchUpdate = 2, - PinchEnd = 3 -}; -enum class VTPStateMachineMessageType : int32_t { - UNKNOWN = 0, - POINTER_MOVE = 1, - LEFT_CLICK_DOWN = 2, - LEFT_CLICK_UP = 3, - RIGHT_CLICK_DOWN = 4, - RIGHT_CLICK_UP = 5, - SCROLL_BEGIN = 6, - SCROLL_UPDATE = 7, - SCROLL_END = 8, - PINCH_BEGIN = 9, - PINCH_UPDATE = 10, - PINCH_END = 11, - PAN_BEGIN = 12, - PAN_UPDATE = 13, - PAN_END = 14, - ROT_BEGIN = 15, - ROT_UPDATE = 16, - ROT_END = 17, - LEFT_TOUCH_DOWN = 18, - LEFT_TOUCH_UP = 19, - TWO_FINGER_TAP = 20, - LEFT_TOUCH_UP_CANCEL = 21, - SWIPE_BEGIN = 22, - SWIPE_UPDATE = 23, - SWIPE_END = 24, - SWIPE_FOUR_BEGIN = 25, - SWIPE_FOUR_UPDATE = 26, - SWIPE_FOUR_END = 27, + PinchEnd = 3, + SingleTap = 4, + DoubleTap = 5, + RemoveTimer = 6, }; enum class VKeyboardActivation : int32_t { @@ -114,7 +76,7 @@ public: static int32_t DeviceLedUpdate(struct libinput_device *device, int32_t funcKey, bool isEnable); LibinputAdapter() = default; DISALLOW_COPY_AND_MOVE(LibinputAdapter); - ~LibinputAdapter() = default; + ~LibinputAdapter(); bool Init(FunInputEvent funInputEvent); void EventDispatch(int32_t fd); void Stop(); @@ -129,14 +91,15 @@ public: { return std::array{fd_, hotplugDetector_.GetFd()}; } - void InitVKeyboard(HandleTouchPoint handleTouchPoint, HardwareKeyEventDetected hardwareKeyEventDetected, GetKeyboardActivationState getKeyboardActivationState, IsFloatingKeyboard isFloatingKeyboard, IsVKeyboardShown isVKeyboardShown, - GetLibinputEventForVKeyboard getLibinputEventForVKeyboard, - GetLibinputEventForVTrackpad getLibinputEventForVTrackpad + GetLibinputEventForVKeyboard getLibinputEventForVKeyboard, + GetLibinputEventForVTrackpad getLibinputEventForVTrackpad, + ResetVTrackpadState resetVTrackpadState, + StopVTrackpadTimer stopVTrackpadTimer ); private: @@ -146,14 +109,14 @@ private: void OnDeviceAdded(std::string path); void OnDeviceRemoved(std::string path); void InitRightButtonAreaConfig(); - void InjectKeyEvent(libinput_event_touch* touch, int32_t keyCode, libinput_key_state state, int64_t frameTime); #ifdef OHOS_BUILD_ENABLE_VKEYBOARD void HandleVFullKeyboardMessages( libinput_event *event, int64_t frameTime, libinput_event_type eventType, libinput_event_touch *touch); void HandleVKeyboardMessage(VKeyboardEventType eventType, std::vector &keyboardEvents, int64_t frameTime); void HandleVTrackpadMessage(VTrackpadEventType eventType, std::vector &events, - int64_t frameTime, libinput_event_touch *touch); + int64_t frameTime, libinput_event_touch *touch, + libinput_event *event, bool& delayvtpDestroy); bool IsVKeyboardActivationDropEvent(libinput_event_touch* touch, libinput_event_type eventType); void InjectEventForTwoFingerOnTouchpad(libinput_event_touch* touch, libinput_event_type eventType, int64_t frameTime); @@ -161,22 +124,26 @@ private: bool IsCursorInCastWindow(); int32_t ConvertToTouchEventType(libinput_event_type eventType); void HandleHWKeyEventForVKeyboard(libinput_event* event); - void ShowMouseCursor(); void HideMouseCursorTemporary(); double GetAccumulatedPressure(int touchId, int32_t eventType, double touchPressure); - bool SkipTouchMove(int touchId, int32_t eventType); // compress touch move events in consecutive two frame void DelayInjectKeyEventCallback(); - bool CreateVKeyboardDelayTimer(libinput_event *event, int32_t delayMs, libinput_event *keyEvent); + bool CreateVKeyboardDelayTimer(int32_t delayMs, libinput_event *keyEvent); void StartVKeyboardDelayTimer(int32_t delayMs); bool GetIsCaptureMode(); + void SafeDestroyVKeyboardDelayedEvent(); + libinput_event_touch* SafeGetVTrackPadTouchEvent(); + void SafeDestroyVTrackPadDelayedEvent(); + + void DelayInjectReleaseCallback(); + void DelayInjectPressReleaseCallback(); void UpdateBootFlag(); - VTPSwipeStateType vtpSwipeState_ = VTPSwipeStateType::SWIPE_END; - libinput_event *vkbDelayedEvent_ = nullptr; libinput_event *vkbDelayedKeyEvent_ = nullptr; - int32_t vkbDelayedKeyCode_ = 0; - std::chrono::system_clock::time_point vtpSingleTapDownTime; - const double vtpSingleTapThreshold = 0.18; // s + libinput_event *vtpDelayedEvent_ = nullptr; + std::mutex vtrDelayedMutex_; + int32_t vkbTimerId_ { -1 }; + int32_t vtpTimerId_ { -1 }; + // set as true once subscriber succeeded. std::atomic_bool hasInitSubscriber_ { false }; static std::atomic_bool isBootCompleted_; @@ -193,6 +160,8 @@ private: IsVKeyboardShown isVKeyboardShown_ { nullptr }; GetLibinputEventForVKeyboard getLibinputEventForVKeyboard_ { nullptr }; GetLibinputEventForVTrackpad getLibinputEventForVTrackpad_ { nullptr }; + ResetVTrackpadState resetVTrackpadState_ { nullptr }; + StopVTrackpadTimer stopVTrackpadTimer_ { nullptr }; int32_t deviceId; std::unordered_map> touchPoints_; static std::unordered_map keyCodes_; diff --git a/service/libinput_adapter/src/libinput_adapter.cpp b/service/libinput_adapter/src/libinput_adapter.cpp index bb4c3126ce84f9b936d0f325e4131bda9bbb1342..956453787f64867b5acd6963ca02233b044bac01 100644 --- a/service/libinput_adapter/src/libinput_adapter.cpp +++ b/service/libinput_adapter/src/libinput_adapter.cpp @@ -16,9 +16,6 @@ #include "libinput_adapter.h" #include -#ifdef OHOS_BUILD_ENABLE_VKEYBOARD -#include -#endif // OHOS_BUILD_ENABLE_VKEYBOARD #include "param_wrapper.h" #include "property_reader.h" @@ -28,9 +25,9 @@ #ifdef OHOS_BUILD_ENABLE_VKEYBOARD #include "key_event_value_transformation.h" #include "timer_manager.h" -#include #include "common_event_manager.h" #include "common_event_support.h" +#include "parameters.h" #endif // OHOS_BUILD_ENABLE_VKEYBOARD #include "multimodal_input_plugin_manager.h" @@ -48,27 +45,26 @@ constexpr int32_t MIN_RIGHT_BTN_AREA_PERCENT { 0 }; constexpr int32_t MAX_RIGHT_BTN_AREA_PERCENT { 100 }; constexpr int32_t INVALID_RIGHT_BTN_AREA { -1 }; #ifdef OHOS_BUILD_ENABLE_VKEYBOARD +constexpr uint32_t VKEY_TP_LB_ID { 272 }; +constexpr uint32_t VKEY_TP_SEAT_BTN_COUNT_NONE { 0 }; constexpr uint32_t KEY_CAPSLOCK { 58 }; constexpr uint32_t LIBINPUT_KEY_VOLUME_DOWN { 114 }; constexpr uint32_t LIBINPUT_KEY_VOLUME_UP { 115 }; constexpr uint32_t LIBINPUT_KEY_POWER { 116 }; constexpr uint32_t LIBINPUT_KEY_FN { 240 }; -constexpr float SCREEN_CAPTURE_WINDOW_ZORDER { 8000.0 }; -constexpr double VTP_LEFT_BUTTON_DELTA_X { 0.0 }; -constexpr double VTP_LEFT_BUTTON_DELTA_Y { -1.0 }; constexpr uint32_t VKEY_PINCH_FIRST_FINGER_ID { 0 }; constexpr uint32_t VKEY_PINCH_SECOND_FINGER_ID { 1 }; constexpr float VKEY_RAW_COORDINATE_RATIO { 8.0 }; constexpr uint32_t VKEY_PINCH_CURSOR_FAKE_DX { 1 }; -constexpr uint32_t WINDOW_NAME_TYPE_SCHREENSHOT { 1 }; enum class VKeyboardTouchEventType : int32_t { TOUCH_DOWN = 0, TOUCH_UP = 1, TOUCH_MOVE = 2, TOUCH_FRAME = 3, }; -#define SCREEN_RECORD_WINDOW_WIDTH 400 -#define SCREEN_RECORD_WINDOW_HEIGHT 200 +constexpr int32_t WAIT_TIME_MS_STAP { 180 }; // milliseconds touch up delay for Single TAP +constexpr int32_t WAIT_TIME_MS_DTAP { 60 }; // milliseconds touch up delay for Double TAP +constexpr int32_t EXPIRED_TIMER_ID { -1 }; #else // OHOS_BUILD_ENABLE_VKEYBOARD constexpr uint32_t KEY_CAPSLOCK { 58 }; #endif // OHOS_BUILD_ENABLE_VKEYBOARD @@ -96,6 +92,21 @@ void HiLogFunc(struct libinput* input, libinput_log_priority priority, const cha } } // namespace +LibinputAdapter::~LibinputAdapter() +{ +#ifdef OHOS_BUILD_ENABLE_VKEYBOARD + if (TimerMgr->IsExist(vkbTimerId_)) { + TimerMgr->RemoveTimer(vkbTimerId_); + SafeDestroyVKeyboardDelayedEvent(); + } + if (TimerMgr->IsExist(vtpTimerId_)) { + TimerMgr->RemoveTimer(vtpTimerId_); + SafeDestroyVTrackPadDelayedEvent(); + } +#endif // OHOS_BUILD_ENABLE_VKEYBOARD + MMI_HILOGI("~LibinputAdapter"); +} + int32_t LibinputAdapter::DeviceLedUpdate(struct libinput_device *device, int32_t funcKey, bool enable) { CHKPR(device, RET_ERR); @@ -296,7 +307,9 @@ void LibinputAdapter::InitVKeyboard(HandleTouchPoint handleTouchPoint, IsFloatingKeyboard isFloatingKeyboard, IsVKeyboardShown isVKeyboardShown, GetLibinputEventForVKeyboard getLibinputEventForVKeyboard, - GetLibinputEventForVTrackpad getLibinputEventForVTrackpad) + GetLibinputEventForVTrackpad getLibinputEventForVTrackpad, + ResetVTrackpadState resetVTrackpadState, + StopVTrackpadTimer stopVTrackpadTimer) { handleTouchPoint_ = handleTouchPoint; hardwareKeyEventDetected_ = hardwareKeyEventDetected; @@ -305,7 +318,8 @@ void LibinputAdapter::InitVKeyboard(HandleTouchPoint handleTouchPoint, isVKeyboardShown_ = isVKeyboardShown; getLibinputEventForVKeyboard_ = getLibinputEventForVKeyboard; getLibinputEventForVTrackpad_ = getLibinputEventForVTrackpad; - + resetVTrackpadState_ = resetVTrackpadState; + stopVTrackpadTimer_ = stopVTrackpadTimer; // init touch device Id. deviceId = -1; } @@ -313,111 +327,122 @@ void LibinputAdapter::InitVKeyboard(HandleTouchPoint handleTouchPoint, #ifdef OHOS_BUILD_ENABLE_VKEYBOARD void LibinputAdapter::DelayInjectKeyEventCallback() { - MMI_HILOGI("Delayed done for kc:%{private}d.", vkbDelayedKeyCode_); - CHKPV(vkbDelayedEvent_); - libinput_event_touch *touch = libinput_event_get_touch_event(vkbDelayedEvent_); - CHKPV(touch); - CHKPV(funInputEvent_); int64_t frameTime = GetSysClockTime(); - funInputEvent_(vkbDelayedKeyEvent_, frameTime); + std::lock_guard guard(vtrDelayedMutex_); + if (vkbDelayedKeyEvent_ != nullptr && funInputEvent_ != nullptr) { + funInputEvent_(vkbDelayedKeyEvent_, frameTime); + free(vkbDelayedKeyEvent_); + vkbDelayedKeyEvent_ = nullptr; + } + vkbTimerId_ = EXPIRED_TIMER_ID; +} + +libinput_event_touch* LibinputAdapter::SafeGetVTrackPadTouchEvent() +{ + std::lock_guard guard(vtrDelayedMutex_); + CHKPP(vtpDelayedEvent_); + return libinput_event_get_touch_event(vtpDelayedEvent_); +} + +void LibinputAdapter::SafeDestroyVKeyboardDelayedEvent() +{ + std::lock_guard guard(vtrDelayedMutex_); + vkbTimerId_ = EXPIRED_TIMER_ID; + CHKPV(vkbDelayedKeyEvent_); free(vkbDelayedKeyEvent_); vkbDelayedKeyEvent_ = nullptr; - libinput_event_destroy(vkbDelayedEvent_); - vkbDelayedEvent_ = nullptr; +} + +void LibinputAdapter::SafeDestroyVTrackPadDelayedEvent() +{ + std::lock_guard guard(vtrDelayedMutex_); + vtpTimerId_ = EXPIRED_TIMER_ID; + stopVTrackpadTimer_(); + CHKPV(vtpDelayedEvent_); + libinput_event_destroy(vtpDelayedEvent_); + vtpDelayedEvent_ = nullptr; } // return true if timer has started successfully. -bool LibinputAdapter::CreateVKeyboardDelayTimer(libinput_event *event, int32_t delayMs, libinput_event *keyEvent) +bool LibinputAdapter::CreateVKeyboardDelayTimer(int32_t delayMs, libinput_event *keyEvent) { - if (event == nullptr || keyEvent == nullptr) { + if (keyEvent == nullptr) { return false; } - if (vkbDelayedEvent_ != nullptr) { + std::lock_guard guard(vtrDelayedMutex_); + if (vkbDelayedKeyEvent_ != nullptr) { MMI_HILOGI("A delayed event is pending, skip delay msg, Delay=%{public}d", delayMs); return false; } - - vkbDelayedEvent_ = event; vkbDelayedKeyEvent_ = keyEvent; - MMI_HILOGD("Create the delayed event Delay=%{public}d", delayMs); + StartVKeyboardDelayTimer(delayMs); + MMI_HILOGI("Create the delayed event, Delay=%{public}d, timer Id=%{public}d", vkbTimerId_, delayMs); return true; } void LibinputAdapter::StartVKeyboardDelayTimer(int32_t delayMs) { - TimerMgr->AddTimer(delayMs, 1, [this]() { + vkbTimerId_ = TimerMgr->AddTimer(delayMs, 1, [this]() { DelayInjectKeyEventCallback(); - }, "LibinputAdapter-StartVKeyboardDelayTimer"); + }); } bool LibinputAdapter::GetIsCaptureMode() { bool isCaptureMode = false; bool isFloating = (isFloatingKeyboard_ != nullptr) ? isFloatingKeyboard_() : false; - InputWindowsManager* inputWindowsManager = static_cast(WIN_MGR.get()); if (inputWindowsManager == nullptr) { return false; } - isCaptureMode = inputWindowsManager->IsCaptureMode() && isFloating; - MMI_HILOGD("Currently keyboard will %s consume touch points", (isCaptureMode ? "not" : "")); + MMI_HILOGD("isCaptureMode=%{public}d", isCaptureMode); return isCaptureMode; } -#endif // OHOS_BUILD_ENABLE_VKEYBOARD -#ifdef OHOS_BUILD_ENABLE_VKEYBOARD void LibinputAdapter::HandleVFullKeyboardMessages( libinput_event *event, int64_t frameTime, libinput_event_type eventType, libinput_event_touch *touch) { // delay the event destroy. - bool delayDestroy = false; - int32_t confirmedDelayMs(0); - + bool delayvtpDestroy = false; if (getLibinputEventForVKeyboard_ == nullptr || getLibinputEventForVTrackpad_ == nullptr) { return; } + // handle trackpad messages. + while (true) { + std::vector events; + VTrackpadEventType eventType = (VTrackpadEventType)getLibinputEventForVTrackpad_(touch, events); + if (eventType == VTrackpadEventType::NoTrackpadEvent) { + break; + } + HandleVTrackpadMessage(eventType, events, frameTime, touch, event, delayvtpDestroy); + } + // handle keyboard messages. while (true) { int32_t delayMs(0); std::vector keyEvents; VKeyboardEventType eventType = (VKeyboardEventType)getLibinputEventForVKeyboard_(touch, delayMs, keyEvents); - if (eventType == VKeyboardEventType::NoKeyboardEvent || keyEvents.size() == 0) { + if (eventType == VKeyboardEventType::NoKeyboardEvent || + (keyEvents.empty() && eventType != VKeyboardEventType::HideCursor)) { break; } // if need to delay, not injecting but store them. Limit to up event. - if (delayMs > 0 && eventType == VKeyboardEventType::StopLongPress && !delayDestroy) { - // start delaying. - delayDestroy = CreateVKeyboardDelayTimer(event, delayMs, *keyEvents.begin()); - if (delayDestroy) { - // create and delay this event. - confirmedDelayMs = delayMs; - continue; - } + if (delayMs > 0 && eventType == VKeyboardEventType::StopLongPress && + CreateVKeyboardDelayTimer(delayMs, keyEvents.front())) { + // could skip the handling now, create the delayed events. + continue; } HandleVKeyboardMessage(eventType, keyEvents, frameTime); } - // handle trackpad messages. - while (true) { - std::vector events; - VTrackpadEventType eventType = (VTrackpadEventType)getLibinputEventForVTrackpad_(touch, events); - if (eventType == VTrackpadEventType::NoTrackpadEvent) { - break; - } - - HandleVTrackpadMessage(eventType, events, frameTime, touch); - } - if (eventType == LIBINPUT_EVENT_TOUCH_FRAME) { // still let frame info go through. funInputEvent_(event, frameTime); } - if (delayDestroy) { - StartVKeyboardDelayTimer(confirmedDelayMs); - } else { + if (!delayvtpDestroy) { libinput_event_destroy(event); } } @@ -427,9 +452,9 @@ void LibinputAdapter::HandleVKeyboardMessage(VKeyboardEventType eventType, { bool newCapsLockState = false; bool libinputCapsLockOn = false; + std::shared_ptr keyEvent = KeyEventHdr->GetKeyEvent(); if (!keyboardEvents.empty()) { // check current caps state. - std::shared_ptr keyEvent = KeyEventHdr->GetKeyEvent(); auto device = libinput_event_get_device(keyboardEvents.front()); if (keyEvent != nullptr && device != nullptr) { newCapsLockState = keyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); @@ -441,27 +466,28 @@ void LibinputAdapter::HandleVKeyboardMessage(VKeyboardEventType eventType, } switch (eventType) { case VKeyboardEventType::StopLongPress: - [[fallthrough]]; + [[fallthrough]]; case VKeyboardEventType::NormalKeyboardEvent: { for (auto event : keyboardEvents) { + CHKPC(event); funInputEvent_(event, frameTime); free(event); - event = nullptr; } + keyboardEvents.clear(); break; } case VKeyboardEventType::UpdateCaps: { for (auto event : keyboardEvents) { + CHKPC(event); funInputEvent_(event, frameTime); free(event); - event = nullptr; } + keyboardEvents.clear(); newCapsLockState = !newCapsLockState; - std::shared_ptr keyEvent = KeyEventHdr->GetKeyEvent(); if (keyEvent != nullptr) { - keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn); + keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, newCapsLockState); } - MultiKeyboardSetLedState(isCapsLockOn); + MultiKeyboardSetLedState(newCapsLockState); break; } case VKeyboardEventType::HideCursor: { @@ -471,7 +497,6 @@ void LibinputAdapter::HandleVKeyboardMessage(VKeyboardEventType eventType, default: break; } - keyboardEvents.clear(); if (libinputCapsLockOn != newCapsLockState) { // if a mismatch is found, sync it now. libinput_toggle_caps_key(); @@ -479,9 +504,10 @@ void LibinputAdapter::HandleVKeyboardMessage(VKeyboardEventType eventType, } void LibinputAdapter::HandleVTrackpadMessage(VTrackpadEventType eventType, std::vector &events, - int64_t frameTime, libinput_event_touch *touch) + int64_t frameTime, libinput_event_touch *touch, + libinput_event *event, bool& delayvtpDestroy) { - if (eventType != VTrackpadEventType::NormalTrackpadEvent) { + if (eventType == VTrackpadEventType::NoTrackpadEvent) { return; } @@ -507,41 +533,141 @@ void LibinputAdapter::HandleVTrackpadMessage(VTrackpadEventType eventType, std:: } } events.clear(); + if (eventType == VTrackpadEventType::SingleTap) { + std::lock_guard guard(vtrDelayedMutex_); + delayvtpDestroy = true; + vtpDelayedEvent_ = event; + vtpTimerId_ = TimerMgr->AddTimer(WAIT_TIME_MS_STAP, 1, [this]() { DelayInjectReleaseCallback(); }); + MMI_HILOGI("SINGLE_TAP: delay, delayedtime=%{private}d, timer id=%{public}d", WAIT_TIME_MS_STAP, vtpTimerId_); + } else if (eventType == VTrackpadEventType::DoubleTap) { + std::lock_guard guard(vtrDelayedMutex_); + delayvtpDestroy = true; + vtpDelayedEvent_ = event; + vtpTimerId_ = TimerMgr->AddTimer(WAIT_TIME_MS_DTAP, 1, [this]() { DelayInjectPressReleaseCallback(); }); + MMI_HILOGI("DOUBLE_TAP: delay, delayedtime=%{private}d, timer id=%{public}d", WAIT_TIME_MS_DTAP, vtpTimerId_); + } else if (eventType == VTrackpadEventType::RemoveTimer) { + MMI_HILOGI("Remove timer, id=%{public}d", vtpTimerId_); + TimerMgr->RemoveTimer(vtpTimerId_); + SafeDestroyVTrackPadDelayedEvent(); + } } -void LibinputAdapter::InjectEventForCastWindow(libinput_event_touch* touch) +void LibinputAdapter::DelayInjectPressReleaseCallback() { + libinput_event_touch *touch = SafeGetVTrackPadTouchEvent(); + if (touch == nullptr || funInputEvent_ == nullptr) { + SafeDestroyVTrackPadDelayedEvent(); + return; + } int64_t frameTime = GetSysClockTime(); - InjectEventForTwoFingerOnTouchpad(touch, libinput_event_type::LIBINPUT_EVENT_TOUCHPAD_UP, frameTime); + event_pointer pDownEvent; + pDownEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_TAP; + pDownEvent.button = VKEY_TP_LB_ID; + pDownEvent.seat_button_count = VKEY_TP_SEAT_BTN_COUNT_NONE; + pDownEvent.state = libinput_button_state::LIBINPUT_BUTTON_STATE_PRESSED; + libinput_event_pointer *lpDownEvent = libinput_create_pointer_event(touch, pDownEvent); + if (lpDownEvent != nullptr) { + funInputEvent_((libinput_event *)lpDownEvent, frameTime); + free(lpDownEvent); + lpDownEvent = nullptr; + MMI_HILOGI("Virtual TrackPad send: LIBINPUT_EVENT_POINTER_TAP PRESSED"); + } + event_pointer pUpEvent; + pUpEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_TAP; + pUpEvent.button = VKEY_TP_LB_ID; + pUpEvent.seat_button_count = VKEY_TP_SEAT_BTN_COUNT_NONE; + pUpEvent.state = libinput_button_state::LIBINPUT_BUTTON_STATE_RELEASED; + libinput_event_pointer *lpUpEvent = libinput_create_pointer_event(touch, pUpEvent); + if (lpUpEvent != nullptr) { + funInputEvent_((libinput_event *)lpUpEvent, frameTime); + free(lpUpEvent); + lpUpEvent = nullptr; + MMI_HILOGI("Virtual TrackPad send: LIBINPUT_EVENT_POINTER_TAP RELEASED"); + } + resetVTrackpadState_(); + SafeDestroyVTrackPadDelayedEvent(); +} + +void LibinputAdapter::DelayInjectReleaseCallback() +{ + libinput_event_touch *touch = SafeGetVTrackPadTouchEvent(); + if (touch == nullptr || funInputEvent_ == nullptr) { + SafeDestroyVTrackPadDelayedEvent(); + return; + } + int64_t frameTime = GetSysClockTime(); + event_pointer pEvent; + pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_TAP; + pEvent.button = VKEY_TP_LB_ID; + pEvent.seat_button_count = VKEY_TP_SEAT_BTN_COUNT_NONE; + pEvent.state = libinput_button_state::LIBINPUT_BUTTON_STATE_RELEASED; + libinput_event_pointer *lpEvent = libinput_create_pointer_event(touch, pEvent); + if (lpEvent != nullptr) { + funInputEvent_((libinput_event *)lpEvent, frameTime); + free(lpEvent); + lpEvent = nullptr; + MMI_HILOGI("Virtual TrackPad send: LIBINPUT_EVENT_POINTER_TAP RELEASED"); + } + resetVTrackpadState_(); + SafeDestroyVTrackPadDelayedEvent(); +} +void LibinputAdapter::InjectEventForTwoFingerOnTouchpad(libinput_event_touch* touch, + libinput_event_type eventType, int64_t frameTime) +{ event_touch tEvent; + tEvent.event_type = eventType; tEvent.seat_slot = VKEY_PINCH_FIRST_FINGER_ID; + libinput_event_touch* ltEvent = libinput_create_touch_event(touch, tEvent); + if (ltEvent != nullptr) { + funInputEvent_((libinput_event*)ltEvent, frameTime); + free(ltEvent); + ltEvent = nullptr; + } + tEvent.seat_slot = VKEY_PINCH_SECOND_FINGER_ID; + ltEvent = libinput_create_touch_event(touch, tEvent); + if (ltEvent != nullptr) { + funInputEvent_((libinput_event*)ltEvent, frameTime); + free(ltEvent); + ltEvent = nullptr; + } +} +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; tEvent.seat_slot = 0; tEvent.slot = 0; - ltEvent = libinput_create_touch_event(touch, tEvent); - funInputEvent_((libinput_event*)ltEvent, frameTime); - free(ltEvent); - ltEvent = nullptr; - + libinput_event_touch* ltEvent = libinput_create_touch_event(touch, tEvent); + if (ltEvent != nullptr) { + funInputEvent_((libinput_event*)ltEvent, frameTime); + free(ltEvent); + ltEvent = nullptr; + } tEvent.event_type = libinput_event_type::LIBINPUT_EVENT_TOUCH_UP; ltEvent = libinput_create_touch_event(touch, tEvent); - funInputEvent_((libinput_event*)ltEvent, frameTime); - free(ltEvent); - ltEvent = nullptr; - + if (ltEvent != nullptr) { + funInputEvent_((libinput_event*)ltEvent, frameTime); + free(ltEvent); + ltEvent = nullptr; + } event_pointer pEvent; pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_MOTION_TOUCHPAD; pEvent.delta_raw_x = VKEY_PINCH_CURSOR_FAKE_DX; pEvent.delta_raw_y = 0; libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent); - funInputEvent_((libinput_event*)lpEvent, frameTime); - free(lpEvent); - lpEvent = nullptr; + if (lpEvent != nullptr) { + funInputEvent_((libinput_event*)lpEvent, frameTime); + free(lpEvent); + lpEvent = nullptr; + } } bool LibinputAdapter::IsCursorInCastWindow() @@ -603,19 +729,12 @@ void LibinputAdapter::HandleHWKeyEventForVKeyboard(libinput_event* event) } } -void LibinputAdapter::ShowMouseCursor() -{ - if (!CursorDrawingComponent::GetInstance().GetMouseDisplayState()) { - MMI_HILOGI("Found hidden mouse cursor during trackpad operation, show it."); - CursorDrawingComponent::GetInstance().SetMouseDisplayState(true); - } -} - void LibinputAdapter::HideMouseCursorTemporary() { MMI_HILOGI("VKeyboard hide mouse."); - if (CursorDrawingComponent::GetInstance().GetMouseDisplayState()) { - CursorDrawingComponent::GetInstance().SetMouseDisplayState(false); + auto& instance = CursorDrawingComponent::GetInstance(); + if (instance.GetMouseDisplayState()) { + instance.SetMouseDisplayState(false); } } @@ -650,7 +769,7 @@ bool LibinputAdapter::IsVKeyboardActivationDropEvent(libinput_event_touch* touch break; } case VKeyboardActivation::ACTIVATED: { - MMI_HILOGI("activation state: %{public}d", static_cast(activateState)); + MMI_HILOGD("activation state: %{public}d", static_cast(activateState)); break; } case VKeyboardActivation::TOUCH_CANCEL: { @@ -665,7 +784,7 @@ bool LibinputAdapter::IsVKeyboardActivationDropEvent(libinput_event_touch* touch break; } case VKeyboardActivation::TOUCH_DROP: { - MMI_HILOGI("activation state: %{public}d, dropping event", static_cast(activateState)); + MMI_HILOGD("activation state: %{public}d, dropping event", static_cast(activateState)); if (eventType != LIBINPUT_EVENT_TOUCH_UP) { bDropEventFlag = true; } @@ -684,14 +803,23 @@ bool LibinputAdapter::IsVKeyboardActivationDropEvent(libinput_event_touch* touch void LibinputAdapter::UpdateBootFlag() { + // check booted flag from parameters. + if (!isBootCompleted_) { + isBootCompleted_ = OHOS::system::GetBoolParameter("bootevent.boot.completed", false); + if (isBootCompleted_) { + MMI_HILOGI("backend booted from Parameter manager (mainly due to process restart)=%{public}d", + static_cast(isBootCompleted_)); + return; + } + } + // check booted flag from UI status. if (!isBootCompleted_ && isVKeyboardShown_ != nullptr) { isBootCompleted_ = isVKeyboardShown_(); if (isBootCompleted_) { - MMI_HILOGI("backend booted from outside (mainly due to process restart)=%{public}d", + MMI_HILOGI("backend booted from VKeyboard UI (mainly due to process restart)=%{public}d", static_cast(isBootCompleted_)); } } - // could also check SA status here. } #endif // OHOS_BUILD_ENABLE_VKEYBOARD @@ -790,19 +918,13 @@ void LibinputAdapter::OnEventHandler() touchPoints_.erase(pos); } } - int32_t longAxis = libinput_event_get_touch_contact_long_axis(touch); int32_t shortAxis = libinput_event_get_touch_contact_short_axis(touch); - MMI_HILOGD("touch event. deviceId:%{private}d, touchId:%{private}d, x:%{private}d, y:%{private}d, \ -type:%{private}d, accPressure:%{private}f, longAxis:%{private}d, shortAxis:%{private}d", - deviceId, + MMI_HILOGD("touch event. touchId:%{private}d, x:%{private}f, y:%{private}f, type:%{private}d", touchId, - static_cast(x), - static_cast(y), - static_cast(eventType), - accumulatedPressure, - longAxis, - shortAxis); + x, + y, + static_cast(eventType)); if (!isInsideWindow && handleTouchPoint_ != nullptr && handleTouchPoint_(x, y, touchId, touchEventType, accumulatedPressure, longAxis, shortAxis) == 0) { @@ -819,15 +941,12 @@ type:%{private}d, accPressure:%{private}f, longAxis:%{private}d, shortAxis:%{pri struct libinput_event_keyboard* keyboardEvent = libinput_event_get_keyboard_event(event); std::shared_ptr keyEvent = KeyEventHdr->GetKeyEvent(); - if (libinput_event_keyboard_get_key_state(keyboardEvent) == LIBINPUT_KEY_STATE_PRESSED - && libinput_event_keyboard_get_key(keyboardEvent) == KEY_CAPSLOCK - && keyEvent != nullptr) { + if (libinput_event_keyboard_get_key_state(keyboardEvent) == LIBINPUT_KEY_STATE_PRESSED && + libinput_event_keyboard_get_key(keyboardEvent) == KEY_CAPSLOCK && keyEvent != nullptr) { bool oldCapsLockOn = keyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); - HandleHWKeyEventForVKeyboard(event); funInputEvent_(event, frameTime); libinput_event_destroy(event); - MultiKeyboardSetLedState(!oldCapsLockOn); keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !oldCapsLockOn); libinput_toggle_caps_key(); diff --git a/service/module_loader/src/mmi_service.cpp b/service/module_loader/src/mmi_service.cpp index 4c48c599e2a5bf4088604116ec247a3a0b5b947c..3dce93b988e551938f6bbf43f3430da327ea2a74 100644 --- a/service/module_loader/src/mmi_service.cpp +++ b/service/module_loader/src/mmi_service.cpp @@ -172,19 +172,6 @@ typedef int32_t (*HANDLE_TOUCHPOINT_TYPE)( double screenX, double screenY, int touchId, int32_t eventType, double touchPressure, int32_t longAxis, int32_t shortAxis); HANDLE_TOUCHPOINT_TYPE handleTouchPoint_ = nullptr; -typedef int32_t (*STATEMACINEMESSAGQUEUE_GETLIBINPUTMESSAGE_TYPE)( - int& delayMs, int& toggleCodeSecond, int& keyCode); -STATEMACINEMESSAGQUEUE_GETLIBINPUTMESSAGE_TYPE statemachineMessageQueue_getLibinputMessage_ = nullptr; -typedef void (*TRACKPADENGINE_GETALLTOUCHMESSAGE_TYPE)( - std::vector>& retMsgList); -TRACKPADENGINE_GETALLTOUCHMESSAGE_TYPE trackPadEngine_getAllTouchMessage_ = nullptr; -typedef void (*TRACKPADENGINE_CLEARTOUCHMESSAGE_TYPE)(); -TRACKPADENGINE_CLEARTOUCHMESSAGE_TYPE trackPadEngine_clearTouchMessage_ = nullptr; -typedef void (*TRACKPADENGINE_GETALLKEYMESSAGE_TYPE)( - std::vector>& retMsgList); -TRACKPADENGINE_GETALLKEYMESSAGE_TYPE trackPadEngine_getAllKeyMessage_ = nullptr; -typedef void (*TRACKPADENGINE_CLEARKEYMESSAGE_TYPE)(); -TRACKPADENGINE_CLEARKEYMESSAGE_TYPE trackPadEngine_clearKeyMessage_ = nullptr; typedef int32_t (*VKEYBOARD_CREATEVKEYBOARDDEVICE_TYPE)(IRemoteObject* &vkeyboardDevice); VKEYBOARD_CREATEVKEYBOARDDEVICE_TYPE vkeyboard_createVKeyboardDevice_ = nullptr; typedef int32_t (*VKEYBOARD_ONFUNCKEYEVENT_TYPE)(std::shared_ptr funcKeyEvent); @@ -203,6 +190,10 @@ GET_LIBINPUT_EVENT_FOR_VKEYBOARD_TYPE getLibinputEventForVKeyboard_ = nullptr; typedef int32_t (*GET_LIBINPUT_EVENT_FOR_VTRACKPAD_TYPE)( libinput_event_touch *touch, std::vector& events); GET_LIBINPUT_EVENT_FOR_VTRACKPAD_TYPE getLibinputEventForVTrackpad_ = nullptr; +typedef void (*RESET_VTRACKPAD_STATE)(); +RESET_VTRACKPAD_STATE resetVTrackpadState_ = nullptr; +typedef void (*STOP_VTRACKPAD_TIMER)(); +STOP_VTRACKPAD_TIMER stopVTrackpadTimer_ = nullptr; #endif // OHOS_BUILD_ENABLE_VKEYBOARD #ifdef OHOS_BUILD_PC_PRIORITY constexpr int32_t PC_PRIORITY { 2 }; @@ -4252,13 +4243,19 @@ void MMIService::InitVKeyboardFuncHandler() g_VKeyboardHandle, "GetLibinputEventForVKeyboard"); getLibinputEventForVTrackpad_ = (GET_LIBINPUT_EVENT_FOR_VTRACKPAD_TYPE)dlsym( g_VKeyboardHandle, "GetLibinputEventForVTrackpad"); + resetVTrackpadState_ = (RESET_VTRACKPAD_STATE)dlsym( + g_VKeyboardHandle, "ResetVTrackpadState"); + stopVTrackpadTimer_ = (STOP_VTRACKPAD_TIMER)dlsym( + g_VKeyboardHandle, "StopVTrackpadTimer"); libinputAdapter_.InitVKeyboard(handleTouchPoint_, vkeyboard_hardwareKeyEventDetected_, vkeyboard_getKeyboardActivationState_, gaussiankeyboard_isFloatingKeyboard_, vkeyboard_isShown_, getLibinputEventForVKeyboard_, - getLibinputEventForVTrackpad_); + getLibinputEventForVTrackpad_, + resetVTrackpadState_, + stopVTrackpadTimer_); } } }