diff --git a/Limelight/Input/CustomTapGestureRecognizer.h b/Limelight/Input/CustomTapGestureRecognizer.h index 8d987953..53823c44 100644 --- a/Limelight/Input/CustomTapGestureRecognizer.h +++ b/Limelight/Input/CustomTapGestureRecognizer.h @@ -18,7 +18,7 @@ @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 areOnScreenControllerTaps; // will be set by the onscreencontrol or other related class +@property (nonatomic, assign) bool containOnScreenControllerTaps; // will be set by the onscreencontrol class //@property (nonatomic, assign) bool haveOnScreenButtonsOnStreamview; @property (nonatomic, readonly) CGFloat lowestTouchPointHeight; @property (nonatomic, readonly) bool gestureCaptured; diff --git a/Limelight/Input/CustomTapGestureRecognizer.m b/Limelight/Input/CustomTapGestureRecognizer.m index ae2aaa08..de31fef4 100644 --- a/Limelight/Input/CustomTapGestureRecognizer.m +++ b/Limelight/Input/CustomTapGestureRecognizer.m @@ -33,7 +33,7 @@ static CGFloat screenWidthInPoints; _immediateTriggering = false; _tapDownTimeThreshold = 0.3; _gestureCaptured = false; - _areOnScreenControllerTaps = false; + _containOnScreenControllerTaps = false; return self; } @@ -74,14 +74,14 @@ static CGFloat screenWidthInPoints; _gestureCaptured = false; self.state = UIGestureRecognizerStateFailed; } - else if(_gestureCaptured && allTouchesCount == [touches count] && !_areOnScreenControllerTaps && ![self areOnScreenButtonsTaps]){ //must exclude virtual controller & onscreen button taps here to prevent stucked button, _areVirtualControllerTaps flag is set by onscreencontrols, areOnScreenButtonsTaps will be done by iterating all button views in streamframview + else if(_gestureCaptured && allTouchesCount == [touches count] && !_containOnScreenControllerTaps && ![self containOnScreenButtonTaps]){ //must exclude virtual controller & onscreen button taps here to prevent stucked button, _areVirtualControllerTaps flag is set by onscreencontrols, containOnScreenButtonsTaps will be returned by iterating all button views in streamframeview _gestureCaptured = false; //reset for next recognition if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){ lowestTouchPointYCoord = 0.0; //reset for next recognition self.state = UIGestureRecognizerStateRecognized; } } - if (allTouchesCount == [touches count]) _areOnScreenControllerTaps = false; // need to reset this flag anyway, when all fingers are lefting + if (allTouchesCount == [touches count]) _containOnScreenControllerTaps = false; // need to reset this flag anyway, when all fingers are lefting } @@ -89,19 +89,19 @@ static CGFloat screenWidthInPoints; // we're unable to import this class to swift codebase by the bridging header,and have to exlucde the onscreen button taps here // by iterating every button view instances. but it's basically ok since the number of buttonViews are always limited. // and this method will only be called when the recognizer is active & and the taps passes all the checks and is about to ge triggered. -- (bool)areOnScreenButtonsTaps { - NSTimeInterval t1 = CACurrentMediaTime(); +- (bool)containOnScreenButtonTaps { + NSTimeInterval allFingersTapDownTime = CACurrentMediaTime() - _gestureCapturedTime; //RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S has been passed to this recognizer as _tapDownTimeShreshold, we'll decide how to deal with pressed flag of on-screen button views based on tapDownTime bool gotOneButtonPressed = false; for(UIView* view in self.view.subviews){ if ([view isKindOfClass:[OnScreenButtonView class]]) { OnScreenButtonView* buttonView = (OnScreenButtonView*) view; - if(gotOneButtonPressed){ // once we have just 1 button pressed already, reset pressed flag for the all the buttonViews + if(gotOneButtonPressed && allFingersTapDownTime <= _tapDownTimeThreshold){ // once we have just 1 button pressed already,& the tapDownTime has not exceeded the threshold, we'll reset pressed flag for the all the buttonViews. buttonView.pressed = false; //reset the flag for buttonView continue; } if(buttonView.pressed){ gotOneButtonPressed = true; //got one button pressed - buttonView.pressed = false; // reset the flag for current buttonView + if(allFingersTapDownTime <= _tapDownTimeThreshold) buttonView.pressed = false; // reset the flag for current buttonView if tapDowntime is still within the threshold, if not, leave the flag for mouse scroller gesture in relative touch mode. } } } diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index 773ad822..db370382 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -910,7 +910,7 @@ static float L3_Y; button.cornerRadius = 45; // 使用 shadowPath 定义阴影形状和扩展范围 - CGFloat spread = 15; // 扩散的大小gggkkkoooovv + CGFloat spread = 15; // 扩散的大小 if([button.name isEqualToString:@"leftStick"] || [button.name isEqualToString:@"rightStick"]) spread = 12; CGRect largerRect = CGRectInset(button.bounds, -spread, -spread); UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:largerRect cornerRadius:button.cornerRadius]; @@ -1100,7 +1100,7 @@ static float L3_Y; if ([gesture isKindOfClass:[CustomTapGestureRecognizer class]]) { // This is a CustomTapGestureRecognizer CustomTapGestureRecognizer *tapGesture = (CustomTapGestureRecognizer *)gesture; - tapGesture.areOnScreenControllerTaps = true; + tapGesture.containOnScreenControllerTaps = true; // Perform actions with tapGesture } } diff --git a/Limelight/Input/RelativeTouchHandler.h b/Limelight/Input/RelativeTouchHandler.h index 8db13186..6d0832bb 100644 --- a/Limelight/Input/RelativeTouchHandler.h +++ b/Limelight/Input/RelativeTouchHandler.h @@ -10,6 +10,7 @@ #import "DataManager.h" #import "CustomTapGestureRecognizer.h" +#define RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S 0.15 NS_ASSUME_NONNULL_BEGIN diff --git a/Limelight/Input/RelativeTouchHandler.m b/Limelight/Input/RelativeTouchHandler.m index 681d50eb..4900af40 100644 --- a/Limelight/Input/RelativeTouchHandler.m +++ b/Limelight/Input/RelativeTouchHandler.m @@ -10,7 +10,6 @@ #import "DataManager.h" #include -#define RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S 0.15 static const int REFERENCE_WIDTH = 1280; @@ -60,6 +59,37 @@ static const int REFERENCE_HEIGHT = 720; return self; } +- (bool)containOnScreenControllerTaps: (NSSet* )touches{ + for(UITouch* touch in touches){ + if([OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) return true; + } + return false; +} + + +- (bool)containOnScreenButtonTaps { + bool gotOneButtonPressed = false; + for(UIView* view in self->view.superview.subviews){ // iterates all on-screen button views in StreamFrameView + if ([view isKindOfClass:[OnScreenButtonView class]]) { + OnScreenButtonView* buttonView = (OnScreenButtonView*) view; + if(buttonView.pressed){ + gotOneButtonPressed = true; //got one button pressed + } + } + } + return gotOneButtonPressed; +} + +- (void)resetAllPressedFlagsForOnscreenButtonViews { + for(UIView* view in self->view.superview.subviews){ // iterates all on-screen button views in StreamFrameView + if ([view isKindOfClass:[OnScreenButtonView class]]) { + OnScreenButtonView* buttonView = (OnScreenButtonView*) view; + buttonView.pressed = false; + } + } +} + + - (void)mouseRightClick { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ Log(LOG_D, @"Sending right mouse button press"); @@ -128,11 +158,13 @@ static const int REFERENCE_HEIGHT = 720; } } else if ([[event allTouches] count] == 2) { // mouse wheel scroll & right button click are both triggered by 2 finger gesture, some times cause competing (right click fails & scroll view jumps around). //I'll deal with this in coming code. - CGPoint firstLocation = [[[[event allTouches] allObjects] objectAtIndex:0] locationInView:view]; - CGPoint secondLocation = [[[[event allTouches] allObjects] objectAtIndex:1] locationInView:view]; + NSSet* twoTouches = [event allTouches]; + CGPoint firstLocation = [[[twoTouches allObjects] objectAtIndex:0] locationInView:view]; + CGPoint secondLocation = [[[twoTouches allObjects] objectAtIndex:1] locationInView:view]; CGPoint avgLocation = CGPointMake((firstLocation.x + secondLocation.x) / 2, (firstLocation.y + secondLocation.y) / 2); - 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. + if ((CACurrentMediaTime() - _mouseRightClickTapRecognizer.gestureCapturedTime > RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S) && touchLocation.y != avgLocation.y && ![self containOnScreenButtonTaps] && ![self containOnScreenControllerTaps:twoTouches]) { //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. + // and we must exclude onscreen button taps & on-screen controller taps LiSendHighResScrollEvent((avgLocation.y - touchLocation.y) * 10); } @@ -141,7 +173,6 @@ static const int REFERENCE_HEIGHT = 720; if ([self isConfirmedMove:firstLocation from:originalLocation]) { touchMoved = true; } - touchLocation = avgLocation; } } @@ -193,6 +224,8 @@ static const int REFERENCE_HEIGHT = 720; // right clicks without moving their other finger. touchMoved = true; } + + if([[event allTouches] count] == [touches count]) [self resetAllPressedFlagsForOnscreenButtonViews]; // reset all pressed flag for on-screen button views after all fingers lifted from screen. } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index 1d4697c5..51a1dcaa 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -84,7 +84,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; isInputingText = false; keyboardToggleRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleKeyboard)]; keyboardToggleRecognizer.numberOfTouchesRequired = settings.keyboardToggleFingers.intValue; //will be changed accordinly by touch modes. - keyboardToggleRecognizer.tapDownTimeThreshold = 0.3; // tap down time threshold in seconds. + keyboardToggleRecognizer.tapDownTimeThreshold = 0.2; // tap down time threshold in seconds. keyboardToggleRecognizer.delaysTouchesBegan = NO; keyboardToggleRecognizer.delaysTouchesEnded = NO; [[NSNotificationCenter defaultCenter] addObserver:self diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 53a16e82..c950b1c6 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -67,7 +67,7 @@ if((_settings.touchMode.intValue == RELATIVE_TOUCH || _settings.touchMode.intValue == REGULAR_NATIVE_TOUCH) && _settings.onscreenControls.intValue == OnScreenControlsLevelCustom){ _oscLayoutTapRecoginizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(layoutOSC)]; _oscLayoutTapRecoginizer.numberOfTouchesRequired = _settings.oscLayoutToolFingers.intValue; //tap a predefined number of fingers to open osc layout tool - _oscLayoutTapRecoginizer.tapDownTimeThreshold = 1; + _oscLayoutTapRecoginizer.tapDownTimeThreshold = 0.2; _oscLayoutTapRecoginizer.delaysTouchesBegan = NO; _oscLayoutTapRecoginizer.delaysTouchesEnded = NO;