diff --git a/VoidLink/Input/OnScreenWidgetView.swift b/VoidLink/Input/OnScreenWidgetView.swift index a3ed4522..8ec95a3b 100644 --- a/VoidLink/Input/OnScreenWidgetView.swift +++ b/VoidLink/Input/OnScreenWidgetView.swift @@ -1683,8 +1683,9 @@ import UIKit self.mousePointerMoved = true } - self.deltaX = UITouchUtil.getDeltaX(from: touch, in: self) - self.deltaY = UITouchUtil.getDeltaY(from: touch, in: self) + let vector = UITouchUtil.vector(of: touch, in: self) + self.deltaX = vector.dx + self.deltaY = vector.dy self.offSetX = currentTouchLocation.x - self.touchBeganLocation.x self.offSetY = currentTouchLocation.y - self.touchBeganLocation.y } diff --git a/VoidLink/Input/RelativeTouchHandler.m b/VoidLink/Input/RelativeTouchHandler.m index f3c991df..33d3b547 100644 --- a/VoidLink/Input/RelativeTouchHandler.m +++ b/VoidLink/Input/RelativeTouchHandler.m @@ -230,8 +230,9 @@ static const float QUICK_TAP_TIME_INTERVAL = 0.2; - (void)sendMouseMoveEvent:(CGPoint)currentLocation{ dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ - int deltaX = ([UITouchUtil getDeltaXFrom:self->touchLockedForMouseMove in:self->streamView]) * 1.35 * self->currentSettings.mousePointerVelocityFactor.floatValue; - int deltaY = ([UITouchUtil getDeltaYFrom:self->touchLockedForMouseMove in:self->streamView]) * 1.35 * self->currentSettings.mousePointerVelocityFactor.floatValue; + CGVector vector = [UITouchUtil vectorOf:self->touchLockedForMouseMove in:self->streamView]; + int deltaX = vector.dx * 1.35 * self->currentSettings.mousePointerVelocityFactor.floatValue; + int deltaY = vector.dy * 1.35 * self->currentSettings.mousePointerVelocityFactor.floatValue; if(self->touchPointSpawnedAtUpperScreenEdge) return; // we're done here. this touch event will not be sent to the remote PC. if(self->firstTouchMoved) LiSendMouseMoveEvent(deltaX, deltaY); diff --git a/VoidLink/Input/UITouchUtil.swift b/VoidLink/Input/UITouchUtil.swift index 2d555cbe..310b5b97 100644 --- a/VoidLink/Input/UITouchUtil.swift +++ b/VoidLink/Input/UITouchUtil.swift @@ -10,7 +10,7 @@ import UIKit @objc class UITouchUtil: NSObject { @objc public static func touches(in view: UIView, from event: UIEvent?) -> Set { - guard let allTouches = event?.allTouches else { return [] } + guard (event?.allTouches) != nil else { return [] } return event?.allTouches?.filter({ $0.view == view }) ?? [] } @@ -28,6 +28,20 @@ import UIKit return hypot(p1.x - p2.x, p1.y - p2.y) } + @objc public static func vector(from touch1: UITouch?, to touch2: UITouch?, in view: UIView?) -> CGVector { + guard let view = view, let touch1 = touch1, let touch2 = touch2 else { return CGVectorMake(0,0) } + let p1 = touch1.location(in: view) + let p2 = touch2.location(in: view) + return CGVectorMake(p2.x - p1.x, p2.y - p1.y) + } + + @objc public static func vector(of touch: UITouch?, in view: UIView?) -> CGVector { + guard let view = view, let touch = touch else { return CGVectorMake(0,0) } + let p2 = touch.location(in: view) + let p1 = touch.previousLocation(in: view) + return CGVectorMake(p2.x - p1.x, p2.y - p1.y) + } + @objc public static func getDeltaX(from touch: UITouch?, in view: UIView?) -> CGFloat { guard let view = view, let touch = touch else { return 0 } return touch.location(in: view).x - touch.previousLocation(in: view).x