mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-18 16:04:40 -04:00
sim btn_touch
Signed-off-by: hwzhangchuang <zhangchuang.zhang@huawei.com>
This commit is contained in:
@@ -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(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(event);
|
||||
}
|
||||
DHLOGD("RecordDeviceChangeStates end.");
|
||||
}
|
||||
|
||||
size_t InputHub::CollectEvent(RawEvent *buffer, size_t &capacity, Device *device, struct input_event readBuffer[],
|
||||
|
||||
@@ -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(const RawEvent &event);
|
||||
/*
|
||||
* Scan the input device node and save info.
|
||||
*/
|
||||
|
||||
@@ -65,7 +65,9 @@ public:
|
||||
void RefreshABSPosition(const std::string &dhId, int32_t absX, int32_t absY);
|
||||
std::pair<int32_t, int32_t> 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
|
||||
*
|
||||
|
||||
@@ -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<int32_t, int32_t> 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<RawEvent> 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<RawEvent> 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,
|
||||
|
||||
Reference in New Issue
Block a user