diff --git a/frameworks/proxy/events/src/pointer_event.cpp b/frameworks/proxy/events/src/pointer_event.cpp index f6bb31783438067eac4741cd0328f7bdb0f2f283..b72ac03add21d9d1e22f6389bda8ae5c92bf3e1b 100644 --- a/frameworks/proxy/events/src/pointer_event.cpp +++ b/frameworks/proxy/events/src/pointer_event.cpp @@ -551,6 +551,8 @@ static const std::unordered_map pointerActionMap = { { PointerEvent::TOUCH_ACTION_SWIPE_RIGHT, "touch-swipe-right" }, { PointerEvent::TOUCH_ACTION_PINCH_OPENED, "touch-pinch-open" }, { PointerEvent::TOUCH_ACTION_PINCH_CLOSEED, "touch-pinch-close" }, + { PointerEvent::POINTER_ACTION_PROXIMITY_IN, "pen-proximity-in" }, + { PointerEvent::POINTER_ACTION_PROXIMITY_OUT, "pen-proximity-out" }, }; const char* PointerEvent::DumpPointerAction() const diff --git a/interfaces/native/innerkits/event/include/pointer_event.h b/interfaces/native/innerkits/event/include/pointer_event.h index 359b3533f6e8c8f5d00a25b6bc15829bafde334d..f5eafe13aa7eefd9734b11d3ba1a0d7ae2cafdcd 100644 --- a/interfaces/native/innerkits/event/include/pointer_event.h +++ b/interfaces/native/innerkits/event/include/pointer_event.h @@ -180,9 +180,18 @@ public: static constexpr int32_t POINTER_ACTION_FINGERPRINT_CLICK = 32; + static constexpr int32_t POINTER_ACTION_HOVER_CANCEL = 33; + static constexpr int32_t POINTER_ACTION_FINGERPRINT_CANCEL = 34; - static constexpr int32_t POINTER_ACTION_HOVER_CANCEL = 33; + /** + * Indicates that the pen proximity action. + * + * @since 12 + */ + static constexpr int32_t POINTER_ACTION_PROXIMITY_IN = 35; + + static constexpr int32_t POINTER_ACTION_PROXIMITY_OUT = 36; /** * 表示触屏手势动作 diff --git a/service/touch_event_normalize/include/tablet_tool_tranform_processor.h b/service/touch_event_normalize/include/tablet_tool_tranform_processor.h index 8aae3ac6f9b6787ae96b22d02080ccdbd8c27146..2c35275650128bb5f2df0b3367b691e473a29068 100644 --- a/service/touch_event_normalize/include/tablet_tool_tranform_processor.h +++ b/service/touch_event_normalize/include/tablet_tool_tranform_processor.h @@ -33,6 +33,7 @@ public: private: int32_t GetToolType(struct libinput_event_tablet_tool* tabletEvent); bool OnTip(struct libinput_event* event); + bool OnTipProximity(struct libinput_event* event); bool OnTipDown(struct libinput_event_tablet_tool* event); bool OnTipMotion(struct libinput_event* event); bool OnTipUp(struct libinput_event_tablet_tool* event); diff --git a/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp b/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp index 2ac1d7b3884f0322fe659daa0c19f561bf6ce341..25f8def9bbd63e20494157371a844d43466ebd3d 100644 --- a/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp +++ b/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp @@ -48,8 +48,11 @@ std::shared_ptr TabletToolTransformProcessor::OnEvent(struct libin break; } case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: { - MMI_HILOGE("Proximity event"); - return nullptr; + if (!OnTipProximity(event)) { + MMI_HILOGE("OnTipProximity failed"); + return nullptr; + } + break; } case LIBINPUT_EVENT_TABLET_TOOL_TIP: { if (!OnTip(event)) { @@ -246,5 +249,60 @@ bool TabletToolTransformProcessor::OnTipUp(struct libinput_event_tablet_tool* ev pointerEvent_->UpdatePointerItem(DEFAULT_POINTER_ID, item); return true; } + +bool TabletToolTransformProcessor::OnTipProximity(struct libinput_event* event) +{ + CALL_DEBUG_ENTER; + CHKPF(event); + auto tabletEvent = libinput_event_get_tablet_tool_event(event); + CHKPF(tabletEvent); + uint64_t time = libinput_event_tablet_tool_get_time_usec(tabletEvent); + pointerEvent_->SetActionTime(time); + + bool tabletProximityState = libinput_event_tablet_tool_get_proximity_state(tabletEvent); + if (tabletProximityState) { + MMI_HILOGI("The pen is getting close and report proximity in event"); + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_PROXIMITY_IN); + } else { + MMI_HILOGI("The pen is getting away and report proximity out event"); + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_PROXIMITY_OUT); + } + + int32_t targetDisplayId = pointerEvent_->GetTargetDisplayId(); + PhysicalCoordinate tCoord; + if (!WIN_MGR->CalculateTipPoint(tabletEvent, targetDisplayId, tCoord)) { + MMI_HILOGE("CalculateTipPoint failed"); + return false; + } + double tiltX = libinput_event_tablet_tool_get_tilt_x(tabletEvent); + double tiltY = libinput_event_tablet_tool_get_tilt_y(tabletEvent); + double pressure = libinput_event_tablet_tool_get_pressure(tabletEvent); + int32_t toolType = GetToolType(tabletEvent); + + PointerEvent::PointerItem item; + if (!pointerEvent_->GetPointerItem(DEFAULT_POINTER_ID, item)) { + MMI_HILOGW("The pointer is expected, but not found"); + } + + pointerEvent_->SetActionStartTime(time); + pointerEvent_->SetTargetDisplayId(targetDisplayId); + pointerEvent_->SetDeviceId(deviceId_); + pointerEvent_->SetPointerId(DEFAULT_POINTER_ID); + + item.SetPointerId(DEFAULT_POINTER_ID); + item.SetDeviceId(deviceId_); + item.SetDownTime(time); + item.SetPressed(false); + item.SetToolType(toolType); + item.SetDisplayX(static_cast(tCoord.x)); + item.SetDisplayY(static_cast(tCoord.y)); + item.SetDisplayXPos(tCoord.x); + item.SetDisplayYPos(tCoord.y); + item.SetTiltX(tiltX); + item.SetTiltY(tiltY); + item.SetPressure(pressure); + pointerEvent_->UpdatePointerItem(DEFAULT_POINTER_ID, item); + return true; +} } // namespace MMI } // namespace OHOS diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index e0af0ece5ec2d13fd7e14d374a30ac249dcb2f6b..264c000882a0c89fcc949823c713c2e6b295fd30 100644 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -2802,7 +2802,8 @@ int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptr= 0) { + if (targetWindowId >= 0 && + (pointerItem.GetToolType() != PointerEvent::TOOL_TYPE_PEN || pointerItem.GetPressure() > 0)) { bool isUiExtentionWindow = false; for (auto &windowinfo : item.uiExtentionWindowInfo) { if (windowinfo.id == targetWindowId) {