From c31c786c63ba8faf8c98de947eb68d7a3a2c2168 Mon Sep 17 00:00:00 2001 From: libangwu Date: Fri, 15 Jul 2022 13:16:23 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=E9=BC=A0=E6=A0=87=E5=8A=A0?= =?UTF-8?q?=E9=80=9F=E7=AE=97=E6=B3=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: libangwu --- .../include/mouse_event_handler.h | 18 +++---- .../src/mouse_event_handler.cpp | 52 ++----------------- 2 files changed, 10 insertions(+), 60 deletions(-) diff --git a/service/mouse_event_handler/include/mouse_event_handler.h b/service/mouse_event_handler/include/mouse_event_handler.h index 9661a9e837..f37b850355 100755 --- a/service/mouse_event_handler/include/mouse_event_handler.h +++ b/service/mouse_event_handler/include/mouse_event_handler.h @@ -49,21 +49,17 @@ private: void HandlePostMoveMouse(PointerEvent::PointerItem& pointerItem); #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING int32_t HandleButtonValueInner(libinput_event_pointer* data); - int32_t HandleMotionCorrection(libinput_event_pointer* data); - double GetSpeedGain(const double &speed) const; void DumpInner(); void InitAbsolution(); private: - std::shared_ptr pointerEvent_ { nullptr }; - int32_t timerId_ { -1 }; - double absolutionX_ { -1.0 }; - double absolutionY_ { -1.0 }; - int32_t buttonId_ { -1 }; - bool isPressed_ { false }; - int32_t currentDisplayId_ { -1 }; - int32_t speed_ { 10 }; - uint64_t lastEventTime_ { 0 }; + std::shared_ptr pointerEvent_ = nullptr; + int32_t timerId_ = -1; + double absolutionX_ = -1; + double absolutionY_ = -1; + int32_t buttonId_ = -1; + bool isPressed_ = false; + int32_t currentDisplayId_ = -1; }; #define MouseEventHdr MouseEventHandler::GetInstance() diff --git a/service/mouse_event_handler/src/mouse_event_handler.cpp b/service/mouse_event_handler/src/mouse_event_handler.cpp index 8418f80b54..c285aafa1f 100755 --- a/service/mouse_event_handler/src/mouse_event_handler.cpp +++ b/service/mouse_event_handler/src/mouse_event_handler.cpp @@ -32,8 +32,6 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "MouseEventHandler"}; -const std::array SPEED_NUMS { 5, 16, 23, 32, 41, 128 }; -const std::array SPEED_GAINS { 0.6, 1.0, 1.2, 1.8, 2.1, 2.8 }; } // namespace MouseEventHandler::MouseEventHandler() { @@ -46,17 +44,6 @@ std::shared_ptr MouseEventHandler::GetPointerEvent() const return pointerEvent_; } -double MouseEventHandler::GetSpeedGain(const double &speed) const -{ - int32_t num = static_cast(ceil(abs(speed))); - for (size_t i = 0; i < SPEED_NUMS.size(); ++i) { - if (num <= SPEED_NUMS[i]) { - return SPEED_GAINS[i]; - } - } - return SPEED_GAINS.back(); -} - int32_t MouseEventHandler::HandleMotionInner(libinput_event_pointer* data) { CALL_DEBUG_ENTER; @@ -73,44 +60,11 @@ int32_t MouseEventHandler::HandleMotionInner(libinput_event_pointer* data) return RET_ERR; } - int32_t ret = HandleMotionCorrection(data); - if (ret != RET_OK) { - MMI_HILOGE("Failed to handle motion correction"); - return ret; - } - + absolutionX_ += libinput_event_pointer_get_dx(data); + absolutionY_ += libinput_event_pointer_get_dy(data); WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); pointerEvent_->SetTargetDisplayId(currentDisplayId_); - MMI_HILOGD("Change Coordinate : x:%{public}lf,y:%{public}lf", absolutionX_, absolutionY_); - return RET_OK; -} - -int32_t MouseEventHandler::HandleMotionCorrection(libinput_event_pointer* data) -{ - CALL_DEBUG_ENTER; - CHKPR(data, ERROR_NULL_POINTER); - - uint64_t usec = libinput_event_pointer_get_time_usec(data); - if (usec <= lastEventTime_) { - MMI_HILOGE("The new time less than or equal to the last time"); - return RET_ERR; - } - uint64_t timeDiff = usec - lastEventTime_; - - double dx = libinput_event_pointer_get_dx(data); - double dy = libinput_event_pointer_get_dy(data); - DisplayGroupInfo displayGroupInfo = WinMgr->GetDisplayGroupInfo(); - double correctionX = (dx / static_cast(timeDiff)) * (static_cast(speed_) / 10.0) * - GetSpeedGain(dx) * static_cast(displayGroupInfo.displaysInfo[0].width); - double correctionY = (dy / static_cast(timeDiff)) * (static_cast(speed_) / 10.0) * - GetSpeedGain(dy) * static_cast(displayGroupInfo.displaysInfo[0].height); - MMI_HILOGD("dx:%{public}lf, dy:%{public}lf, correctionX:%{public}lf, correctionY:%{public}lf," - "timeDiff:%{public}ju, width:%{public}d, height:%{public}d", - dx, dy, correctionX, correctionY, - timeDiff, displayGroupInfo.displaysInfo[0].width, displayGroupInfo.displaysInfo[0].height); - absolutionX_ += correctionX; - absolutionY_ += correctionY; - lastEventTime_ = usec; + MMI_HILOGD("Change Coordinate : x:%{public}lf,y:%{public}lf", absolutionX_, absolutionY_); return RET_OK; } -- Gitee