Skip to content

Commit

Permalink
feat: avoid disabling native command-tab (closes #834)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Mar 13, 2021
1 parent 5390e41 commit fb51c5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/logic/events/KeyboardEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions src/ui/preferences-window/tabs/ControlsTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fb51c5d

Please sign in to comment.