Merge branch 'fix-macos-shortcuts' of https://github.com/page-down/kitty
This commit is contained in:
@@ -265,7 +265,6 @@ display_reconfigured(CGDirectDisplayID display UNUSED, CGDisplayChangeSummaryFla
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NSDictionary<NSString*,NSNumber*> *global_shortcuts = nil;
|
static NSDictionary<NSString*,NSNumber*> *global_shortcuts = nil;
|
||||||
static NSSet<NSNumber*> *global_configured_shortcuts = nil;
|
|
||||||
|
|
||||||
@interface GLFWHelper : NSObject
|
@interface GLFWHelper : NSObject
|
||||||
@end
|
@end
|
||||||
@@ -291,10 +290,6 @@ static NSSet<NSNumber*> *global_configured_shortcuts = nil;
|
|||||||
[global_shortcuts release];
|
[global_shortcuts release];
|
||||||
global_shortcuts = nil;
|
global_shortcuts = nil;
|
||||||
}
|
}
|
||||||
if (global_configured_shortcuts != nil) {
|
|
||||||
[global_configured_shortcuts release];
|
|
||||||
global_configured_shortcuts = nil;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end // GLFWHelper
|
@end // GLFWHelper
|
||||||
@@ -587,6 +582,7 @@ build_global_shortcuts_lookup(void) {
|
|||||||
// dump these in a terminal with: defaults read com.apple.symbolichotkeys
|
// dump these in a terminal with: defaults read com.apple.symbolichotkeys
|
||||||
NSMutableDictionary<NSString*, NSNumber*> *temp = [NSMutableDictionary dictionaryWithCapacity:128]; // will be autoreleased
|
NSMutableDictionary<NSString*, NSNumber*> *temp = [NSMutableDictionary dictionaryWithCapacity:128]; // will be autoreleased
|
||||||
NSMutableSet<NSNumber*> *temp_configured = [NSMutableSet setWithCapacity:128]; // will be autoreleased
|
NSMutableSet<NSNumber*> *temp_configured = [NSMutableSet setWithCapacity:128]; // will be autoreleased
|
||||||
|
NSMutableSet<NSNumber*> *temp_missing_value = [NSMutableSet setWithCapacity:128]; // will be autoreleased
|
||||||
NSDictionary *apple_settings = [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.apple.symbolichotkeys"];
|
NSDictionary *apple_settings = [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.apple.symbolichotkeys"];
|
||||||
if (apple_settings) {
|
if (apple_settings) {
|
||||||
NSDictionary<NSString*, id> *symbolic_hotkeys = [apple_settings objectForKey:@"AppleSymbolicHotKeys"];
|
NSDictionary<NSString*, id> *symbolic_hotkeys = [apple_settings objectForKey:@"AppleSymbolicHotKeys"];
|
||||||
@@ -600,7 +596,10 @@ build_global_shortcuts_lookup(void) {
|
|||||||
if (!enabled || ![enabled isKindOfClass:[NSNumber class]] ) continue;
|
if (!enabled || ![enabled isKindOfClass:[NSNumber class]] ) continue;
|
||||||
[temp_configured addObject:@(sc)];
|
[temp_configured addObject:@(sc)];
|
||||||
id v = [sc_value objectForKey:@"value"];
|
id v = [sc_value objectForKey:@"value"];
|
||||||
if (!v || ![v isKindOfClass:[NSDictionary class]]) continue;
|
if (!v || ![v isKindOfClass:[NSDictionary class]]) {
|
||||||
|
if ([(NSNumber*)enabled intValue]) [temp_missing_value addObject:@(sc)];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
NSDictionary *value = v;
|
NSDictionary *value = v;
|
||||||
id t = [value objectForKey:@"type"];
|
id t = [value objectForKey:@"type"];
|
||||||
if (!t || ![t isKindOfClass:[NSString class]] || ![t isEqualToString:@"standard"]) continue;
|
if (!t || ![t isKindOfClass:[NSString class]] || ![t isEqualToString:@"standard"]) continue;
|
||||||
@@ -625,14 +624,46 @@ build_global_shortcuts_lookup(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add global shortcut definitions when the default enabled shortcut is not defined,
|
||||||
|
// or when the default enabled shortcut is not disabled and is missing a value.
|
||||||
|
// Here are the shortcuts that are enabled by default in the standard ANSI (US) layout.
|
||||||
|
// macOS provides separate configurations for some languages or keyboards.
|
||||||
|
// In general, the rules here will not take effect.
|
||||||
|
static char buf[64];
|
||||||
|
#define S(i, t, m, k) if ([temp_configured member:@(i)] == nil || [temp_missing_value member:@(i)] != nil) { \
|
||||||
|
snprintf(buf, sizeof(buf) - 1, #t":%lx:%ld", (unsigned long)m, (long)k); \
|
||||||
|
temp[@(buf)] = @(i); \
|
||||||
|
}
|
||||||
|
|
||||||
|
// launchpad & dock
|
||||||
|
S(kSHKTurnDockHidingOnOrOff, c, (NSEventModifierFlagOption | NSEventModifierFlagCommand), 'd'); // Opt, Cmd, D
|
||||||
|
// mission control
|
||||||
|
S(kSHKMissionControl, v, NSEventModifierFlagControl, 126); // Ctrl, Arrow Up
|
||||||
|
S(kSHKApplicationWindows, v, NSEventModifierFlagControl, 125); // Ctrl, Arrow Down
|
||||||
|
// keyboard
|
||||||
|
S(kSHKMoveFocusToTheMenuBar, v, NSEventModifierFlagControl, 120); // Ctrl, F2
|
||||||
|
S(kSHKMoveFocusToTheDock, v, NSEventModifierFlagControl, 99); // Ctrl, F3
|
||||||
|
S(kSHKMoveFocusToActiveOrNextWindow, v, NSEventModifierFlagControl, 118); // Ctrl, F4
|
||||||
|
S(kSHKMoveFocusToActiveOrNextWindow, v, (NSEventModifierFlagShift | NSEventModifierFlagControl), 118); // Shift, Ctrl, F4
|
||||||
|
S(kSHKMoveFocusToNextWindow, c, NSEventModifierFlagCommand, 96); // Cmd, `
|
||||||
|
S(kSHKMoveFocusToNextWindow, c, (NSEventModifierFlagShift | NSEventModifierFlagCommand), 96); // Shift, Cmd, `
|
||||||
|
S(kSHKMoveFocusToStatusMenus, v, NSEventModifierFlagControl, 100); // Ctrl, F8
|
||||||
|
// input sources
|
||||||
|
S(kSHKSelectThePreviousInputSource, c, NSEventModifierFlagControl, 32); // Ctrl, Space bar
|
||||||
|
S(kSHKSelectNextSourceInInputMenu, c, (NSEventModifierFlagControl | NSEventModifierFlagOption), 32); // Ctrl, Opt, Space bar
|
||||||
|
// spotlight
|
||||||
|
S(kSHKShowSpotlightSearch, c, NSEventModifierFlagCommand, 32); // Cmd, Space bar
|
||||||
|
S(kSHKShowFinderSearchWindow, c, (NSEventModifierFlagOption | NSEventModifierFlagCommand), 32); // Opt, Cmd, Space bar
|
||||||
|
|
||||||
|
#undef S
|
||||||
global_shortcuts = [[NSDictionary dictionaryWithDictionary:temp] retain];
|
global_shortcuts = [[NSDictionary dictionaryWithDictionary:temp] retain];
|
||||||
global_configured_shortcuts = [[NSSet setWithSet:temp_configured] retain];
|
|
||||||
/* NSLog(@"global_shortcuts: %@", global_shortcuts); */
|
/* NSLog(@"global_shortcuts: %@", global_shortcuts); */
|
||||||
/* NSLog(@"global_configured_shortcuts: %@", global_configured_shortcuts); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
lookup_global_shortcut(NSEvent *event, NSDictionary<NSString*,NSNumber*> *global_shortcuts) {
|
is_active_apple_global_shortcut(NSEvent *event) {
|
||||||
|
if (global_shortcuts == nil) build_global_shortcuts_lookup();
|
||||||
NSEventModifierFlags modifierFlags = USEFUL_MODS([event modifierFlags]);
|
NSEventModifierFlags modifierFlags = USEFUL_MODS([event modifierFlags]);
|
||||||
static char lookup_key[64];
|
static char lookup_key[64];
|
||||||
#define LOOKUP(t, k) \
|
#define LOOKUP(t, k) \
|
||||||
@@ -658,45 +689,6 @@ lookup_global_shortcut(NSEvent *event, NSDictionary<NSString*,NSNumber*> *global
|
|||||||
return kSHKUnknown;
|
return kSHKUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
default_global_character_shortcut(uint32_t ch, NSEventModifierFlags mods) {
|
|
||||||
if ((ch == '`' || ch == '~') && (mods & ~NSEventModifierFlagShift) == NSEventModifierFlagCommand) return kSHKMoveFocusToNextWindow;
|
|
||||||
if (ch == NSF4FunctionKey && (mods & ~NSEventModifierFlagShift) == NSEventModifierFlagCommand) return kSHKMoveFocusToActiveOrNextWindow;
|
|
||||||
return kSHKUnknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
default_global_vk_shortcut(unsigned short vk, NSEventModifierFlags mods) {
|
|
||||||
(void)vk; (void)mods;
|
|
||||||
return kSHKUnknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
is_active_apple_global_shortcut(NSEvent *event) {
|
|
||||||
if (global_shortcuts == nil) build_global_shortcuts_lookup();
|
|
||||||
int ans = lookup_global_shortcut(event, global_shortcuts);
|
|
||||||
if (ans != kSHKUnknown) return ans;
|
|
||||||
// look for known global shortcuts
|
|
||||||
NSEventModifierFlags modifierFlags = USEFUL_MODS([event modifierFlags]);
|
|
||||||
if ([event.charactersIgnoringModifiers length] == 1) {
|
|
||||||
if (modifierFlags & NSEventModifierFlagShift) {
|
|
||||||
const uint32_t ch_without_shift = vk_to_unicode_key_with_current_layout([event keyCode]);
|
|
||||||
if (ch_without_shift < GLFW_FKEY_FIRST || ch_without_shift > GLFW_FKEY_LAST) {
|
|
||||||
ans = default_global_character_shortcut(ch_without_shift, modifierFlags);
|
|
||||||
if (ans != kSHKUnknown && [global_configured_shortcuts member:@(ans)] == nil) return ans;
|
|
||||||
}
|
|
||||||
const unichar ch = [event.charactersIgnoringModifiers characterAtIndex:0];
|
|
||||||
ans = default_global_character_shortcut(ch, modifierFlags);
|
|
||||||
if (ans != kSHKUnknown && [global_configured_shortcuts member:@(ans)] == nil) return ans;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unsigned short vk = [event keyCode];
|
|
||||||
ans = default_global_vk_shortcut(vk, modifierFlags);
|
|
||||||
if (ans != kSHKUnknown && [global_configured_shortcuts member:@(ans)] == nil) return ans;
|
|
||||||
return kSHKUnknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_useful_apple_global_shortcut(int sc) {
|
is_useful_apple_global_shortcut(int sc) {
|
||||||
switch(sc) {
|
switch(sc) {
|
||||||
@@ -990,7 +982,6 @@ void _glfwPlatformTerminate(void)
|
|||||||
|
|
||||||
_glfwTerminateNSGL();
|
_glfwTerminateNSGL();
|
||||||
if (global_shortcuts != nil) { [global_shortcuts release]; global_shortcuts = nil; }
|
if (global_shortcuts != nil) { [global_shortcuts release]; global_shortcuts = nil; }
|
||||||
if (global_configured_shortcuts != nil) { [global_configured_shortcuts release]; global_configured_shortcuts = nil; }
|
|
||||||
|
|
||||||
} // autoreleasepool
|
} // autoreleasepool
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user