fix: allow f-keys as shortcuts-when-active (closes #5166)
This commit is contained in:
1 parent
1a2822d130
commit
a0c9feefca
3 files changed
+25
-5
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import Cocoa
|
||||
import Darwin
|
||||
import Carbon.HIToolbox.Events
|
||||
|
||||
extension NSAppearance {
|
||||
func getThemeName() -> AppearanceThemePreference {
|
||||
|
||||
@@ -42,14 +42,16 @@ class ATShortcut {
|
||||
return false
|
||||
}
|
||||
|
||||
private func modifiersMatch(_ modifiers: UInt32) -> Bool {
|
||||
private func modifiersMatch(_ modifiers: CarbonModifierFlags) -> Bool {
|
||||
let modifiersCleaned = modifiers.cleaned()
|
||||
let shortcutModifiersCleaned = shortcut.carbonModifierFlags.cleaned()
|
||||
// holdShortcut: contains at least
|
||||
if id.hasPrefix("holdShortcut") {
|
||||
return modifiers == (modifiers | shortcut.carbonModifierFlags)
|
||||
return modifiersCleaned == (modifiersCleaned | shortcutModifiersCleaned)
|
||||
}
|
||||
// other shortcuts: contains exactly or exactly + holdShortcut modifiers
|
||||
let holdModifiers = ControlsTab.shortcuts[Preferences.indexToName("holdShortcut", App.app.shortcutIndex)]?.shortcut.carbonModifierFlags ?? 0
|
||||
return modifiers == shortcut.carbonModifierFlags || modifiers == (shortcut.carbonModifierFlags | holdModifiers)
|
||||
let holdModifiersCleaned = ControlsTab.shortcuts[Preferences.indexToName("holdShortcut", App.app.shortcutIndex)]?.shortcut.carbonModifierFlags.cleaned() ?? 0
|
||||
return modifiersCleaned == shortcutModifiersCleaned || modifiersCleaned == (shortcutModifiersCleaned | holdModifiersCleaned)
|
||||
}
|
||||
|
||||
func shouldTrigger() -> Bool {
|
||||
@@ -114,3 +116,21 @@ enum ShortcutScope {
|
||||
case global
|
||||
case local
|
||||
}
|
||||
|
||||
extension NSEvent.ModifierFlags {
|
||||
// NSEvent.addLocalMonitorForEvents may return events with broken modifiers (e.g. [.NSEventModifierFlagOption, .NSEventModifierFlagFunction, 0x120])
|
||||
// we filter modifiers to only include valid modifiers; which doesn't include fn as we don't support it as a modifier
|
||||
func cleaned() -> Self {
|
||||
return self.intersection([.command, .shift, .option, .control, .capsLock])
|
||||
}
|
||||
}
|
||||
|
||||
typealias CarbonModifierFlags = UInt32
|
||||
|
||||
extension CarbonModifierFlags {
|
||||
// cocoaToCarbonFlags may remove NSEventModifierFlagFunction
|
||||
// we filter modifiers to only include valid modifiers; which doesn't include fn as we don't support it as a modifier
|
||||
func cleaned() -> Self {
|
||||
return self & (UInt32(cmdKey) | UInt32(shiftKey) | UInt32(optionKey) | UInt32(controlKey) | UInt32(alphaLock))
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,6 @@ class CursorEvents {
|
||||
let deltaX = event.locationInWindow.x - deadZoneInitialPosition.x
|
||||
let deltaY = event.locationInWindow.y - deadZoneInitialPosition.y
|
||||
let d = hypot(deltaX, deltaY)
|
||||
Logger.error { d }
|
||||
isAllowedToMouseHover = d > 25
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user