Posts

Post not yet marked as solved
1 Replies
I tried [UIApplication.sharedApplication activateSceneSessionForRequest:[UISceneSessionActivationRequest requestWithRole:UISceneSessionRoleImmersiveSpaceApplication] errorHandler:nil] But doing so results in Error Domain=UISceneErrorDomain Code=1 "Scene session activation failed because the requested role "UISceneSessionRoleImmersiveSpaceApplication" is not supported.” Not sure why? However, using a manifest of <key>UIApplicationSceneManifest</key> <dict> <key>UIApplicationPreferredDefaultSceneSessionRole</key> <string>UISceneSessionRoleImmersiveSpaceApplication</string> <key>UIApplicationSupportsMultipleScenes</key> <true/> <key>UISceneConfigurations</key> <dict> <key>UISceneSessionRoleImmersiveSpaceApplication</key> <array> <dict> <key>UISceneConfigurationName</key> <string>ImmersiveApp</string> </dict> </array> </dict> </dict> Seems to work, giving callbacks to application:configurationForConnectingSceneSession:options with <UISceneSession: 0x60000179c540; role: UISceneSessionRoleImmersiveSpaceApplication; persistentIdentifier: org.qt-project.example-xrsimulator.rasterwindow:SFBSystemService-7F604A14-E3DE-43D2-86E0-05CC29DAE1DC; scene: (nil); configuration: <UISceneConfiguration: 0x60000179d140>; userInfo: <__NSDictionary0: 0x1e494e2e0>> So I’m not sure why the explicit activateSceneSessionForRequest API doesn’t work?
Post not yet marked as solved
3 Replies
To test things further, I've created a custom keyboard layout (attached), with the following mappings: +----------+--------------+--------------------+----------+ | Key code | Physical key | No modifiers layer | ⌘ layer | +----------+--------------+--------------------+----------+ | 7 | x | e | c | +----------+--------------+--------------------+----------+ | 8 | c | a | b | +----------+--------------+--------------------+----------+ | 9 | v | c | d | +----------+--------------+--------------------+----------+ Testing with an NSButton with .keyEquivalent = @"c" and .keyEquivalentModifierMask = NSEventModifierFlagCommand, I'm observing: Pressing the c key alone, or with ⌘, does not trigger the button, so the logic in NSButton does not seem to be based on the key code of the event (8) Pressing the x key alone does not trigger the button, but pressing ⌘x does, so the logic does seems to match on NSEvent.characters Pressing the v key alone does not trigger the button, nor does pressing ⌘v, so the logic does not to match on NSEvent.charactersIgnoringModifiers The behavior observed for [NSEvent _matchesKeyEquivalent:modifierMask:] seems to be exactly the same. This would indicate that a "correct and robust" implementation is: - (BOOL)performKeyEquivalent:(NSEvent *)event { if (event.modifierFlags & self.keyEquivalentModifierMask && [event.characters isEqualToString:self.keyEquivalent]) return YES; return NO; } It this the case? Are the more things to consider? Thanks! test-keyboard.keylayout.txt
Post not yet marked as solved
3 Replies
Thank you for your reply. I've observed the switch to a Latin/English-like layout (using Accessibility Keyboard) when pressing ⌘ for the Hebrew layout. The question is how an implementation of performKeyEquivalent would correctly account for and support this? Based on the performKeyEquivalent documentation here, and the Handling Key Events documentation here, the implementation should check the unmodified characters of the incoming events: You should extract the characters for a key equivalent using the NSEvent method charactersIgnoringModifiers. The implementation should extract the characters for a key equivalent from the passed-in NSEvent object using the charactersIgnoringModifiers method and then examine them to determine if they are a key equivalent it recognizes. Which naively would be something like: - (BOOL)performKeyEquivalent:(NSEvent *)event { if (event.modifierFlags & NSEventModifierFlagCommand) { if ([event.charactersIgnoringModifiers isEqualToString:@"c"]) return YES; } return NO; } But this implementation would fail to catch the Latin layer of the Hebrew layout. Assuming the documentation is incomplete, a more robust implementation would perhaps be something like: - (BOOL)performKeyEquivalent:(NSEvent *)event { if (event.modifierFlags & NSEventModifierFlagCommand) { if ([event.charactersIgnoringModifiers isEqualToString:@"c"]) return YES; if ([event.characters isEqualToString:@"c"]) return YES; } return NO; } But is that correct? Are there cases where comparing against both the modified and unmodified characters will fail or produce unexpected matches? Should the behavior be different based on properties of the keyboard layout? [NSEvent _matchesKeyEquivalent:modifierMask:] seems to handle this correctly, but contains references to text input APIs like TISCopyCurrentKeyboardInputSource, TSMGetInputSourceProperty, and TSMGetDeadKeyState, which seems to indicate the naive approach above is not sufficient to match AppKit's own behavior. The goal would be for the custom control to respond to performKeyEquivalent the same way an NSButton or NSMenuItem would in terms of which events are considered matches and which are not. In particular, for a generic control that allows user defined key equivalents, so without relying on specifics of any particular key equivalent.