From 4dc6220f28b2accd8bfd0edcfaa73d85e3a11b32 Mon Sep 17 00:00:00 2001 From: True Zhuanjia Date: Thu, 12 Feb 2026 15:33:43 +0800 Subject: [PATCH] touch track point improvements --- VoidLink/Input/NativeTouchHandler.m | 42 +++++++++++++++---------- VoidLink/Input/OnScreenWidgetView.swift | 1 + VoidLink/Input/PureNativeTouchHandler.m | 42 ++++++++++++++++--------- 3 files changed, 54 insertions(+), 31 deletions(-) diff --git a/VoidLink/Input/NativeTouchHandler.m b/VoidLink/Input/NativeTouchHandler.m index f25a1eb4..e1b8a5e5 100644 --- a/VoidLink/Input/NativeTouchHandler.m +++ b/VoidLink/Input/NativeTouchHandler.m @@ -224,7 +224,7 @@ } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - dispatch_async(dispatch_get_global_queue(touchDownQos, 0), ^{ + dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ for (UITouch* touch in touches){ // continue to the next loop if current touch is already captured by OSC. works only in regular native touch if([OnScreenControls.touchesCapturedByOnScreenControls containsObject:touch]) continue; @@ -233,8 +233,8 @@ [self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_DOWN withEvent:event]; } - dispatch_async(dispatch_get_main_queue(), ^{ - if(self->trackPointEnabled){ + if(self->trackPointEnabled){ + dispatch_async(dispatch_get_main_queue(), ^{ [CATransaction begin]; [CATransaction setDisableActions:YES]; for (UITouch* touch in touches){ @@ -244,13 +244,13 @@ trackPoint.hidden = false; } [CATransaction commit]; - } - }); + }); + } }); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, moveEventIntervalNSec), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, moveEventIntervalNSec), dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ for (UITouch* touch in touches){ if([OnScreenControls.touchesCapturedByOnScreenControls containsObject:touch]) continue; if(self->activateCoordSelector) [self updatePointerObjInDict:touch]; @@ -259,8 +259,8 @@ } }); - dispatch_async(dispatch_get_main_queue(), ^{ - if(self->trackPointEnabled){ + if(self->trackPointEnabled){ + dispatch_async(dispatch_get_main_queue(), ^{ [CATransaction begin]; [CATransaction setDisableActions:YES]; for (UITouch* touch in touches){ @@ -269,12 +269,12 @@ trackPoint.position = [touch locationInView:self->streamView]; } [CATransaction commit]; - } - }); + }); + } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, moveEventIntervalNSec), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, moveEventIntervalNSec), dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ for (UITouch* touch in touches){ if([OnScreenControls.touchesCapturedByOnScreenControls containsObject:touch]){ [OnScreenControls.touchesCapturedByOnScreenControls removeObject:touch]; @@ -287,8 +287,16 @@ } }); - dispatch_async(dispatch_get_main_queue(), ^{ - if(self->trackPointEnabled){ + if(self->trackPointEnabled){ + if(touches.count == [UITouchUtil touchesIn:streamView from:event].count){ + [CATransaction begin]; + [CATransaction setDisableActions:YES]; + for(CAShapeLayer* trackPoint in trackPointPool) trackPoint.hidden = true; + [CATransaction commit]; + return; + } + + dispatch_async(dispatch_get_main_queue(), ^{ [CATransaction begin]; [CATransaction setDisableActions:YES]; for (UITouch* touch in touches){ @@ -297,15 +305,14 @@ trackPoint.hidden = true; } [CATransaction commit]; - } - }); + }); + } } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [self touchesEnded:touches withEvent:event]; } - - (void)populatePointerObjIntoDict:(UITouch*)touch{ NativeTouchPointer* pointer = [[NativeTouchPointer alloc] initWithTouch:touch]; pointer.useRelativeCoords = pointer.initialPoint.x > pointerVelocityDividerLocationByPoints; @@ -345,6 +352,9 @@ pointerIdPool= nil; unassignedPointerIds = nil; blacklistedTouches = nil; + for(CAShapeLayer* layer in trackPointPool){ + [layer removeFromSuperlayer]; + } trackPointPool = nil; pointerObjDict = nil; } diff --git a/VoidLink/Input/OnScreenWidgetView.swift b/VoidLink/Input/OnScreenWidgetView.swift index eb47141c..03706285 100644 --- a/VoidLink/Input/OnScreenWidgetView.swift +++ b/VoidLink/Input/OnScreenWidgetView.swift @@ -2996,6 +2996,7 @@ import SVGKit self.functionalButtonDelegate?.alterAbsTouchDragWith(mouseButton:BUTTON_LEFT) } buttonDownVisualEffectLayer.removeFromSuperlayer() + trackPoint.removeFromSuperlayer() crossMarkLayer.removeFromSuperlayer() lrudIndicatorBall.removeFromSuperlayer() l3r3Indicator.removeFromSuperlayer() diff --git a/VoidLink/Input/PureNativeTouchHandler.m b/VoidLink/Input/PureNativeTouchHandler.m index b8ead698..27c70d76 100644 --- a/VoidLink/Input/PureNativeTouchHandler.m +++ b/VoidLink/Input/PureNativeTouchHandler.m @@ -215,15 +215,16 @@ } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - dispatch_async(dispatch_get_global_queue(touchDownQos, 0), ^{ + dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ for (UITouch* touch in touches){ // continue to the next loop if current touch is already captured by OSC. works only in regular native touch [self handleTouchDown:touch]; //generate & populate pointerId if(self->activateCoordSelector) [self populatePointerObjIntoDict:touch]; [self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_DOWN]; } - dispatch_async(dispatch_get_main_queue(), ^{ - if(self->trackPointEnabled){ + + if(self->trackPointEnabled){ + dispatch_async(dispatch_get_main_queue(), ^{ [CATransaction begin]; [CATransaction setDisableActions:YES]; for (UITouch* touch in touches){ @@ -233,13 +234,13 @@ trackPoint.hidden = false; } [CATransaction commit]; - } - }); + }); + } }); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, moveEventIntervalNSec), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, moveEventIntervalNSec), dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ for (UITouch* touch in touches){ if(self->activateCoordSelector) [self updatePointerObjInDict:touch]; [self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_MOVE]; @@ -247,8 +248,8 @@ } }); - dispatch_async(dispatch_get_main_queue(), ^{ - if(self->trackPointEnabled){ + if(self->trackPointEnabled){ + dispatch_async(dispatch_get_main_queue(), ^{ [CATransaction begin]; [CATransaction setDisableActions:YES]; for (UITouch* touch in touches){ @@ -257,12 +258,12 @@ trackPoint.position = [touch locationInView:self->streamView]; } [CATransaction commit]; - } - }); + }); + } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, moveEventIntervalNSec), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, moveEventIntervalNSec), dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ for (UITouch* touch in touches){ [self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_UP]; //send touch event before remove pointerId [self removePointerId:touch]; //then remove pointerId @@ -271,8 +272,16 @@ } }); - dispatch_async(dispatch_get_main_queue(), ^{ - if(self->trackPointEnabled){ + if(self->trackPointEnabled){ + if(touches.count == [UITouchUtil touchesIn:streamView from:event].count){ + [CATransaction begin]; + [CATransaction setDisableActions:YES]; + for(CAShapeLayer* trackPoint in trackPointPool) trackPoint.hidden = true; + [CATransaction commit]; + return; + } + + dispatch_async(dispatch_get_main_queue(), ^{ [CATransaction begin]; [CATransaction setDisableActions:YES]; for (UITouch* touch in touches){ @@ -281,8 +290,8 @@ trackPoint.hidden = true; } [CATransaction commit]; - } - }); + }); + } } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { @@ -325,6 +334,9 @@ pointerIdPool= nil; unassignedPointerIds = nil; blacklistedTouches = nil; + for(CAShapeLayer* layer in trackPointPool){ + [layer removeFromSuperlayer]; + } trackPointPool = nil; pointerObjDict = nil; }