diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index aa8dc8a361983e4bec59bcd8b6fce398e8b40a41..141c761c5bcfa1ec1b52f19261fe33b1e7167e11 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -201,6 +201,11 @@ size_t InputHub::GetEvents(RawEvent *buffer, size_t bufferSize) return event - buffer; } +bool InputHub::IsCuror(Device *device) +{ + return device->classes & INPUT_DEVICE_CLASS_CURSOR; +} + bool InputHub::IsTouchPad(Device *device) { return ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) && @@ -218,6 +223,53 @@ bool InputHub::IsTouchPad(const InputDevice &inputDevice) return true; } +void InputHub::MatchAndDealEvent(Device *device, const RawEvent &event) +{ + // Deal key state + if (event.type == EV_KEY && event.code != BTN_TOOL_FINGER && event.value == KEY_DOWN_STATE) { + DInputState::GetInstance().AddKeyDownState(event); + RecordChangeEventLog(event); + } + + if (event.type == EV_KEY && event.value == KEY_UP_STATE) { + DInputState::GetInstance().RemoveKeyDownState(event); + RecordChangeEventLog(event); + } + + if (event.type == EV_KEY && event.value == KEY_REPEAT) { + DInputState::GetInstance().CheckAndSetLongPressedKeyOrder(event); + } + + if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_X || event.code == ABS_X)) { + DInputState::GetInstance().RefreshABSPosition(event.descriptor, event.value, -1); + } + + if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_Y || event.code == ABS_Y)) { + DInputState::GetInstance().RefreshABSPosition(event.descriptor, -1, event.value); + } + + if (IsTouchPad(device) && event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_UP_STATE && + !DInputState::GetInstance().IsDhIdDown(event.descriptor)) { + DHLOGI("Find touchpad BTN_MOUSE UP state that not down effective at sink side, dhId: %s", + event.descriptor.c_str()); + DInputState::GetInstance().SimulateTouchPadBtnMouseUpState(event.descriptor, event); + } + + if (IsTouchPad(device) && event.type == EV_KEY && event.code == BTN_TOUCH && event.value == KEY_UP_STATE && + !DInputState::GetInstance().IsDhIdDown(event.descriptor)) { + DHLOGI("Find touchpad BTN_TOUCH UP state that not down effective at sink side, dhId: %s", + event.descriptor.c_str()); + DInputState::GetInstance().SimulateTouchPadBtnTouchUpState(event.descriptor, event); + } + + if (IsCuror(device) && event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_UP_STATE && + !DInputState::GetInstance().IsDhIdDown(event.descriptor)) { + DHLOGI("Find mouse BTN_MOUSE UP state that not down effective at sink side, dhId: %s", + event.descriptor.c_str()); + DInputState::GetInstance().SimulateMouseBtnMouseUpState(event.descriptor, event); + } +} + void InputHub::RecordDeviceChangeStates(Device *device, struct input_event readBuffer[], const size_t count) { DHLOGD("RecordDeviceChangeStates enter."); @@ -229,46 +281,17 @@ void InputHub::RecordDeviceChangeStates(Device *device, struct input_event readB } for (size_t i = 0; i < count; i++) { - RawEvent event; const struct input_event& iev = readBuffer[i]; + RawEvent event; event.when = ProcessEventTimestamp(iev); event.type = iev.type; event.code = iev.code; event.value = iev.value; event.path = device->path; event.descriptor = isTouchEvent ? touchDescriptor : device->identifier.descriptor; - - // Deal key state - if (event.type == EV_KEY && event.code != BTN_TOOL_FINGER && event.value == KEY_DOWN_STATE) { - DInputState::GetInstance().AddKeyDownState(event); - RecordChangeEventLog(event); - } - - if (event.type == EV_KEY && event.value == KEY_UP_STATE) { - DInputState::GetInstance().RemoveKeyDownState(event); - RecordChangeEventLog(event); - } - - if (event.type == EV_KEY && event.value == KEY_REPEAT) { - DInputState::GetInstance().CheckAndSetLongPressedKeyOrder(event); - } - - if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_X || event.code == ABS_X)) { - DInputState::GetInstance().RefreshABSPosition(event.descriptor, event.value, -1); - } - - if (event.type == EV_ABS && (event.code == ABS_MT_POSITION_Y || event.code == ABS_Y)) { - DInputState::GetInstance().RefreshABSPosition(event.descriptor, -1, event.value); - } - - if (IsTouchPad(device) && event.type == EV_KEY && event.code == BTN_MOUSE && event.value == KEY_UP_STATE && - !DInputState::GetInstance().IsDhIdDown(event.descriptor)) { - DHLOGI("Find touchpad UP state that not down effective at sink side, dhId: %s", - event.descriptor.c_str()); - DInputState::GetInstance().SimulateTouchPadUpState(event.descriptor, event); - } - DHLOGD("RecordDeviceChangeStates end."); + MatchAndDealEvent(device, event); } + DHLOGD("RecordDeviceChangeStates end."); } size_t InputHub::CollectEvent(RawEvent *buffer, size_t &capacity, Device *device, struct input_event readBuffer[], diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 9e6e64c5db7dc0a737bbe4493c24a02afee7ad25..a2be41fb6a2b5491b001b15f6cbf929995f6996d 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -150,6 +150,7 @@ private: bool ContainsNonZeroByte(const uint8_t *array, uint32_t startIndex, uint32_t endIndex); int64_t ProcessEventTimestamp(const input_event &event); + bool IsCuror(Device *device); bool IsTouchPad(const InputDevice &inputDevice); bool IsTouchPad(Device *device); @@ -179,7 +180,7 @@ private: * Record Mouse/KeyBoard/TouchPad state such as key down. */ void RecordDeviceChangeStates(Device *device, struct input_event readBuffer[], const size_t count); - + void MatchAndDealEvent(Device *device, const RawEvent &event); /* * Scan the input device node and save info. */ diff --git a/services/state/include/dinput_state.h b/services/state/include/dinput_state.h index d16a9f99ee6e3d1e2cdd35807158a4ec21e1d2b3..c075d33da304737dd4628283020f2b31f69b8e28 100644 --- a/services/state/include/dinput_state.h +++ b/services/state/include/dinput_state.h @@ -65,7 +65,9 @@ public: void RefreshABSPosition(const std::string &dhId, int32_t absX, int32_t absY); std::pair GetAndClearABSPosition(const std::string &dhId); - void SimulateTouchPadUpState(const std::string &dhId, const struct RawEvent &event); + void SimulateTouchPadBtnMouseUpState(const std::string &dhId, const struct RawEvent &event); + void SimulateTouchPadBtnTouchUpState(const std::string &dhId, const struct RawEvent &event); + void SimulateMouseBtnMouseUpState(const std::string &dhId, const struct RawEvent &event); /** * @brief check is one device in down state * diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index 470c4f739887c3e74b4d1339ea22101fc34f6125..66cd0d2584b0eb93e55efd5b305dd24412445db0 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -168,12 +168,12 @@ void DInputState::SimulateBtnTouchEvent(const int32_t sessionId, const std::stri DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(sessionId, simEvents); } -void DInputState::SimulateTouchPadUpState(const std::string &dhId, const struct RawEvent &event) +void DInputState::SimulateTouchPadBtnMouseUpState(const std::string &dhId, const struct RawEvent &event) { std::pair touchPos = GetAndClearABSPosition(dhId); int32_t dx = touchPos.first; int32_t dy = touchPos.second; - DHLOGI("Sinmulate touch pad UP state to source, dhId: %s, dx: %d, dy: %d", dhId.c_str(), dx, dy); + DHLOGI("Sinmulate touch pad BTN_MOUSE UP state to source, dhId: %s, dx: %d, dy: %d", dhId.c_str(), dx, dy); int32_t simTrackingId = GetRandomInt32(); RawEvent touchTrackingIdEv1 = { event.when, EV_ABS, ABS_MT_TRACKING_ID, simTrackingId, dhId, event.path }; RawEvent btnToolFingerDownEv = { event.when, EV_KEY, BTN_TOOL_FINGER, KEY_DOWN_STATE, dhId, event.path }; @@ -211,6 +211,32 @@ void DInputState::SimulateTouchPadUpState(const std::string &dhId, const struct DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(lastSessionId_, simEvents); } +void DInputState::SimulateTouchPadBtnTouchUpState(const std::string &dhId, const struct RawEvent &event) +{ + DHLOGI("Sinmulate touch pad BTN_TOUCH UP state to source, dhId: %s", dhId.c_str()); + int32_t simTrackingId = GetRandomInt32(); + RawEvent touchTrackingIdEv = { event.when, EV_ABS, ABS_MT_TRACKING_ID, simTrackingId, dhId, event.path }; + RawEvent btnTouchUpEv = { event.when, EV_KEY, BTN_TOUCH, KEY_UP_STATE, dhId, event.path }; + RawEvent btnToolFingerUpEv = { event.when, EV_KEY, BTN_TOOL_FINGER, KEY_UP_STATE, dhId, event.path }; + RawEvent mscEv = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path }; + RawEvent sycReportEv = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; + + std::vector simEvents = { touchTrackingIdEv, btnTouchUpEv, btnToolFingerUpEv, mscEv, sycReportEv }; + DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(lastSessionId_, simEvents); +} + +void DInputState::SimulateMouseBtnMouseUpState(const std::string &dhId, const struct RawEvent &event) +{ + DHLOGI("Sinmulate Mouse BTN_MOUSE UP state to source, dhId: %s", dhId.c_str()); + int32_t scanId = GetRandomInt32(); + RawEvent mscScanEv = { event.when, EV_MSC, MSC_SCAN, scanId, dhId, event.path }; + RawEvent btnMouseUpEv = { event.when, EV_KEY, BTN_MOUSE, KEY_UP_STATE, dhId, event.path }; + RawEvent sycReportEv = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; + + std::vector simEvents = { mscScanEv, btnMouseUpEv, sycReportEv }; + DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsgBatch(lastSessionId_, simEvents); +} + void DInputState::SimulateNormalEvent(const int32_t sessionId, const std::string &dhId, const struct RawEvent &event) { DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhId,