소스 검색

Apple Pencil tap gesture while using server cursor

Luke Noble 3 년 전
부모
커밋
15dffe99cc
2개의 변경된 파일29개의 추가작업 그리고 0개의 파일을 삭제
  1. 28 0
      Platform/iOS/Display/VMDisplayMetalViewController+Touch.m
  2. 1 0
      Platform/iOS/Display/VMDisplayMetalViewController.h

+ 28 - 0
Platform/iOS/Display/VMDisplayMetalViewController+Touch.m

@@ -74,6 +74,10 @@ const CGFloat kScrollResistance = 10.0f;
     _tap.delegate = self;
     _tap.allowedTouchTypes = @[ @(UITouchTypeDirect) ];
     _tap.cancelsTouchesInView = NO;
+    _tapPencil = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureTapPencil:)];
+    _tapPencil.delegate = self;
+    _tapPencil.allowedTouchTypes = @[ @(UITouchTypePencil) ];
+    _tapPencil.cancelsTouchesInView = NO;
     _twoTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureTwoTap:)];
     _twoTap.numberOfTouchesRequired = 2;
     _twoTap.delegate = self;
@@ -91,6 +95,7 @@ const CGFloat kScrollResistance = 10.0f;
     [self.mtkView addGestureRecognizer:_twoPan];
     [self.mtkView addGestureRecognizer:_threePan];
     [self.mtkView addGestureRecognizer:_tap];
+    [self.mtkView addGestureRecognizer:_tapPencil];
     [self.mtkView addGestureRecognizer:_twoTap];
     [self.mtkView addGestureRecognizer:_longPress];
     [self.mtkView addGestureRecognizer:_pinch];
@@ -417,6 +422,23 @@ static CGFloat CGPointToPixel(CGFloat point) {
     }
 }
 
+- (IBAction)gestureTapPencil:(UITapGestureRecognizer *)sender {
+    if (sender.state == UIGestureRecognizerStateEnded &&
+        self.serverModeCursor) { // otherwise we handle in touchesBegan
+        
+        CSInputButton button = kCSInputButtonLeft;
+        
+        if (@available(iOS 12.1, *)) {
+            if (_pencilForceRightClickOnce) {
+                button = kCSInputButtonRight;
+                _pencilForceRightClickOnce = false;
+            }
+        }
+        
+        [self mouseClick:button location:[sender locationInView:sender.view]];
+    }
+}
+
 - (IBAction)gestureTwoTap:(UITapGestureRecognizer *)sender {
     if (sender.state == UIGestureRecognizerStateEnded &&
         self.twoFingerTapType == VMGestureTypeRightClick) {
@@ -502,9 +524,15 @@ static CGFloat CGPointToPixel(CGFloat point) {
     if (gestureRecognizer == _tap && otherGestureRecognizer == _twoTap) {
         return YES;
     }
+    if (gestureRecognizer == _tapPencil && otherGestureRecognizer == _twoTap) {
+        return YES;
+    }
     if (gestureRecognizer == _longPress && otherGestureRecognizer == _tap) {
         return YES;
     }
+    if (gestureRecognizer == _longPress && otherGestureRecognizer == _tapPencil) {
+        return YES;
+    }
     if (gestureRecognizer == _longPress && otherGestureRecognizer == _twoTap) {
         return YES;
     }

+ 1 - 0
Platform/iOS/Display/VMDisplayMetalViewController.h

@@ -48,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
     UIPanGestureRecognizer *_twoPan;
     UIPanGestureRecognizer *_threePan;
     UITapGestureRecognizer *_tap;
+    UITapGestureRecognizer *_tapPencil;
     UITapGestureRecognizer *_twoTap;
     UILongPressGestureRecognizer *_longPress;
     UIPinchGestureRecognizer *_pinch;