fix: don't crash when the nsevent contructor fails
Error was: alt-tab-macos[17018:919870] unrecognized type is 4294967294 alt-tab-macos[17018:919870] *** Assertion failure in -[NSEvent _initWithCGEvent:eventRef:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1671.60.107/AppKit.subproj/NSEvent.m:1977 alt-tab-macos[17018:919870] Invalid parameter not satisfying: _type > 0 && _type <= kCGSLastEventType
This commit is contained in:
1 parent
ba9379b041
commit
6f613547c4
1 file changed
+17
-16
@@ -19,22 +19,23 @@ func listenToGlobalKeyboardEvents(_ delegate: Application) {
|
||||
}
|
||||
|
||||
func keyboardHandler(_ cgEvent: CGEvent, _ delegate: Application) -> Unmanaged<CGEvent>? {
|
||||
let event = NSEvent(cgEvent: cgEvent)!
|
||||
let keyDown = event.type == .keyDown
|
||||
let optionKeyEvent = event.keyCode == metaKey
|
||||
let tabKeyEvent = event.keyCode == tabKey
|
||||
if optionKeyEvent && event.modifiersDown([metaModifierFlag]) {
|
||||
delegate.keyDownMeta()
|
||||
} else if tabKeyEvent && event.modifiersDown([metaModifierFlag]) && keyDown {
|
||||
delegate.keyDownMetaTab()
|
||||
// focused app will not receive the event (will not press tab key in that app)
|
||||
return nil
|
||||
} else if tabKeyEvent && event.modifiersDown([metaModifierFlag, .shift]) && keyDown {
|
||||
delegate.keyDownMetaShiftTab()
|
||||
// focused app will not receive the event (will not press tab key in that app)
|
||||
return nil
|
||||
} else if optionKeyEvent && !keyDown {
|
||||
delegate.keyUpMeta()
|
||||
if cgEvent.type == .keyDown || cgEvent.type == .keyUp || cgEvent.type == .flagsChanged, let event = NSEvent.init(cgEvent: cgEvent) {
|
||||
let keyDown = event.type == .keyDown
|
||||
let optionKeyEvent = event.keyCode == metaKey
|
||||
let tabKeyEvent = event.keyCode == tabKey
|
||||
if optionKeyEvent && event.modifiersDown([metaModifierFlag]) {
|
||||
delegate.keyDownMeta()
|
||||
} else if tabKeyEvent && event.modifiersDown([metaModifierFlag]) && keyDown {
|
||||
delegate.keyDownMetaTab()
|
||||
// focused app will not receive the event (will not press tab key in that app)
|
||||
return nil
|
||||
} else if tabKeyEvent && event.modifiersDown([metaModifierFlag, .shift]) && keyDown {
|
||||
delegate.keyDownMetaShiftTab()
|
||||
// focused app will not receive the event (will not press tab key in that app)
|
||||
return nil
|
||||
} else if optionKeyEvent && !keyDown {
|
||||
delegate.keyUpMeta()
|
||||
}
|
||||
}
|
||||
// focused app will receive the event
|
||||
return Unmanaged.passRetained(cgEvent)
|
||||
|
||||
Reference in new issue
Block a user