From 3c5b6ba79545fb60dec2bcb494b689edf0e91470 Mon Sep 17 00:00:00 2001 From: True Zhuanjia Date: Wed, 14 Aug 2024 22:44:12 +0800 Subject: [PATCH] udpate --- Limelight/Input/CustomTapGestureRecognizer.h | 2 +- Limelight/Input/CustomTapGestureRecognizer.m | 13 ++++++++----- Limelight/Input/OnScreenControls.h | 3 +++ Limelight/Input/OnScreenControls.m | 2 ++ Limelight/Input/RelativeTouchHandler.h | 4 ++++ Limelight/Input/RelativeTouchHandler.m | 16 +++++++--------- Limelight/Input/StreamView.m | 6 ++++++ 7 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Limelight/Input/CustomTapGestureRecognizer.h b/Limelight/Input/CustomTapGestureRecognizer.h index f110c70c..10fad7df 100644 --- a/Limelight/Input/CustomTapGestureRecognizer.h +++ b/Limelight/Input/CustomTapGestureRecognizer.h @@ -18,9 +18,9 @@ @property (nonatomic, assign) uint8_t numberOfTouchesRequired; @property (nonatomic, assign) bool immediateTriggering; // if enabled, trigger the signal on touchesBegan stage. @property (nonatomic, assign) double tapDownTimeThreshold; // tap down threshold in seconds. +@property (nonatomic, assign) bool areVirtualControllerTaps; // will be set by the onscreencontrol class @property (nonatomic, readonly) CGFloat lowestTouchPointHeight; @property (nonatomic, readonly) bool gestureCaptured; -@property (nonatomic, readonly) bool areVirtualControllerTaps; @property (nonatomic, readonly) NSTimeInterval gestureCapturedTime; @end diff --git a/Limelight/Input/CustomTapGestureRecognizer.m b/Limelight/Input/CustomTapGestureRecognizer.m index aa554746..b3ae1a89 100644 --- a/Limelight/Input/CustomTapGestureRecognizer.m +++ b/Limelight/Input/CustomTapGestureRecognizer.m @@ -45,10 +45,11 @@ static CGFloat screenWidthInPoints; if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y; } - if(_numberOfTouchesRequired == 2){ + // this mechanism is deprecated. + /* if(_numberOfTouchesRequired == 2){ NSArray *twoTouches = [[event allTouches] allObjects]; _areVirtualControllerTaps = fabs([twoTouches[1] locationInView:self.view].x - [twoTouches[0] locationInView:self.view].x) > screenWidthInPoints/3; - } + } */ _lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord; if(_immediateTriggering){ @@ -67,17 +68,19 @@ static CGFloat screenWidthInPoints; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { // [super touchesEnded:touches withEvent:event]; if(_immediateTriggering) return; - if([[event allTouches] count] > _numberOfTouchesRequired) { + uint8_t allTouchesCount = [[event allTouches] count]; + if(allTouchesCount > _numberOfTouchesRequired) { _gestureCaptured = false; self.state = UIGestureRecognizerStateFailed; - } - else if(_gestureCaptured && [[event allTouches] count] == [touches count] && !_areVirtualControllerTaps){ //must exclude virtual controller taps here to prevent stucked button + } + else if(_gestureCaptured && allTouchesCount == [touches count] && !_areVirtualControllerTaps){ //must exclude virtual controller taps here to prevent stucked button, _areVirtualControllerTaps flag is set by onscreencontrols or anyother related classes. _gestureCaptured = false; //reset for next recognition if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){ lowestTouchPointYCoord = 0.0; //reset for next recognition self.state = UIGestureRecognizerStateRecognized; } } + if (allTouchesCount == [touches count]) _areVirtualControllerTaps = false; // need to reset this flag anyway, when all fingers are lefting } @end diff --git a/Limelight/Input/OnScreenControls.h b/Limelight/Input/OnScreenControls.h index 2c647b42..21e54604 100644 --- a/Limelight/Input/OnScreenControls.h +++ b/Limelight/Input/OnScreenControls.h @@ -8,6 +8,7 @@ #import #import "ControllerSupport.h" +#import "CustomTapGestureRecognizer.h" #import "OSCProfile.h" @class ControllerSupport; @@ -31,6 +32,8 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) { OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons }; + +@property (nonatomic, assign) CustomTapGestureRecognizer* mouseRightClickTapRecognizer; // this object will be passed to onscreencontrols class for areVirtualControllerTaps flag setting @property CALayer* _aButton; @property CALayer* _bButton; @property CALayer* _xButton; diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index 5305da39..3bafb2e5 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -1037,6 +1037,8 @@ static float L3_Y; } } if (updated) { + _mouseRightClickTapRecognizer.areVirtualControllerTaps = true; //inform the tap recognizer that this will be a controller tap. + [_controllerSupport updateFinished:_controller]; } return updated || stickTouch; diff --git a/Limelight/Input/RelativeTouchHandler.h b/Limelight/Input/RelativeTouchHandler.h index ea4a16e8..8db13186 100644 --- a/Limelight/Input/RelativeTouchHandler.h +++ b/Limelight/Input/RelativeTouchHandler.h @@ -8,10 +8,14 @@ #import "StreamView.h" #import "DataManager.h" +#import "CustomTapGestureRecognizer.h" + NS_ASSUME_NONNULL_BEGIN @interface RelativeTouchHandler : UIResponder +@property (nonatomic, readonly) CustomTapGestureRecognizer* mouseRightClickTapRecognizer; // this object will be passed to onscreencontrol class for areVirtualControllerTaps flag setting + - (id)initWithView:(StreamView*)view andSettings:(TemporarySettings*)settings; diff --git a/Limelight/Input/RelativeTouchHandler.m b/Limelight/Input/RelativeTouchHandler.m index 0e0ddffe..e6f6954a 100644 --- a/Limelight/Input/RelativeTouchHandler.m +++ b/Limelight/Input/RelativeTouchHandler.m @@ -7,7 +7,6 @@ // #import "RelativeTouchHandler.h" -#import "CustomTapGestureRecognizer.h" #import "DataManager.h" #include @@ -24,7 +23,6 @@ static const int REFERENCE_HEIGHT = 720; BOOL isDragging; NSTimer* dragTimer; NSUInteger peakTouchCount; - CustomTapGestureRecognizer* rightClickTapRecognizer; #if TARGET_OS_TV UIGestureRecognizer* remotePressRecognizer; @@ -39,12 +37,12 @@ static const int REFERENCE_HEIGHT = 720; self->view = view; self->currentSettings = settings; // replace righclick recoginizing with my CustomTapGestureRecognizer for better experience, higher recoginizing rate. - rightClickTapRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(mouseRightClick)]; - rightClickTapRecognizer.numberOfTouchesRequired = 2; - rightClickTapRecognizer.tapDownTimeThreshold = RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S; // tap down time in seconds. - rightClickTapRecognizer.delaysTouchesBegan = NO; - rightClickTapRecognizer.delaysTouchesEnded = NO; - [self->view addGestureRecognizer:rightClickTapRecognizer]; + _mouseRightClickTapRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(mouseRightClick)]; + _mouseRightClickTapRecognizer.numberOfTouchesRequired = 2; + _mouseRightClickTapRecognizer.tapDownTimeThreshold = RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S; // tap down time in seconds. + _mouseRightClickTapRecognizer.delaysTouchesBegan = NO; + _mouseRightClickTapRecognizer.delaysTouchesEnded = NO; + [self->view addGestureRecognizer:_mouseRightClickTapRecognizer]; @@ -134,7 +132,7 @@ static const int REFERENCE_HEIGHT = 720; CGPoint secondLocation = [[[[event allTouches] allObjects] objectAtIndex:1] locationInView:view]; CGPoint avgLocation = CGPointMake((firstLocation.x + secondLocation.x) / 2, (firstLocation.y + secondLocation.y) / 2); - if ((CACurrentMediaTime() - rightClickTapRecognizer.gestureCapturedTime > RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S) && touchLocation.y != avgLocation.y) { //prevent sending scrollevent while right click gesture is being recognized. The time threshold is only 150ms, resulting in a barely noticeable delay before the scroll event is activated. + if ((CACurrentMediaTime() - _mouseRightClickTapRecognizer.gestureCapturedTime > RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S) && touchLocation.y != avgLocation.y) { //prevent sending scrollevent while right click gesture is being recognized. The time threshold is only 150ms, resulting in a barely noticeable delay before the scroll event is activated. LiSendHighResScrollEvent((avgLocation.y - touchLocation.y) * 10); } diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index 102c8fd9..09510778 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -124,6 +124,12 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; } onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport streamConfig:streamConfig]; + // here we pass the tap recognizer to the onscreencontrols obj + if (settings.touchMode.intValue == RELATIVE_TOUCH){ + RelativeTouchHandler* relativeTouchHandler = (RelativeTouchHandler*) touchHandler; + onScreenControls.mouseRightClickTapRecognizer = relativeTouchHandler.mouseRightClickTapRecognizer; + } + OnScreenControlsLevel level = (OnScreenControlsLevel)[settings.onscreenControls integerValue]; if (settings.touchMode.intValue != RELATIVE_TOUCH && settings.touchMode.intValue != REGULAR_NATIVE_TOUCH ) { Log(LOG_I, @"On-screen controls disabled in non-relative touch mode");