From 8756a2100e2b8b86bbac7a0ae67d82bf97f9e0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 20 May 2024 15:38:04 +0200 Subject: [PATCH 1/3] iOS: Fix threading issue with launch-url --- ios/ViewController.mm | 8 +++++--- ios/main.mm | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 11649745cd..ca5148089b 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -197,7 +197,7 @@ extern float g_safeInsetBottom; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; view.drawableStencilFormat = GLKViewDrawableStencilFormat8; [EAGLContext setCurrentContext:self.context]; - self.preferredFramesPerSecond = 60; + self.preferredFramesPerSecond = 60; // NOTE: We don't yet take advantage of 120hz screens [[DisplayManager shared] updateResolution:[UIScreen mainScreen]]; @@ -239,7 +239,6 @@ extern float g_safeInsetBottom; NativeFrame(graphicsContext); } - INFO_LOG(SYSTEM, "Emulation thread shutting down\n"); NativeShutdownGraphics(); @@ -752,7 +751,10 @@ void stopLocation() { void System_LaunchUrl(LaunchUrlType urlType, char const* url) { - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithCString:url encoding:NSStringEncodingConversionAllowLossy]]]; + NSURL *nsUrl = [NSURL URLWithString:[NSString stringWithCString:url encoding:NSStringEncodingConversionAllowLossy]]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] openURL:nsUrl] options:@{} completionHandler:nil]; + }); } void bindDefaultFBO() diff --git a/ios/main.mm b/ios/main.mm index 073304b3ca..a51a65bc2e 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -437,6 +437,16 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string [sharedViewController shareText:text]; return true; } +/* + // Not 100% sure the threading is right + case SystemRequestType::COPY_TO_CLIPBOARD: + { + @autoreleasepool { + [UIPasteboard generalPasteboard].string = @(param1.c_str()); + return 0; + } + } +*/ case SystemRequestType::SET_KEEP_SCREEN_BRIGHT: dispatch_async(dispatch_get_main_queue(), ^{ INFO_LOG(SYSTEM, "SET_KEEP_SCREEN_BRIGHT: %d", (int)param3); From aa6962df4a204bfacad1af56363f9ec32f144c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 20 May 2024 16:12:25 +0200 Subject: [PATCH 2/3] iOS swipe gesture recognizer experiment --- ios/ViewController.h | 2 +- ios/ViewController.mm | 19 ++++++++++++++++++- ios/main.mm | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ios/ViewController.h b/ios/ViewController.h index d64d973c77..d17de68c1c 100644 --- a/ios/ViewController.h +++ b/ios/ViewController.h @@ -10,7 +10,7 @@ #import "LocationHelper.h" @interface ViewController : GLKViewController + LocationHandlerDelegate, CameraFrameDelegate, UIGestureRecognizerDelegate> - (void)shareText:(NSString *)text; - (void)shutdown; diff --git a/ios/ViewController.mm b/ios/ViewController.mm index ca5148089b..fa0ce2f52b 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -192,6 +192,12 @@ extern float g_safeInsetBottom; self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; } + UISwipeGestureRecognizer *mSwipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; + + [mSwipeLeftRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)]; + + [[self view] addGestureRecognizer:mSwipeLeftRecognizer]; + GLKView* view = (GLKView *)self.view; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; @@ -250,6 +256,17 @@ extern float g_safeInsetBottom; }); } +- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer +{ + if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) { + INFO_LOG(SYSTEM, "LEFT"); + } else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) { + INFO_LOG(SYSTEM, "RIGHT"); + } else { + INFO_LOG(SYSTEM, "OTHER SWIPE: %d", (int)recognizer.direction); + } +} + - (void)appWillTerminate:(NSNotification *)notification { [self shutdown]; @@ -753,7 +770,7 @@ void System_LaunchUrl(LaunchUrlType urlType, char const* url) { NSURL *nsUrl = [NSURL URLWithString:[NSString stringWithCString:url encoding:NSStringEncodingConversionAllowLossy]]; dispatch_async(dispatch_get_main_queue(), ^{ - [[UIApplication sharedApplication] openURL:nsUrl] options:@{} completionHandler:nil]; + [[UIApplication sharedApplication] openURL:nsUrl options:@{} completionHandler:nil]; }); } diff --git a/ios/main.mm b/ios/main.mm index a51a65bc2e..28d1bdf6aa 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -560,3 +560,4 @@ int main(int argc, char *argv[]) return UIApplicationMain(argc, argv, NSStringFromClass([PPSSPPUIApplication class]), NSStringFromClass([AppDelegate class])); } } + From c083e0966a84f3abb2197411228ae3916aad7c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 20 May 2024 16:22:27 +0200 Subject: [PATCH 3/3] iOS: Add recognizer for swipe-from-left-edge gesture, for Back --- ios/ViewController.mm | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ios/ViewController.mm b/ios/ViewController.mm index fa0ce2f52b..b25b5cb83e 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -192,12 +192,10 @@ extern float g_safeInsetBottom; self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; } - UISwipeGestureRecognizer *mSwipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; + UIScreenEdgePanGestureRecognizer *mBackGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:) ]; + [mBackGestureRecognizer setEdges:UIRectEdgeLeft]; + [[self view] addGestureRecognizer:mBackGestureRecognizer]; - [mSwipeLeftRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)]; - - [[self view] addGestureRecognizer:mSwipeLeftRecognizer]; - GLKView* view = (GLKView *)self.view; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; @@ -256,15 +254,16 @@ extern float g_safeInsetBottom; }); } -- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer +- (void)handleSwipeFrom:(UIScreenEdgePanGestureRecognizer *)recognizer { - if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) { - INFO_LOG(SYSTEM, "LEFT"); - } else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) { - INFO_LOG(SYSTEM, "RIGHT"); - } else { - INFO_LOG(SYSTEM, "OTHER SWIPE: %d", (int)recognizer.direction); - } + if (recognizer.state == UIGestureRecognizerStateEnded) { + KeyInput key; + key.flags = KEY_DOWN | KEY_UP; + key.keyCode = NKCODE_BACK; + key.deviceId = DEVICE_ID_TOUCH; + NativeKey(key); + INFO_LOG(SYSTEM, "Detected back swipe"); + } } - (void)appWillTerminate:(NSNotification *)notification