70QOhosOptional<MouseEvent>
MouseEvent::createFromNativeEvent(
const ::Input_MouseEvent *event)
72 auto jsWindowId = JsWindowId(::OH_Input_GetMouseEventWindowId(event));
74 auto actionValue = ::OH_Input_GetMouseEventAction(event);
75 auto optMappedAction = tryMapMouseEventAction(actionValue);
76 if (!optMappedAction.has_value()) {
78 "%s: Filter for jsWindowId: %f, received unrecognized mouse event action: %d, event will be ignored",
79 Q_FUNC_INFO, jsWindowId.value(), actionValue);
83 auto buttonValue = ::OH_Input_GetMouseEventButton(event);
84 auto optMappedButton = tryMapMouseEventButton(buttonValue);
85 if (!optMappedButton.has_value()) {
87 "%s: Filter for jsWindowId: %f, received unrecognized mouse event action: %d, event will be ignored",
88 Q_FUNC_INFO, jsWindowId.value(), actionValue);
92 auto displayId = QOhosDisplayInfo::JsDisplayId(::OH_Input_GetMouseEventDisplayId(event));
93 auto displayPosition =
95 ::OH_Input_GetMouseEventDisplayX(event),
96 ::OH_Input_GetMouseEventDisplayY(event));
99 .jsWindowId = jsWindowId,
100 .jsDisplayId = displayId,
101 .button = optMappedButton.value(),
102 .action = optMappedAction.value(),
103 .displayPosition = displayPosition,
104 .globalPosition = mapFromDisplayToGlobal(displayPosition, displayId),
105 .actionTime = std::chrono::microseconds(::OH_Input_GetMouseEventActionTime(event)),
108 return makeQOhosOptional(mouseEvent);
111QOhosOptional<TouchEvent>
TouchEvent::createFromNativeEvent(
const ::Input_TouchEvent *event)
113 auto jsWindowId = JsWindowId(::OH_Input_GetTouchEventWindowId(event));
115 auto actionValue = ::OH_Input_GetTouchEventAction(event);
116 auto optMappedAction = tryMapTouchEventAction(actionValue);
117 if (!optMappedAction.has_value()) {
119 "%s: Filter for jsWindowId: %f, received unrecognized touch event action: %d, event will be ignored",
120 Q_FUNC_INFO, jsWindowId.value(), actionValue);
124 auto displayId = JsDisplayId(::OH_Input_GetTouchEventDisplayId(event));
125 auto displayPosition = QPoint(
126 ::OH_Input_GetTouchEventDisplayX(event),
127 ::OH_Input_GetTouchEventDisplayY(event));
130 .jsWindowId = jsWindowId,
131 .jsDisplayId = displayId,
132 .displayPosition = displayPosition,
133 .globalPosition = mapFromDisplayToGlobal(displayPosition, displayId),
134 .action = optMappedAction.value(),
135 .fingerId = ::OH_Input_GetTouchEventFingerId(event),
136 .actionTime = std::chrono::microseconds(::OH_Input_GetTouchEventActionTime(event)),
139 return makeQOhosOptional(keyEvent);
142QOhosOptional<KeyEvent>
KeyEvent::createFromNativeEvent(
const ::Input_KeyEvent *event)
144 auto jsWindowId = JsWindowId(::OH_Input_GetKeyEventWindowId(event));
146 auto actionValue = ::OH_Input_GetKeyEventAction(event);
147 auto optMappedAction = tryMapKeyEventAction(actionValue);
148 if (!optMappedAction.has_value()) {
150 "%s: Filter for jsWindowId: %f, received unrecognized key event action: %d, event will be ignored",
151 Q_FUNC_INFO, jsWindowId.value(), actionValue);
156 .jsWindowId = jsWindowId,
157 .actionTime = std::chrono::microseconds(::OH_Input_GetKeyEventActionTime(event)),
158 .action = optMappedAction.value(),
159 .keyCode = ::OH_Input_GetKeyEventKeyCode(event),
162 return makeQOhosOptional(keyEvent);
167 const auto sourceType = ::OH_ArkUI_UIInputEvent_GetSourceType(inputEvent);
168 if (sourceType == ::UI_INPUT_EVENT_SOURCE_TYPE_UNKNOWN)
169 qOhosWarning(QtForOhos) <<
"Obtained ArkUI unknown source type for input event";
170 return sourceType == ::UI_INPUT_EVENT_SOURCE_TYPE_TOUCH_SCREEN
171 ? QInputDevice::DeviceType::TouchScreen
172 : QInputDevice::DeviceType::TouchPad;
204 return NativeNodeMouseEvent {
205 .timestampMs = getInputEventTimeMs(event),
206 .localPosition = getPointerEventLocalPosition(event),
207 .displayPosition = getPointerEventDisplayPosition(event),
208 .globalPosition = getPointerEventGlobalPosition(event),
209 .button = callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_MouseEvent_GetMouseButton), event),
210 .action = callArkUi(Q_OHOS_NAMED_FUNC(::OH_ArkUI_MouseEvent_GetMouseAction), event),
211 .modifiers = readKeyModifiersFromOhosUiInputEvent(event),