| | |
| | | private static let allowedModifierMask = UInt32( |
| | | controlKey | optionKey | shiftKey | cmdKey | kEventKeyModifierFnMask |
| | | ) |
| | | private static let functionKeyCodes: Set<Int> = [ |
| | | kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F5, kVK_F6, |
| | | kVK_F7, kVK_F8, kVK_F9, kVK_F10, kVK_F11, kVK_F12 |
| | | ] |
| | | |
| | | static func defaultHotkey(for kind: LauncherHotkeyKind) -> LauncherHotkey { |
| | | kind.hotkey |
| | |
| | | private static func hasSupportedModifierCombination(_ hotkey: LauncherHotkey) -> Bool { |
| | | let modifiers = hotkey.modifiers & allowedModifierMask |
| | | guard modifiers != 0 else { return false } |
| | | if modifiers == UInt32(shiftKey) || modifiers == UInt32(optionKey) { |
| | | if modifiers == UInt32(shiftKey) { |
| | | return false |
| | | } |
| | | if modifiers == UInt32(kEventKeyModifierFnMask) { |
| | |
| | | return true |
| | | case kVK_LeftArrow, kVK_RightArrow, kVK_UpArrow, kVK_DownArrow: |
| | | return true |
| | | case kVK_F1...kVK_F12: |
| | | return true |
| | | default: |
| | | return LauncherHotkey.printableKeyCodes.contains(Int(keyCode)) |
| | | let key = Int(keyCode) |
| | | return functionKeyCodes.contains(key) || LauncherHotkey.printableKeyCodes.contains(key) |
| | | } |
| | | } |
| | | |