diff --git a/VoidLink/Input/CustomTapGestureRecognizer.m b/VoidLink/Input/CustomTapGestureRecognizer.m index 2834c693..c3ff4114 100644 --- a/VoidLink/Input/CustomTapGestureRecognizer.m +++ b/VoidLink/Input/CustomTapGestureRecognizer.m @@ -90,7 +90,16 @@ static CGFloat screenWidthInPoints; _gestureCaptured = false; //reset for next recognition if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){ // lowestTouchPointYCoord = 0.0; //reset for next recognition - self.state = UIGestureRecognizerStateRecognized; + + for(UITouch* touch in touches){ + CGVector vector = [UITouchUtil vectorOf:touch in:self.view]; + if(hypot(vector.dx, vector.dy)>2){ + self.state = UIGestureRecognizerStateFailed; + break; + } + } + + if(self.state != UIGestureRecognizerStateFailed) self.state = UIGestureRecognizerStateRecognized; // NSLog(@"gen _lowestTouchPointHeight %f markmark touchesEnd", _lowestTouchPointHeight); } } diff --git a/VoidLink/Input/RelativeTouchHandler.m b/VoidLink/Input/RelativeTouchHandler.m index f72c20bd..14f8e8d2 100644 --- a/VoidLink/Input/RelativeTouchHandler.m +++ b/VoidLink/Input/RelativeTouchHandler.m @@ -193,10 +193,12 @@ static const float QUICK_TAP_TIME_INTERVAL = 0.2; if(TouchPadGestureHandler.ctrlDown) LiSendKeyboardEvent(CommandManager.keyboardButtonMappings[@"CTRL"].shortValue,KEY_ACTION_UP,0); + [TouchPadGestureHandler startInertialScroll]; + if(multiTouchesDetected){ if([UITouchUtil touchesIn:streamView from:event].count == touches.count){ - - multiTouchesDetected = false;} + multiTouchesDetected = false; + } return; } if([UITouchUtil touchesIn:streamView from:event].count == touches.count) multiTouchesDetected = false; diff --git a/VoidLink/Input/TouchPadGestureHandler.swift b/VoidLink/Input/TouchPadGestureHandler.swift index 4f3eac9f..10496391 100644 --- a/VoidLink/Input/TouchPadGestureHandler.swift +++ b/VoidLink/Input/TouchPadGestureHandler.swift @@ -16,7 +16,21 @@ import UIKit @objc public static var enableHorizontalScroll:Bool = true @objc public static var scrollSensitivity:CGFloat = 1.0 @objc public static var pinchSensitivity:CGFloat = 1.0 + @objc public static var displayLinkRate:CGFloat = 60 + + private static var inertialScroller: InertialScroller = InertialScroller(decelerationRate: 0.915, displayLinkRate: displayLinkRate) { + if ctrlDown {return} + LiSendHighResScrollEvent(Int16(inertialScroller.vector.dy*7*scrollSensitivity)) + if TouchPadGestureHandler.enableHorizontalScroll {LiSendHighResHScrollEvent(Int16(-inertialScroller.vector.dx*7*scrollSensitivity))} + } + + @objc public static func startInertialScroll(){ + inertialScroller.timer?.restart() + } + @objc public static func handleGesture(in view: UIView, with event: UIEvent) { + inertialScroller.timer?.pause() + let currentTouches = UITouchUtil.touches(in: view, from: event) guard currentTouches.count == 2 else { return } @@ -35,19 +49,22 @@ import UIKit let midPointDeltaX = midPointVector.dx let midPointDeltaY = midPointVector.dy + inertialScroller.vector = CGVector(dx: midPointDeltaX, dy: midPointDeltaY) + let originalPinchDelta = currentDistance-previousDistance; let pinchDelta = enablePinch ? originalPinchDelta*7*pinchSensitivity : 0; LiSendHighResScrollEvent(Int16(pinchDelta + midPointDeltaY*7*scrollSensitivity)) if enableHorizontalScroll {LiSendHighResHScrollEvent(Int16(-midPointDeltaX*7*scrollSensitivity))} - if !enablePinch || !ctrlDownForPinch {return}; - - if abs(originalPinchDelta) > abs(midPointDeltaY)*1.3, abs(originalPinchDelta) > abs(midPointDeltaX)*1.3 { - LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["CTRL"]!, CChar(KEY_ACTION_DOWN), 0) - ctrlDown = true - } else { - LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["CTRL"]!, CChar(KEY_ACTION_UP), 0) - ctrlDown = false + if enablePinch, ctrlDownForPinch { + let midPointDelta = hypot(midPointDeltaX, midPointDeltaY) + if abs(originalPinchDelta) > midPointDelta*1.3, midPointDelta < 2 { + LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["CTRL"]!, CChar(KEY_ACTION_DOWN), 0) + ctrlDown = true + } else { + LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["CTRL"]!, CChar(KEY_ACTION_UP), 0) + ctrlDown = false + } } } } diff --git a/VoidLink/ViewControllers/StreamFrameViewController.m b/VoidLink/ViewControllers/StreamFrameViewController.m index a689046f..4a0c0d4c 100644 --- a/VoidLink/ViewControllers/StreamFrameViewController.m +++ b/VoidLink/ViewControllers/StreamFrameViewController.m @@ -451,6 +451,7 @@ TouchPadGestureHandler.ctrlDownForPinch = _settings.ctrlDownForPinch; TouchPadGestureHandler.scrollSensitivity = _settings.scrollSensitivity.floatValue; TouchPadGestureHandler.pinchSensitivity = _settings.pinchSensitivity.floatValue; + TouchPadGestureHandler.displayLinkRate = _settings.framerate.intValue; NSLog(@"frameview gestures: %d", (uint32_t)[self.view.gestureRecognizers count]); NSLog(@"streamview gestures: %d", (uint32_t)[_streamView.gestureRecognizers count]);