Skip to content

Commit

Permalink
Merge pull request #19187 from hrydgard/keyboard-activation-fix
Browse files Browse the repository at this point in the history
iOS: Fix issue with keyboard popping up after file picker.
  • Loading branch information
hrydgard authored May 26, 2024
2 parents 2a3f8af + c26de64 commit 14225d4
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 22 deletions.
1 change: 1 addition & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ enum class SystemNotification {
TEST_JAVA_EXCEPTION,
KEEP_SCREEN_AWAKE,
ACTIVITY,
UI_STATE_CHANGED,
};

// I guess it's not super great architecturally to centralize this, since it's not general - but same with a lot of
Expand Down
1 change: 1 addition & 0 deletions Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void UpdateUIState(GlobalUIState newState) {
if (globalUIState != newState && globalUIState != UISTATE_EXIT) {
globalUIState = newState;
System_Notify(SystemNotification::DISASSEMBLY);
System_Notify(SystemNotification::UI_STATE_CHANGED);
System_SetKeepScreenBright(globalUIState == UISTATE_INGAME);
}
}
Expand Down
32 changes: 22 additions & 10 deletions UI/DarwinFileSystemServices.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ppsspp_config.h"
#include "Core/Config.h"
#include "Common/Log.h"
#include "DarwinFileSystemServices.h"
#include <dispatch/dispatch.h>
#include <CoreServices/CoreServices.h>
Expand All @@ -16,6 +17,7 @@
#endif

#if __has_include(<UIKit/UIKit.h>)
#include "../ios/ViewControllerCommon.h"
#include <UIKit/UIKit.h>

@interface DocumentPickerDelegate : NSObject <UIDocumentPickerDelegate>
Expand All @@ -24,18 +26,27 @@ @interface DocumentPickerDelegate : NSObject <UIDocumentPickerDelegate>

@implementation DocumentPickerDelegate
-(instancetype)initWithCallback: (DarwinDirectoryPanelCallback)callback {
if (self = [super init]) {
self.callback = callback;
}

return self;
if (self = [super init]) {
self.callback = callback;
}
return self;
}

- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
if (urls.count >= 1)
- (void)didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
if (urls.count >= 1)
self.callback(true, Path(urls[0].path.UTF8String));
else
self.callback(false, Path());
else
self.callback(false, Path());

INFO_LOG(SYSTEM, "Callback processed, pre-emptively hide keyboard");
[sharedViewController hideKeyboard];
}

- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
self.callback(false, Path());

INFO_LOG(SYSTEM, "Picker cancelled, pre-emptively hide keyboard");
[sharedViewController hideKeyboard];
}

@end
Expand Down Expand Up @@ -77,6 +88,7 @@ - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocum
// panel.allowedFileTypes = @[(__bridge NSString *)kUTTypeFolder];

NSModalResponse modalResponse = [panel runModal];
INFO_LOG(SYSTEM, "Mac: Received response from modal");
if (modalResponse == NSModalResponseOK && panel.URLs.firstObject) {
callback(true, Path(panel.URLs.firstObject.path.UTF8String));
} else if (modalResponse == NSModalResponseCancel) {
Expand Down Expand Up @@ -144,4 +156,4 @@ void RestartMacApp() {
[task launch];
exit(0);
#endif
}
}
13 changes: 10 additions & 3 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,16 +712,23 @@ void InitPadLayout(float xres, float yres, float globalScale) {
bottom_key_spacing *= 0.8f;
}

// On IOS, nudge the bottom button up a little to avoid the task switcher.
#if PPSSPP_PLATFORM(IOS)
const float bottom_button_Y = 80.0f;
#else
const float bottom_button_Y = 60.0f;
#endif

int start_key_X = halfW + bottom_key_spacing * scale;
int start_key_Y = yres - 60 * scale;
int start_key_Y = yres - bottom_button_Y * scale;
initTouchPos(g_Config.touchStartKey, start_key_X, start_key_Y);

int select_key_X = halfW;
int select_key_Y = yres - 60 * scale;
int select_key_Y = yres - bottom_button_Y * scale;
initTouchPos(g_Config.touchSelectKey, select_key_X, select_key_Y);

int fast_forward_key_X = halfW - bottom_key_spacing * scale;
int fast_forward_key_Y = yres - 60 * scale;
int fast_forward_key_Y = yres - bottom_button_Y * scale;
initTouchPos(g_Config.touchFastForwardKey, fast_forward_key_X, fast_forward_key_Y);

// L and R------------------------------------------------------------
Expand Down
32 changes: 25 additions & 7 deletions ios/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,22 @@ - (void)controllerDidDisconnect:(NSNotification *)note
// Enables tapping for edge area.
-(UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
return UIRectEdgeAll;
if (GetUIState() == UISTATE_INGAME) {
// In-game, we need all the control we can get. Though, we could possibly
// allow the top edge?
INFO_LOG(SYSTEM, "Defer system gestures on all edges");
return UIRectEdgeAll;
} else {
INFO_LOG(SYSTEM, "Allow system gestures on the bottom");
// Allow task switching gestures to take precedence, without causing
// scroll events in the UI.
return UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight;
}
}

- (void)uiStateChanged
{
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
}

- (UIView *)getView {
Expand Down Expand Up @@ -448,18 +463,14 @@ -(void) deleteBackward {
INFO_LOG(SYSTEM, "Backspace");
}

-(BOOL) hasText
{
return YES;
}

-(void) insertText:(NSString *)text
{
std::string str = std::string([text UTF8String]);
INFO_LOG(SYSTEM, "Chars: %s", str.c_str());
UTF8 chars(str);
while (!chars.end()) {
uint32_t codePoint = chars.next();
INFO_LOG(SYSTEM, "Codepoint#: %d", codePoint);
KeyInput input{};
input.deviceId = DEVICE_ID_KEYBOARD;
input.flags = KEY_CHAR;
Expand All @@ -470,17 +481,24 @@ -(void) insertText:(NSString *)text

-(BOOL) canBecomeFirstResponder
{
return YES;
return true;
}

-(BOOL) hasText
{
return true;
}

-(void) showKeyboard {
dispatch_async(dispatch_get_main_queue(), ^{
INFO_LOG(SYSTEM, "becomeFirstResponder");
[self becomeFirstResponder];
});
}

-(void) hideKeyboard {
dispatch_async(dispatch_get_main_queue(), ^{
INFO_LOG(SYSTEM, "resignFirstResponder");
[self resignFirstResponder];
});
}
Expand Down
2 changes: 2 additions & 0 deletions ios/ViewControllerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- (void)didBecomeActive;
- (void)willResignActive;

- (void)uiStateChanged;

@end

extern id <PPSSPPViewController> sharedViewController;
Expand Down
17 changes: 16 additions & 1 deletion ios/ViewControllerMetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,22 @@ - (void)viewSafeAreaInsetsDidChange {
// Enables tapping for edge area.
-(UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
return UIRectEdgeAll;
if (GetUIState() == UISTATE_INGAME) {
// In-game, we need all the control we can get. Though, we could possibly
// allow the top edge?
INFO_LOG(SYSTEM, "Defer system gestures on all edges");
return UIRectEdgeAll;
} else {
INFO_LOG(SYSTEM, "Allow system gestures on the bottom");
// Allow task switching gestures to take precedence, without causing
// scroll events in the UI.
return UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight;
}
}

- (void)uiStateChanged
{
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
}

- (void)bindDefaultFBO
Expand Down
10 changes: 9 additions & 1 deletion ios/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,15 @@ bool System_GetPropertyBool(SystemProperty prop) {

void System_Notify(SystemNotification notification) {
switch (notification) {
default: break;
case SystemNotification::UI_STATE_CHANGED:
dispatch_async(dispatch_get_main_queue(), ^{
if (sharedViewController) {
[sharedViewController uiStateChanged];
}
});
break;
default:
break;
}
}

Expand Down

0 comments on commit 14225d4

Please sign in to comment.