diff --git a/src/logic/events/KeyboardEvents.swift b/src/logic/events/KeyboardEvents.swift index b1375730..02e3a72a 100644 --- a/src/logic/events/KeyboardEvents.swift +++ b/src/logic/events/KeyboardEvents.swift @@ -18,9 +18,10 @@ class KeyboardEvents { static var eventHotKeyRefs = [EventHotKeyRef?](repeating: nil, count: globalShortcuts.count) static var hotModifierEventHandler: EventHandlerRef? static var hotKeyEventHandler: EventHandlerRef? + static var localMonitor: Any? static func observe() { - NSEvent.addLocalMonitorForEvents(matching: [.keyDown, .flagsChanged]) { event in + localMonitor = NSEvent.addLocalMonitorForEvents(matching: [.keyDown, .flagsChanged]) { event in // global .flagsChanged events are not send to the app when it's active, thus modifiers-only shortcuts should be matched in global and local handlers if handleHotModifier(cocoaToCarbonFlags(event.modifierFlags)) || handleLocalEvents(event) { return nil // don't propagate event diff --git a/src/logic/events/MouseEvents.swift b/src/logic/events/MouseEvents.swift index 82e2e8eb..89f2d635 100644 --- a/src/logic/events/MouseEvents.swift +++ b/src/logic/events/MouseEvents.swift @@ -29,7 +29,7 @@ private func observe_() { callback: mouseHandler, userInfo: nil) MouseEvents.toggle(false) - let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0) + let runLoopSource = CFMachPortCreateRunLoopSource(nil, eventTap, 0) CFRunLoopAddSource(BackgroundWork.mouseEventsThread.runLoop, runLoopSource, .commonModes) } @@ -48,7 +48,7 @@ private func mouseHandler(proxy: CGEventTapProxy, type: CGEventType, cgEvent: CG } else if (type == .tapDisabledByUserInput || type == .tapDisabledByTimeout) && shouldBeEnabled { CGEvent.tapEnable(tap: eventTap!, enable: true) } - return Unmanaged.passRetained(cgEvent) // focused app will receive the event + return Unmanaged.passUnretained(cgEvent) // focused app will receive the event } private func isPointerInsideUi_() {