mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-19 17:43:35 -04:00
@@ -201,6 +201,12 @@ size_t InputHub::GetEvents(RawEvent *buffer, size_t bufferSize)
|
||||
return event - buffer;
|
||||
}
|
||||
|
||||
bool InputHub::IsTouchPad(Device *device)
|
||||
{
|
||||
return ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) &&
|
||||
IsTouchPad(device->identifier);
|
||||
}
|
||||
|
||||
bool InputHub::IsTouchPad(const InputDevice &inputDevice)
|
||||
{
|
||||
std::string dhName = inputDevice.name;
|
||||
@@ -254,6 +260,13 @@ void InputHub::RecordDeviceChangeStates(Device *device, struct input_event readB
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +151,7 @@ private:
|
||||
bool ContainsNonZeroByte(const uint8_t *array, uint32_t startIndex, uint32_t endIndex);
|
||||
int64_t ProcessEventTimestamp(const input_event &event);
|
||||
bool IsTouchPad(const InputDevice &inputDevice);
|
||||
bool IsTouchPad(Device *device);
|
||||
|
||||
/*
|
||||
* this macro is used to tell if "bit" is set in "array"
|
||||
|
||||
@@ -320,7 +320,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInputDhid(cons
|
||||
stopIndeedOnes.noSharingDhIds = stopIndeedDhIds;
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes);
|
||||
|
||||
DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1);
|
||||
DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, sessionId);
|
||||
|
||||
if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) {
|
||||
DHLOGE("All dhid stop sharing, sessionId: %d is closed.", sessionId);
|
||||
@@ -387,7 +387,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput
|
||||
stopIndeedOnes.noSharingDhIds = stopIndeedDhIds;
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes);
|
||||
|
||||
DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1);
|
||||
DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, toSinkSessionId);
|
||||
|
||||
if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) {
|
||||
DHLOGE("All dhid stop sharing, sessionId: %d is closed.", toSinkSessionId);
|
||||
|
||||
@@ -64,6 +64,16 @@ 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);
|
||||
/**
|
||||
* @brief check is one device in down state
|
||||
*
|
||||
* @param dhId the dhid
|
||||
* @return true in down state
|
||||
* @return false NOT in down state
|
||||
*/
|
||||
bool IsDhIdDown(const std::string &dhId);
|
||||
private:
|
||||
DInputState() = default;
|
||||
~DInputState();
|
||||
@@ -82,6 +92,7 @@ private:
|
||||
std::mutex absPosMtx_;
|
||||
// Record abs x/y of touchpad
|
||||
std::unordered_map<std::string, std::pair<int32_t, int32_t>> absPositionsMap_;
|
||||
std::atomic<int32_t> lastSessionId_ {0};
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -70,6 +70,7 @@ int32_t DInputState::RecordDhIds(const std::vector<std::string> &dhIds, DhIdStat
|
||||
if (state == DhIdState::THROUGH_OUT) {
|
||||
SimulateEventInjectToSrc(sessionId, dhIds);
|
||||
}
|
||||
lastSessionId_ = sessionId;
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -167,6 +168,49 @@ 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)
|
||||
{
|
||||
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);
|
||||
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 };
|
||||
RawEvent btnToolDoubleTapUpEv = { event.when, EV_KEY, BTN_TOOL_DOUBLETAP, KEY_UP_STATE, dhId, event.path };
|
||||
RawEvent mscEv1 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path };
|
||||
RawEvent sycReportEv1 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path };
|
||||
|
||||
RawEvent absMtSlot = { event.when, EV_ABS, ABS_MT_SLOT, 0x0, dhId, event.path };
|
||||
RawEvent absMtPosX1 = { event.when, EV_ABS, ABS_MT_POSITION_X, dx, dhId, event.path };
|
||||
RawEvent absMtPosY1 = { event.when, EV_ABS, ABS_MT_POSITION_Y, dy, dhId, event.path };
|
||||
RawEvent absPosX1 = { event.when, EV_ABS, ABS_X, dx, dhId, event.path };
|
||||
RawEvent absPosY1 = { event.when, EV_ABS, ABS_Y, dy, dhId, event.path };
|
||||
RawEvent mscEv2 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path };
|
||||
RawEvent sycReportEv2 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path };
|
||||
|
||||
RawEvent absMtPosX2 = { event.when, EV_ABS, ABS_MT_POSITION_X, dx, dhId, event.path };
|
||||
RawEvent absMtPosY2 = { event.when, EV_ABS, ABS_MT_POSITION_Y, dy, dhId, event.path };
|
||||
RawEvent btnMouseUpEv = { event.when, EV_KEY, BTN_MOUSE, KEY_UP_STATE, dhId, event.path };
|
||||
RawEvent absPosX2 = { event.when, EV_ABS, ABS_X, dx, dhId, event.path };
|
||||
RawEvent absPosY2 = { event.when, EV_ABS, ABS_Y, dy, dhId, event.path };
|
||||
RawEvent mscEv3 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path };
|
||||
RawEvent sycReportEv3 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path };
|
||||
|
||||
RawEvent touchTrackingIdEv2 = { 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 mscEv4 = { event.when, EV_MSC, MSC_TIMESTAMP, 0x0, dhId, event.path };
|
||||
RawEvent sycReportEv4 = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path };
|
||||
|
||||
std::vector<RawEvent> simEvents = {
|
||||
touchTrackingIdEv1, btnToolFingerDownEv, btnToolDoubleTapUpEv, mscEv1, sycReportEv1,
|
||||
absMtSlot, absMtPosX1, absMtPosY1, absPosX1, absPosY1, mscEv2, sycReportEv2,
|
||||
absMtPosX2, absMtPosY2, btnMouseUpEv, absPosX2, absPosY2, mscEv3, sycReportEv3,
|
||||
touchTrackingIdEv2, btnTouchUpEv, btnToolFingerUpEv, mscEv4, sycReportEv4 };
|
||||
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,
|
||||
@@ -200,6 +244,13 @@ std::pair<int32_t, int32_t> DInputState::GetAndClearABSPosition(const std::strin
|
||||
return absPos;
|
||||
}
|
||||
|
||||
bool DInputState::IsDhIdDown(const std::string &dhId)
|
||||
{
|
||||
std::lock_guard<std::mutex> mapLock(keyDownStateMapMtx_);
|
||||
auto iter = keyDownStateMap_.find(dhId);
|
||||
return iter != keyDownStateMap_.end();
|
||||
}
|
||||
|
||||
void DInputState::AddKeyDownState(struct RawEvent event)
|
||||
{
|
||||
std::lock_guard<std::mutex> mapLock(keyDownStateMapMtx_);
|
||||
|
||||
Reference in New Issue
Block a user