inertial scroll for touchpad gesture

This commit is contained in:
TrueZhuanjia
2025-12-09 22:49:34 +08:00
parent 7caa778ff8
commit 03817bcfd7
4 changed files with 40 additions and 11 deletions
+10 -1
View File
@@ -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);
}
}
+4 -2
View File
@@ -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;
+25 -8
View File
@@ -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
}
}
}
}
@@ -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]);