diff --git a/service/mouse_event_handler/include/mouse_event_handler.h b/service/mouse_event_handler/include/mouse_event_handler.h index 5f13542f7931bbbb8df002532ce35ade6bfdfa4b..c0d17155ace59047c8028c9f6994b7fb5bcd827f 100755 --- a/service/mouse_event_handler/include/mouse_event_handler.h +++ b/service/mouse_event_handler/include/mouse_event_handler.h @@ -54,18 +54,20 @@ 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); + bool GetSpeedGain(const double &vin, double& gain) const; void DumpInner(); void InitAbsolution(); private: - 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; - int32_t speed_ = DEFAULT_SPEED; + 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_ { DEFAULT_SPEED }; }; #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 87a5f8f55bd61bfa1e4b72f65cd5759afe817524..b9ba198e9629437737a512fccd84bad677543bd7 100755 --- a/service/mouse_event_handler/src/mouse_event_handler.cpp +++ b/service/mouse_event_handler/src/mouse_event_handler.cpp @@ -31,7 +31,11 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "MouseEventHandler"}; +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 }; +const std::array SPEED_DIFF_NUMS { 0.0, -2.0, -5.0, -19.0, -28.6, -57.3 }; +constexpr double DOUBLE_ZERO = 1e-6; constexpr int32_t MIN_SPEED = 1; constexpr int32_t MAX_SPEED = 20; } // namespace @@ -46,6 +50,23 @@ std::shared_ptr MouseEventHandler::GetPointerEvent() const return pointerEvent_; } +bool MouseEventHandler::GetSpeedGain(const double& vin, double& gain) const +{ + if (abs(vin) < DOUBLE_ZERO) { + MMI_HILOGE("The value of the parameter passed in is 0"); + return false; + } + int32_t num = static_cast(ceil(abs(vin))); + for (size_t i = 0; i < SPEED_NUMS.size(); ++i) { + if (num <= SPEED_NUMS[i]) { + gain = (SPEED_GAINS[i] * vin + SPEED_DIFF_NUMS[i]) / vin; + return true; + } + } + gain = (SPEED_GAINS.back() * vin + SPEED_DIFF_NUMS.back()) / vin; + return true; +} + int32_t MouseEventHandler::HandleMotionInner(libinput_event_pointer* data) { CALL_DEBUG_ENTER; @@ -62,11 +83,37 @@ int32_t MouseEventHandler::HandleMotionInner(libinput_event_pointer* data) return RET_ERR; } - absolutionX_ += libinput_event_pointer_get_dx(data); - absolutionY_ += libinput_event_pointer_get_dy(data); + int32_t ret = HandleMotionCorrection(data); + if (ret != RET_OK) { + MMI_HILOGE("Failed to handle motion correction"); + return ret; + } + WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); pointerEvent_->SetTargetDisplayId(currentDisplayId_); - MMI_HILOGD("Change Coordinate : x:%{public}lf,y:%{public}lf", absolutionX_, absolutionY_); + 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); + double dx = libinput_event_pointer_get_dx(data); + double dy = libinput_event_pointer_get_dy(data); + double vin = (fmax(abs(dx), abs(dy)) + fmin(abs(dx), abs(dy))) / 2.0; + double gain { 0.0 }; + if (!GetSpeedGain(vin, gain)) { + MMI_HILOGE("Get speed gain failed"); + return RET_ERR; + } + double correctionX = dx * gain * static_cast(speed_) / 10.0; + double correctionY = dy * gain * static_cast(speed_) / 10.0; + MMI_HILOGD("Get and process the movement coordinates, dx:%{public}lf, dy:%{public}lf," + "correctionX:%{public}lf, correctionY:%{public}lf, gain:%{public}lf", + dx, dy, correctionX, correctionY, gain); + absolutionX_ += correctionX; + absolutionY_ += correctionY; return RET_OK; } diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index c978fddeafa70677f728589f65828e882709de14..ca104ed037313e11d1ca3205cd6ae697cde691fb 100755 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -813,19 +813,21 @@ void InputWindowsManager::UpdateAndAdjustMouseLocation(int32_t& displayId, doubl if (displayId == lastDisplayId) { if (integerX < 0) { integerX = 0; + x = static_cast(integerX); } if (integerX >= width) { integerX = width - 1; + x = static_cast(integerX); } if (integerY < 0) { integerY = 0; + y = static_cast(integerY); } if (integerY >= height) { integerY = height - 1; + y = static_cast(integerY); } } - x = static_cast(integerX); - y = static_cast(integerY); mouseLocation_.physicalX = integerX; mouseLocation_.physicalY = integerY; MMI_HILOGD("Mouse Data: physicalX:%{public}d,physicalY:%{public}d, displayId:%{public}d",