From ddfe6201a6e3b0027a4302cc973c59c27bfbfc74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Tue, 23 Jun 2020 19:07:30 +0200 Subject: [PATCH] handle hardware mouse in trackpad mode --- Mini vMac/TrackPad.m | 19 +++++++++++++++++++ Mini vMac/ViewController.m | 6 ++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Mini vMac/TrackPad.m b/Mini vMac/TrackPad.m index 0c5120e..7b3a79c 100644 --- a/Mini vMac/TrackPad.m +++ b/Mini vMac/TrackPad.m @@ -45,7 +45,21 @@ } } +- (BOOL)isMouseEvent:(UIEvent *)event { +#if __IPHONE_13_4 + if (@available(iOS 13.4, *)) { + return event.buttonMask != 0; + } +#endif + return NO; +} + - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { + if ([self isMouseEvent:event]) { + [self startDragging]; + return; + } + [currentTouches unionSet:touches]; if (currentTouches.count == 1) { [self firstTouchBegan:touches.anyObject withEvent:event]; @@ -67,6 +81,7 @@ } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { + if ([self isMouseEvent:event]) return; UITouch *touch = touches.anyObject; CGPoint touchLoc = [touch locationInView:self]; previousTouchLoc = [touch previousLocationInView:self]; @@ -91,6 +106,10 @@ } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { + if ([self isMouseEvent:event]) { + [self stopDragging]; + return; + } [currentTouches minusSet:touches]; if (currentTouches.count > 0) { return; diff --git a/Mini vMac/ViewController.m b/Mini vMac/ViewController.m index 7c8bc1c..c67688b 100644 --- a/Mini vMac/ViewController.m +++ b/Mini vMac/ViewController.m @@ -147,8 +147,10 @@ API_AVAILABLE(ios(13.4)) #ifdef __IPHONE_13_4 if (@available(iOS 13.4, *)) { - interaction = [[UIPointerInteraction alloc] initWithDelegate: self]; - [self.view addInteraction:interaction]; + if (interaction == nil) { + interaction = [[UIPointerInteraction alloc] initWithDelegate: self]; + [self.view addInteraction:interaction]; + } } #endif