feat: avoid disabling native command-tab (closes #834)

This commit is contained in:
Louis Pontoise
2021-03-13 23:52:42 +09:00
committed by lwouis
parent 5390e411cc
commit fb51c5d14b
2 changed files with 12 additions and 8 deletions
-8
View File
@@ -21,13 +21,11 @@ class KeyboardEvents {
static func addGlobalShortcut(_ controlId: String, _ shortcut: Shortcut) {
addGlobalHandlerIfNeeded(shortcut)
registerHotKeyIfNeeded(controlId, shortcut)
toggleNativeCommandTabIfNeeded(shortcut, false)
}
static func removeGlobalShortcut(_ controlId: String, _ shortcut: Shortcut) {
unregisterHotKeyIfNeeded(controlId, shortcut)
removeHandlerIfNeeded()
toggleNativeCommandTabIfNeeded(shortcut, true)
}
private static func unregisterHotKeyIfNeeded(_ controlId: String, _ shortcut: Shortcut) {
@@ -63,12 +61,6 @@ class KeyboardEvents {
}
}
private static func toggleNativeCommandTabIfNeeded(_ shortcut: Shortcut, _ enabled: Bool) {
if (shortcut.carbonModifierFlags == cmdKey || shortcut.carbonModifierFlags == (cmdKey | shiftKey)) && shortcut.carbonKeyCode == kVK_Tab {
setNativeCommandTabEnabled(enabled)
}
}
static func addEventHandlers() {
addLocalMonitorForKeyDownAndKeyUp()
addCgEventTapForModifierFlags()
@@ -110,6 +110,18 @@ class ControlsTab {
if scope == .global {
KeyboardEvents.addGlobalShortcut(controlId, atShortcut.shortcut)
}
toggleNativeCommandTabIfNeeded()
}
private static func toggleNativeCommandTabIfNeeded() {
for atShortcut in shortcuts.values {
let shortcut = atShortcut.shortcut
if (shortcut.carbonModifierFlags == cmdKey || shortcut.carbonModifierFlags == (cmdKey | shiftKey)) && shortcut.carbonKeyCode == kVK_Tab {
setNativeCommandTabEnabled(false)
return
}
}
setNativeCommandTabEnabled(true)
}
@objc static func shortcutChangedCallback(_ sender: NSControl) {