Skip to content

Commit

Permalink
Suppress accidental movements during drags and clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Sep 11, 2017
1 parent 45dbd46 commit 7d7500b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Limelight/Input/StreamView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#import "ControllerSupport.h"

@implementation StreamView {
CGPoint touchLocation;
CGPoint touchLocation, originalLocation;
BOOL touchMoved;
OnScreenControls* onScreenControls;

Expand Down Expand Up @@ -46,11 +46,16 @@ - (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelega
}
}

- (Boolean)isConfirmedMove:(CGPoint)currentPoint from:(CGPoint)originalPoint {
// Movements of greater than 20 pixels are considered confirmed
return hypotf(originalPoint.x - currentPoint.x, originalPoint.y - currentPoint.y) >= 20;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
Log(LOG_D, @"Touch down");
if (![onScreenControls handleTouchDownEvent:touches]) {
UITouch *touch = [[event allTouches] anyObject];
touchLocation = [touch locationInView:self];
originalLocation = touchLocation = [touch locationInView:self];
touchMoved = false;
if ([[event allTouches] count] == 1 && !isDragging) {
dragTimer = [NSTimer scheduledTimerWithTimeInterval:0.650
Expand Down Expand Up @@ -88,8 +93,13 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

if (deltaX != 0 || deltaY != 0) {
LiSendMouseMoveEvent(deltaX, deltaY);
touchMoved = true;
touchLocation = currentLocation;

// If we've moved far enough to confirm this wasn't just human/machine error,
// mark it as such.
if ([self isConfirmedMove:touchLocation from:originalLocation]) {
touchMoved = true;
}
}
}
} else if ([[event allTouches] count] == 2) {
Expand All @@ -100,7 +110,13 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (touchLocation.y != avgLocation.y) {
LiSendScrollEvent(avgLocation.y - touchLocation.y);
}
touchMoved = true;

// If we've moved far enough to confirm this wasn't just human/machine error,
// mark it as such.
if ([self isConfirmedMove:firstLocation from:originalLocation]) {
touchMoved = true;
}

touchLocation = avgLocation;
}
}
Expand Down

0 comments on commit 7d7500b

Please sign in to comment.