Simplify border detection in native touch modes
This commit is contained in:
1 parent
cb034b96a4
commit
2b5a1c0551
6 files changed
+201
-21
No files matched your search
@@ -11,7 +11,6 @@
|
||||
#import "NativeTouchPointer.h"
|
||||
#import "OnScreenControls.h"
|
||||
#import "StreamView.h"
|
||||
#import "DataManager.h"
|
||||
|
||||
#include <Limelight.h>
|
||||
|
||||
@@ -22,7 +21,7 @@
|
||||
StreamView* streamView;
|
||||
TemporarySettings* currentSettings;
|
||||
bool activateCoordSelector;
|
||||
bool notPureNativeTouchMode;
|
||||
bool touchPointSpawnedAtUpperScreenEdge;
|
||||
|
||||
// Use a Dictionary to store UITouch object's memory address as key, and pointerId as value,字典存放UITouch对象地址和pointerId映射关系
|
||||
// pointerId will be generated from a pre-defined pool
|
||||
@@ -31,7 +30,7 @@
|
||||
NSMutableSet<NSNumber *> *activePointerIds; //pointerId Set for active touches.
|
||||
NSMutableSet<NSNumber *> *pointerIdPool; //pre-defined pool of pointerIds.
|
||||
NSMutableSet<NSNumber *> *unassignedPointerIds;
|
||||
NSMutableSet<NSNumber *> *excludedPointerIds; // a NSSet of pointerIds of touches that will not be sent to the remote PC for better swipe gesture handling
|
||||
|
||||
CGFloat slideGestureVerticalThreshold;
|
||||
CGFloat screenWidthWithThreshold;
|
||||
CGFloat EDGE_TOLERANCE;
|
||||
@@ -42,7 +41,7 @@
|
||||
self->streamView = view;
|
||||
self->currentSettings = settings;
|
||||
self->activateCoordSelector = currentSettings.pointerVelocityModeDivider.floatValue != 1.0;
|
||||
self->notPureNativeTouchMode = !(currentSettings.touchMode.intValue == PURE_NATIVE_TOUCH);
|
||||
// self->notPureNativeTouchMode = !(currentSettings.touchMode.intValue == PURE_NATIVE_TOUCH);
|
||||
|
||||
self->pointerIdDict = [NSMutableDictionary dictionary];
|
||||
self->pointerIdPool = [NSMutableSet set];
|
||||
@@ -50,7 +49,8 @@
|
||||
[self->pointerIdPool addObject:@(i)];
|
||||
}
|
||||
self->activePointerIds = [NSMutableSet set];
|
||||
self->excludedPointerIds = [[NSMutableSet alloc] init];
|
||||
// self->excludedPointerIds = [[NSMutableSet alloc] init];
|
||||
self->touchPointSpawnedAtUpperScreenEdge = false;
|
||||
|
||||
EDGE_TOLERANCE = 15.0;
|
||||
slideGestureVerticalThreshold = CGRectGetHeight([[UIScreen mainScreen] bounds]) * 0.4;
|
||||
@@ -75,9 +75,12 @@
|
||||
[pointerIdDict setObject:@(pointerId) forKey:@(memAddrValue)];
|
||||
[activePointerIds addObject:@(pointerId)];
|
||||
|
||||
//check if touch point is spawned on the left or right upper half screen edges, if so we'll populate the excluded pointer id NSSet and not send the touch event to remote PC. this is for better handling in-stream slide gesture
|
||||
//check if touch point is spawned on the left or right upper half screen edges, event to remote PC. this is for better handling in-stream slide gesture
|
||||
CGPoint initialPoint = [touch locationInView:self->streamView];
|
||||
if(initialPoint.y < slideGestureVerticalThreshold && (initialPoint.x < EDGE_TOLERANCE || initialPoint.x > screenWidthWithThreshold)) [excludedPointerIds addObject:@(pointerId)];
|
||||
if(initialPoint.y < slideGestureVerticalThreshold && (initialPoint.x < EDGE_TOLERANCE || initialPoint.x > screenWidthWithThreshold)) {
|
||||
self->touchPointSpawnedAtUpperScreenEdge = true;
|
||||
// [excludedPointerIds addObject:@(pointerId)];
|
||||
}
|
||||
}
|
||||
|
||||
// remove pointerId in touchesEnded or touchesCancelled
|
||||
@@ -87,7 +90,7 @@
|
||||
if(pointerIdObj != nil){
|
||||
[activePointerIds removeObject:pointerIdObj];
|
||||
[pointerIdDict removeObjectForKey:@(memAddrValue)];
|
||||
if([excludedPointerIds containsObject:pointerIdObj]) [excludedPointerIds removeObject:pointerIdObj]; // remove pointer id from excludedPointerId NSSet
|
||||
// if([excludedPointerIds containsObject:pointerIdObj]) [excludedPointerIds removeObject:pointerIdObj]; // remove pointer id from excludedPointerId NSSet
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,12 +102,10 @@
|
||||
|
||||
|
||||
- (void)sendTouchEvent:(UITouch*)touch withTouchtype:(uint8_t)touchType{
|
||||
CGPoint targetCoords;
|
||||
uint8_t pointerId = [self retrievePointerIdFromDict:touch];
|
||||
// NSLog(@"excluded count: %d", (uint32_t)[excludedPointerIds count]);
|
||||
if(touchPointSpawnedAtUpperScreenEdge) return; // we're done here. this touch event will not be sent to the remote PC. and this must be checked after coord selector finishes populating new relative coords, or the app will crash!
|
||||
|
||||
if([excludedPointerIds containsObject:@(pointerId)]) return; // if the pointerId has been excluded by edge check, we're done here. this touch event will not be sent to the remote PC. and this must be checked after coord selector finishes populating new relative coords, or the app will crash!
|
||||
|
||||
CGPoint targetCoords;
|
||||
// NSLog(@"excluded count: %d", (uint32_t)[excludedPointerIds count]);
|
||||
if(activateCoordSelector && touch.phase == UITouchPhaseMoved) targetCoords = [NativeTouchPointer selectCoordsFor:touch]; // coordinates of touch pointer replaced to relative ones here.
|
||||
else targetCoords = [touch locationInView:streamView];
|
||||
|
||||
@@ -112,7 +113,8 @@
|
||||
CGSize videoSize = [streamView getVideoAreaSize];
|
||||
CGFloat normalizedX = location.x / videoSize.width;
|
||||
CGFloat normalizedY = location.y / videoSize.height;
|
||||
|
||||
uint8_t pointerId = [self retrievePointerIdFromDict:touch];
|
||||
|
||||
if([NativeTouchPointer getPointerObjFromDict:touch].needResetCoords){ // access whether the current pointer has reached the boundary, and need a coord reset.
|
||||
LiSendTouchEvent(LI_TOUCH_EVENT_UP, pointerId, normalizedX, normalizedY, 0, 0, 0, 0); //event must sent from the lowest level directy by LiSendTouchEvent to simulate continous dragging to another point on screen
|
||||
LiSendTouchEvent(LI_TOUCH_EVENT_DOWN, pointerId, 0.3, 0.4, 0, 0, 0, 0);
|
||||
@@ -122,7 +124,7 @@
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
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(notPureNativeTouchMode && [OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) continue;
|
||||
if([OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) continue;
|
||||
[self handleTouchDown:touch]; //generate & populate pointerId
|
||||
if(activateCoordSelector) [NativeTouchPointer populatePointerObjIntoDict:touch];
|
||||
[self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_DOWN];
|
||||
@@ -133,7 +135,7 @@
|
||||
// NSLog(@"captured by OSB touches: %d", (uint32_t)[OnScreenControls.touchAddrsCapturedByOnScreenControls count]);
|
||||
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(notPureNativeTouchMode && [OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) continue;
|
||||
if([OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) continue;
|
||||
if(activateCoordSelector) [NativeTouchPointer updatePointerObjInDict:touch];
|
||||
[self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_MOVE];
|
||||
[[NativeTouchPointer getPointerObjFromDict:touch] doesNeedResetCoords]; // execute the judging of doesReachBoundary for current pointer instance. (happens after the event is sent to Sunshine service)
|
||||
@@ -145,11 +147,12 @@
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
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(notPureNativeTouchMode && [OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) continue;
|
||||
if([OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) continue;
|
||||
[self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_UP]; //send touch event before remove pointerId
|
||||
[self removePointerId:touch]; //then remove pointerId
|
||||
if(activateCoordSelector) [NativeTouchPointer removePointerObjFromDict:touch];
|
||||
}
|
||||
if(touchPointSpawnedAtUpperScreenEdge && [[event allTouches] count] == [touches count]) touchPointSpawnedAtUpperScreenEdge = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user