Merge pull request #35 from narbs/master

Add support for mouse pointer interaction introduced in iOS 13.4
This commit is contained in:
Jesús A. Álvarez 2020-03-31 12:09:56 +02:00 committed by GitHub
commit 3af32e9acc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -10,7 +10,12 @@
#import "ScreenView.h"
#import "KBKeyboardView.h"
#ifdef __IPHONE_13_4
API_AVAILABLE(ios(13.4))
@interface ViewController : UIViewController <UIPointerInteractionDelegate, KBKeyboardViewDelegate>
#else
@interface ViewController : UIViewController <KBKeyboardViewDelegate>
#endif
@property (weak, nonatomic) IBOutlet ScreenView *screenView;
@property (nonatomic, getter=isKeyboardVisible) BOOL keyboardVisible;

View File

@ -13,6 +13,8 @@
#import "KBKeyboardView.h"
#import "KBKeyboardLayout.h"
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
@interface ViewController ()
@end
@ -22,8 +24,36 @@
KBKeyboardView *keyboardView;
UISwipeGestureRecognizer *showKeyboardGesture, *hideKeyboardGesture, *insertDiskGesture, *showSettingsGesture;
UIControl *pointingDeviceView;
#ifdef __IPHONE_13_4
UIPointerInteraction* interaction;
#endif
}
- (Point)mouseLocForCGPoint:(CGPoint)point {
Point mouseLoc;
CGRect screenBounds = self.screenView.screenBounds;
CGSize screenSize = self.screenView.screenSize;
mouseLoc.h = (point.x - screenBounds.origin.x) * (screenSize.width/screenBounds.size.width);
mouseLoc.v = (point.y - screenBounds.origin.y) * (screenSize.height/screenBounds.size.height);
return mouseLoc;
}
#ifdef __IPHONE_13_4
- (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4)){
if (request != nil) {
Point mouseLoc = [self mouseLocForCGPoint:request.location];
// NSLog(@"Interaction: x2: %hi, y2: %hi", (short)mouseLoc.h, (short)mouseLoc.v);
[[AppDelegate sharedEmulator] setMouseX:mouseLoc.h Y:mouseLoc.v];
}
return defaultRegion;
}
- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region {
return [UIPointerStyle hiddenPointerStyle];
}
#endif
- (void)viewDidLoad {
[super viewDidLoad];
[self installKeyboardGestures];
@ -63,6 +93,12 @@
[pointingDeviceView removeFromSuperview];
pointingDeviceView = nil;
}
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.4")) {
interaction = [[UIPointerInteraction alloc] initWithDelegate: self];
[self.view addInteraction:interaction];
}
BOOL useTrackPad = [[NSUserDefaults standardUserDefaults] boolForKey:@"trackpad"];
Class pointingDeviceClass = useTrackPad ? [TrackPad class] : [TouchScreen class];
pointingDeviceView = [[pointingDeviceClass alloc] initWithFrame:self.view.bounds];