From e8ea942ad2692967746f1f7104bef0430479cd4f Mon Sep 17 00:00:00 2001 From: Mimiste Date: Fri, 8 Apr 2016 00:12:59 +0200 Subject: [PATCH] Drag and drop Possibility to initiate a drag and drop - Touch for 2 second to initiate a drag - Move the cursor as usual - Tap top drop --- Limelight/Input/StreamView.m | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index 3f6cb9a..ee387b1 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -17,6 +17,9 @@ BOOL touchMoved; OnScreenControls* onScreenControls; + BOOL isDragging; + NSTimer* dragTimer; + float xDeltaFactor; float yDeltaFactor; float screenFactor; @@ -49,11 +52,25 @@ UITouch *touch = [[event allTouches] anyObject]; touchLocation = [touch locationInView:self]; touchMoved = false; + dragTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 + target:self + selector:@selector(onDragStart:) + userInfo:nil + repeats:NO]; + } +} + +- (void)onDragStart:(NSTimer*)timer { + if (!touchMoved && !isDragging){ + isDragging = true; + LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT); } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (![onScreenControls handleTouchMovedEvent:touches]) { + [dragTimer invalidate]; + dragTimer = nil; if ([[event allTouches] count] == 1) { UITouch *touch = [[event allTouches] anyObject]; CGPoint currentLocation = [touch locationInView:self]; @@ -91,6 +108,8 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { Log(LOG_D, @"Touch up"); if (![onScreenControls handleTouchUpEvent:touches]) { + [dragTimer invalidate]; + dragTimer = nil; if (!touchMoved) { if ([[event allTouches] count] == 2) { Log(LOG_D, @"Sending right mouse button press"); @@ -104,13 +123,15 @@ } else { - Log(LOG_D, @"Sending left mouse button press"); - - LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT); - - // Wait 100 ms to simulate a real button press - usleep(100 * 1000); - + if (!isDragging){ + Log(LOG_D, @"Sending left mouse button press"); + + LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT); + + // Wait 100 ms to simulate a real button press + usleep(100 * 1000); + } + isDragging = false; LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT); } }