mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-11-21 12:30:50 +00:00
visionOS: show layout menu from keyboard button
This commit is contained in:
parent
53cb92f4ef
commit
ed99d1bbfb
@ -22,6 +22,7 @@
|
||||
|
||||
@property (weak, nonatomic, nullable) id<KBKeyboardViewDelegate> delegate;
|
||||
@property (nonatomic, strong, nullable) KBKeyboardLayout *layout;
|
||||
@property (nonatomic, strong, nullable) UIMenu *layoutMenu;
|
||||
|
||||
@property (nonatomic, readonly, nonnull) NSArray<KBKey*>* keys;
|
||||
@property (nonatomic, readonly, nonnull) NSArray<KBKey*>* stickyKeys;
|
||||
|
@ -126,11 +126,15 @@
|
||||
keyFrame.origin.x += safeAreaInsets.left;
|
||||
}
|
||||
if (scancode == VKC_HIDE) {
|
||||
#if defined(TARGET_OS_VISION) && TARGET_OS_VISION == 1
|
||||
// close window to hide
|
||||
return;
|
||||
#else
|
||||
key = [[KBHideKey alloc] initWithFrame:keyFrame];
|
||||
#if defined(TARGET_OS_VISION) && TARGET_OS_VISION == 1
|
||||
if (self.layoutMenu != nil) {
|
||||
key.showsMenuAsPrimaryAction = YES;
|
||||
key.menu = self.layoutMenu;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
#else
|
||||
[key addTarget:self action:@selector(hideKeyboard:) forControlEvents:UIControlEventTouchUpInside];
|
||||
#endif
|
||||
} else if (scancode == VKC_SHIFT_CAPS) {
|
||||
|
@ -27,5 +27,6 @@
|
||||
@property (nonatomic, readonly) UIViewController* keyboardViewController;
|
||||
- (void)initXr;
|
||||
+ (void)adjustToScreenSize;
|
||||
- (UIMenu*)keyboardLayoutMenu;
|
||||
@end
|
||||
#endif
|
||||
|
@ -67,6 +67,7 @@ API_AVAILABLE(ios(13.4))
|
||||
}
|
||||
}
|
||||
keyboardView = [[KBKeyboardView alloc] initWithFrame:CGRectMake(0, 0, keyboardSize.width, keyboardSize.height)];
|
||||
keyboardView.layoutMenu = [self keyboardLayoutMenu];
|
||||
keyboardView.layout = layout;
|
||||
keyboardView.delegate = self;
|
||||
}
|
||||
|
@ -62,5 +62,21 @@ extension ViewController {
|
||||
resizingRestrictions: .uniform
|
||||
))
|
||||
}
|
||||
|
||||
@objc
|
||||
func keyboardLayoutMenu() -> UIMenu {
|
||||
let layouts = AppDelegate.shared.keyboardLayoutPaths ?? []
|
||||
let items: [UIMenuElement] = layouts.map({ path in
|
||||
UIDeferredMenuElement.uncached { completion in
|
||||
let layoutId = (path as NSString).lastPathComponent
|
||||
let displayName = (layoutId as NSString).deletingPathExtension
|
||||
let selected = UserDefaults.standard.string(forKey: "keyboardLayout") == layoutId
|
||||
completion([UIAction(title: displayName, state: selected ? .on : .off) { _ in
|
||||
UserDefaults.standard.setValue(layoutId, forKey: "keyboardLayout")
|
||||
}])
|
||||
}
|
||||
})
|
||||
return UIMenu(title: "Layout", options: [], children: items)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user