Skip to content

Commit

Permalink
perf: fix very small memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Aug 20, 2020
1 parent c531e52 commit 8b7da21
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/logic/events/KeyboardEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/logic/events/MouseEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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_() {
Expand Down

0 comments on commit 8b7da21

Please sign in to comment.