From 802bed69d544cbcaab9257819180dfa2157bc4d1 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Fri, 21 Feb 2025 23:52:20 +0100 Subject: [PATCH] allow more precise touch movements --- client/eventsSDL/InputSourceTouch.cpp | 23 +++++++++++++++++------ client/eventsSDL/InputSourceTouch.h | 4 ++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/client/eventsSDL/InputSourceTouch.cpp b/client/eventsSDL/InputSourceTouch.cpp index 8b8a45491..0c0425063 100644 --- a/client/eventsSDL/InputSourceTouch.cpp +++ b/client/eventsSDL/InputSourceTouch.cpp @@ -58,6 +58,15 @@ InputSourceTouch::InputSourceTouch() void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfinger) { + Point screenSize = GH.screenDimensions(); + + motionAccumulatedX[tfinger.fingerId] += tfinger.dx; + motionAccumulatedY[tfinger.fingerId] += tfinger.dy; + + float motionThreshold = 1.0 / std::min(screenSize.x, screenSize.y); + if(motionAccumulatedX[tfinger.fingerId] < motionThreshold && motionAccumulatedY[tfinger.fingerId] < motionThreshold && motionAccumulatedX[tfinger.fingerId] > -motionThreshold && motionAccumulatedY[tfinger.fingerId] > -motionThreshold) + return; + if (CCS && CCS->curh && settings["video"]["cursor"].String() == "software" && state != TouchState::RELATIVE_MODE) CCS->curh->cursorMove(GH.getCursorPosition().x, GH.getCursorPosition().y); @@ -65,12 +74,11 @@ void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfin { case TouchState::RELATIVE_MODE: { - Point screenSize = GH.screenDimensions(); int scalingFactor = GH.screenHandler().getScalingFactor(); Point moveDistance { - static_cast(screenSize.x * params.relativeModeSpeedFactor * tfinger.dx), - static_cast(screenSize.y * params.relativeModeSpeedFactor * tfinger.dy) + static_cast(screenSize.x * params.relativeModeSpeedFactor * motionAccumulatedX[tfinger.fingerId]), + static_cast(screenSize.y * params.relativeModeSpeedFactor * motionAccumulatedY[tfinger.fingerId]) }; GH.input().moveCursorPosition(moveDistance); @@ -112,6 +120,9 @@ void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfin break; } } + + motionAccumulatedX[tfinger.fingerId] = 0; + motionAccumulatedY[tfinger.fingerId] = 0; } void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinger) @@ -293,7 +304,7 @@ int InputSourceTouch::getNumTouchFingers() const void InputSourceTouch::emitPanningEvent(const SDL_TouchFingerEvent & tfinger) { - Point distance = convertTouchToMouse(-tfinger.dx, -tfinger.dy); + Point distance = convertTouchToMouse(-motionAccumulatedX[tfinger.fingerId], -motionAccumulatedY[tfinger.fingerId]); GH.events().dispatchGesturePanning(lastTapPosition, convertTouchToMouse(tfinger), distance); } @@ -327,8 +338,8 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger) float thisX = tfinger.x * GH.screenDimensions().x; float thisY = tfinger.y * GH.screenDimensions().y; - float deltaX = tfinger.dx * GH.screenDimensions().x; - float deltaY = tfinger.dy * GH.screenDimensions().y; + float deltaX = motionAccumulatedX[tfinger.fingerId] * GH.screenDimensions().x; + float deltaY = motionAccumulatedY[tfinger.fingerId] * GH.screenDimensions().y; float oldX = thisX - deltaX - otherX; float oldY = thisY - deltaY - otherY; diff --git a/client/eventsSDL/InputSourceTouch.h b/client/eventsSDL/InputSourceTouch.h index dd4d46267..0fcc03a51 100644 --- a/client/eventsSDL/InputSourceTouch.h +++ b/client/eventsSDL/InputSourceTouch.h @@ -10,6 +10,7 @@ #pragma once +#include "SDL_touch.h" #include "../../lib/Point.h" // Debug option. If defined, mouse events will instead generate touch events, allowing testing of touch input on desktop @@ -110,6 +111,9 @@ class InputSourceTouch Point lastLeftClickPosition; int numTouchFingers; + std::map motionAccumulatedX; + std::map motionAccumulatedY; + Point convertTouchToMouse(const SDL_TouchFingerEvent & current); Point convertTouchToMouse(float x, float y);