From 68efe9a9c400ed987e7508742402dc0d1d2584f4 Mon Sep 17 00:00:00 2001 From: dreamond_wxy Date: Tue, 20 Aug 2024 10:17:36 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=89=8B=E5=86=99=E7=AC=94=E6=82=AC?= =?UTF-8?q?=E6=B5=AE=E7=89=B9=E6=80=A7=E5=A4=9A=E6=A8=A1=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dreamond_wxy Change-Id: Iaa8e6bbfdc1f812f77e1cdb58fa3188b0a957929 --- frameworks/proxy/events/src/pointer_event.cpp | 2 + .../innerkits/event/include/pointer_event.h | 9 +++ .../include/tablet_tool_tranform_processor.h | 1 + .../src/tablet_tool_tranform_processor.cpp | 61 ++++++++++++++++++- .../src/input_windows_manager.cpp | 3 +- 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/frameworks/proxy/events/src/pointer_event.cpp b/frameworks/proxy/events/src/pointer_event.cpp index f6bb317834..b72ac03add 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 359b3533f6..e35e0df3d4 100644 --- a/interfaces/native/innerkits/event/include/pointer_event.h +++ b/interfaces/native/innerkits/event/include/pointer_event.h @@ -184,6 +184,15 @@ public: 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 8aae3ac6f9..2c35275650 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 2ac1d7b388..22c2bef610 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,59 @@ 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 e0af0ece5e..fa565d0041 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) { -- Gitee From dcc4e35176b1a1ae364d56c7a4041071b4f2e25d Mon Sep 17 00:00:00 2001 From: dreamond_wxy Date: Tue, 20 Aug 2024 21:29:48 +0800 Subject: [PATCH 2/4] fix bugs for targetWindow update Signed-off-by: dreamond_wxy Change-Id: I8166920977b3d54287bd32bce5f4310732fb4a64 --- service/window_manager/src/input_windows_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index fa565d0041..ff8581bbba 100644 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -2803,7 +2803,7 @@ int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptr= 0 && - (pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_PEN && pointerItem.GetPressure() > 0)) { + (pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_PEN || pointerItem.GetPressure() > 0)) { bool isUiExtentionWindow = false; for (auto &windowinfo : item.uiExtentionWindowInfo) { if (windowinfo.id == targetWindowId) { -- Gitee From e872ea84b72154f8e187f1f293ed1acbcd0697fb Mon Sep 17 00:00:00 2001 From: dreamond_wxy Date: Tue, 27 Aug 2024 11:30:21 +0800 Subject: [PATCH 3/4] fix bugs for pen proximity Signed-off-by: dreamond_wxy Change-Id: I9d02604e58e77d008887e9a7dc3781cf83c90b44 --- .../innerkits/event/include/pointer_event.h | 4 ++-- .../src/tablet_tool_tranform_processor.cpp | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/interfaces/native/innerkits/event/include/pointer_event.h b/interfaces/native/innerkits/event/include/pointer_event.h index e35e0df3d4..f5eafe13aa 100644 --- a/interfaces/native/innerkits/event/include/pointer_event.h +++ b/interfaces/native/innerkits/event/include/pointer_event.h @@ -180,10 +180,10 @@ public: static constexpr int32_t POINTER_ACTION_FINGERPRINT_CLICK = 32; - static constexpr int32_t POINTER_ACTION_FINGERPRINT_CANCEL = 34; - static constexpr int32_t POINTER_ACTION_HOVER_CANCEL = 33; + static constexpr int32_t POINTER_ACTION_FINGERPRINT_CANCEL = 34; + /** * Indicates that the pen proximity action. * 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 22c2bef610..25f8def9bb 100644 --- a/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp +++ b/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp @@ -282,17 +282,18 @@ bool TabletToolTransformProcessor::OnTipProximity(struct libinput_event* event) 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); } + + 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); -- Gitee From b2fdfe10aba5fa4f8755ea735bc1cf5396902dc8 Mon Sep 17 00:00:00 2001 From: dreamond_wxy Date: Tue, 27 Aug 2024 12:06:42 +0800 Subject: [PATCH 4/4] fix strategy bugs Signed-off-by: dreamond_wxy Change-Id: I3c08c667f8ac0e8dcd180fa27e50dc9d08d8bbac --- service/window_manager/src/input_windows_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index ff8581bbba..264c000882 100644 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -2803,7 +2803,7 @@ int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptr= 0 && - (pointerItem.GetToolType() == PointerEvent::TOOL_TYPE_PEN || pointerItem.GetPressure() > 0)) { + (pointerItem.GetToolType() != PointerEvent::TOOL_TYPE_PEN || pointerItem.GetPressure() > 0)) { bool isUiExtentionWindow = false; for (auto &windowinfo : item.uiExtentionWindowInfo) { if (windowinfo.id == targetWindowId) { -- Gitee