mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-11-22 03:30:59 +00:00
always show keyboard again when pressing keyboard button
This commit is contained in:
parent
772ce2c326
commit
afef4e5b25
@ -32,6 +32,7 @@ extern NSString *DocumentsChangedNotification;
|
||||
- (IBAction)showInsertDisk:(id)sender;
|
||||
- (IBAction)showSettings:(id)sender;
|
||||
- (IBAction)showGestureHelp:(id)sender;
|
||||
- (UIScene*)sceneWithName:(NSString*)name;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -333,13 +333,12 @@ NSString *DocumentsChangedNotification = @"documentsChanged";
|
||||
return [UISceneConfiguration configurationWithName:@"Keyboard" sessionRole:UIWindowSceneSessionRoleApplication];
|
||||
}
|
||||
}
|
||||
if (![self hasDefaultScene]) {
|
||||
if ([self sceneWithName:@"Default"] == nil) {
|
||||
return [UISceneConfiguration configurationWithName:@"Default" sessionRole:UIWindowSceneSessionRoleApplication];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
|
||||
// if only keyboard is left, show default view again
|
||||
if (![self hasDefaultScene]) {
|
||||
@ -348,13 +347,13 @@ NSString *DocumentsChangedNotification = @"documentsChanged";
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)hasDefaultScene {
|
||||
- (UIScene*)sceneWithName:(NSString*)name {
|
||||
for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
|
||||
if ([scene.session.configuration.name isEqualToString:@"Default"]) {
|
||||
return YES;
|
||||
if ([scene.session.configuration.name isEqualToString:name]) {
|
||||
return scene;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -20,6 +20,7 @@ class KeyboardSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
fatalError("No main view controller")
|
||||
}
|
||||
|
||||
scene.activationConditions.canActivateForTargetContentIdentifierPredicate = NSPredicate(format: "self == 'net.namedfork.keyboard'", argumentArray: nil)
|
||||
let defaultSize = mainViewController.keyboardViewController.preferredContentSize
|
||||
let minSize = defaultSize.applying(.init(scaleX: 0.75, y: 0.75))
|
||||
let maxSize = defaultSize.applying(.init(scaleX: 1.25, y: 1.25))
|
||||
@ -33,6 +34,14 @@ class KeyboardSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
))
|
||||
window = UIWindow(windowScene: windowScene)
|
||||
|
||||
// destroy existing keyboard window
|
||||
if let oldWindow = mainViewController.keyboardViewController?.view?.window {
|
||||
oldWindow.rootViewController = nil
|
||||
if let oldScene = oldWindow.windowScene?.session.scene {
|
||||
UIApplication.shared.requestSceneSessionDestruction(oldScene.session, options: nil)
|
||||
}
|
||||
}
|
||||
|
||||
if let window {
|
||||
window.rootViewController = mainViewController.keyboardViewController
|
||||
window.makeKeyAndVisible()
|
||||
|
@ -320,17 +320,24 @@ static int8_t usb_to_adb_scancode[] = {
|
||||
}
|
||||
|
||||
- (void)setKeyboardVisible:(BOOL)visible animated:(BOOL)animated {
|
||||
if (self.keyboardVisible == visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(TARGET_OS_VISION) && TARGET_OS_VISION == 1
|
||||
if (visible) {
|
||||
UISceneSessionActivationRequest *request = [UISceneSessionActivationRequest requestWithRole:UIWindowSceneSessionRoleApplication];
|
||||
request.userActivity = [[NSUserActivity alloc] initWithActivityType:@"net.namedfork.keyboard"];
|
||||
[[UIApplication sharedApplication] activateSceneSessionForRequest:request errorHandler:nil];
|
||||
} // only show, no hide
|
||||
request.userActivity.targetContentIdentifier = @"net.namedfork.keyboard";
|
||||
[[UIApplication sharedApplication] activateSceneSessionForRequest:request errorHandler:^(NSError * _Nonnull error) {
|
||||
NSLog(@"Activation error: %@", error);
|
||||
}];
|
||||
} else {
|
||||
UIScene *keyboardScene = [[AppDelegate sharedInstance] sceneWithName:@"Keyboard"];
|
||||
if (keyboardScene != nil) {
|
||||
[[UIApplication sharedApplication] requestSceneSessionDestruction:keyboardScene.session options:nil errorHandler:nil];
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (self.keyboardVisible == visible) {
|
||||
return;
|
||||
}
|
||||
if (visible) {
|
||||
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"keyboardLayout" options:0 context:NULL];
|
||||
[self loadKeyboardView];
|
||||
|
Loading…
Reference in New Issue
Block a user