diff --git a/Podfile.lock b/Podfile.lock index 3bc66c18..92e6b507 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -20,7 +20,7 @@ EXTERNAL SOURCES: CHECKOUT OPTIONS: ShortcutRecorder: - :commit: 4aebe01e1ec9eebb520ef50e42bc321be473c580 + :commit: f718220854575bad86fa89dd2bb3decd0b14b2b0 :git: https://github.com/Kentzo/ShortcutRecorder.git SPEC CHECKSUMS: diff --git a/alt-tab-macos.xcodeproj/project.pbxproj b/alt-tab-macos.xcodeproj/project.pbxproj index b55231e9..bf0f28ff 100644 --- a/alt-tab-macos.xcodeproj/project.pbxproj +++ b/alt-tab-macos.xcodeproj/project.pbxproj @@ -113,7 +113,6 @@ D04BA26C75F76C277653C932 /* FeedbackWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedbackWindow.swift; sourceTree = ""; }; D04BA27C87B86C4484A5B15B /* TabViewItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabViewItem.swift; sourceTree = ""; }; D04BA282BB16C1554595A968 /* Applications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Applications.swift; sourceTree = ""; }; - D04BA2A4F257F4DCE1421758 /* Podfile.lock */ = {isa = PBXFileReference; lastKnownFileType = file.lock; path = Podfile.lock; sourceTree = ""; }; D04BA2C7B51F68651B3C60E2 /* 6 windows - 1 line.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "6 windows - 1 line.jpg"; sourceTree = ""; }; D04BA2E723062A1DAC58618F /* setup_ci_pr.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = setup_ci_pr.sh; sourceTree = ""; }; D04BA2E8D5D5CC23456BC8F7 /* tr */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = tr; path = Localizable.strings; sourceTree = ""; }; @@ -294,7 +293,6 @@ D04BA2C9EF33A646D0977195 /* .github */, 4807A6C423A9CD190052A53E /* Frameworks */, 4A443501F57D4759B190C07E /* Pods */, - D04BA2A4F257F4DCE1421758 /* Podfile.lock */, D04BA0E071D2EDFDB9A20523 /* Podfile */, D04BAAF760E3A8A22BDA84D6 /* appcast.xml */, D04BA6251F309645757C6000 /* src */, diff --git a/src/ui/generic-components/UnclearableRecorderControl.swift b/src/ui/generic-components/UnclearableRecorderControl.swift index 1f7bd118..aa38da49 100644 --- a/src/ui/generic-components/UnclearableRecorderControl.swift +++ b/src/ui/generic-components/UnclearableRecorderControl.swift @@ -1,29 +1,30 @@ import Cocoa import ShortcutRecorder -class UnclearableRecorderControl: RecorderControl { +class UnclearableRecorderControl: RecorderControl, RecorderControlDelegate { convenience init(_ shortcutString: String, _ modifierFlagsOnly: Bool) { self.init(frame: .zero) - allowsDeleteToClearShortcutAndEndRecording = false - set(allowedModifierFlags: CocoaModifierFlagsMask, requiredModifierFlags: [], allowsEmptyModifierFlags: false) + delegate = self + allowsEscapeToCancelRecording = false + set(allowedModifierFlags: CocoaModifierFlagsMask, requiredModifierFlags: [], allowsEmptyModifierFlags: true) if modifierFlagsOnly { allowsModifierFlagsOnlyShortcut = true } objectValue = Shortcut(keyEquivalent: shortcutString) - // TODO: doesn't seem to work; handle width of the control better - allowsExpansionToolTips = true - widthAnchor.constraint(equalToConstant: 80).isActive = true + widthAnchor.constraint(equalToConstant: 100).isActive = true } override func drawClearButton(_ aDirtyRect: NSRect) { - // don't draw the clear button + if !allowsModifierFlagsOnlyShortcut { + super.drawClearButton(aDirtyRect) + } } - override func areModifierFlagsValid(_ aModifierFlags: NSEvent.ModifierFlags, for aKeyCode: KeyCode) -> Bool { + func recorderControl(_ aControl: RecorderControl, canRecord aShortcut: Shortcut) -> Bool { // only allow modifiers: ⌥ -> valid, e -> invalid, ⌥e -> invalid - if allowsModifierFlagsOnlyShortcut && aKeyCode != .none { + if allowsModifierFlagsOnlyShortcut && aShortcut.keyCode != .none { return false } - return super.areModifierFlagsValid(aModifierFlags, for: aKeyCode) + return true } } diff --git a/src/ui/preferences-window/tabs/GeneralTab.swift b/src/ui/preferences-window/tabs/GeneralTab.swift index 292f4eba..85763bd6 100644 --- a/src/ui/preferences-window/tabs/GeneralTab.swift +++ b/src/ui/preferences-window/tabs/GeneralTab.swift @@ -71,16 +71,23 @@ class GeneralTab { @objc static func shortcutChangedCallback(_ sender: NSControl) { let controlId = sender.identifier!.rawValue - // remove the holdShortcut character in case they also use it in the other shortcuts - let newValue = (sender as! RecorderControl).stringValue.replacingOccurrences(of: Preferences.holdShortcut, with: "") - switch controlId { - case "holdShortcut": - addShortcut({ App.app.focusTarget() }, .up, Shortcut(keyEquivalent: Preferences.holdShortcut)!, controlId) - shortcutsDependentOnHoldShortcut.forEach { $0.sendAction($0.action, to: $0.target) } - case "nextWindowShortcut": addShortcut({ App.app.showUiOrCycleSelection(1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId) - case "previousWindowShortcut": addShortcut({ App.app.showUiOrCycleSelection(-1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId) - case "cancelShortcut": addShortcut({ App.app.hideUi() }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId) - default: return + if controlId == "holdShortcut" { + addShortcut({ App.app.focusTarget() }, .up, Shortcut(keyEquivalent: Preferences.holdShortcut)!, controlId) + shortcutsDependentOnHoldShortcut.forEach { $0.sendAction($0.action, to: $0.target) } + } else { + // remove the holdShortcut character in case they also use it in the other shortcuts + let newValue = Preferences.holdShortcut.reduce((sender as! RecorderControl).stringValue, { $0.replacingOccurrences(of: String($1), with: "") }) + if newValue.isEmpty { + removeShortcutIfExists(controlId, .down) + return + } + if controlId == "nextWindowShortcut" { + addShortcut({ App.app.showUiOrCycleSelection(1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId) + } else if controlId == "previousWindowShortcut" { + addShortcut({ App.app.showUiOrCycleSelection(-1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId) + } else if controlId == "cancelShortcut" { + addShortcut({ App.app.hideUi() }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId) + } } }