From 3c2c596dc77679385e18039052e2b7556049e07f Mon Sep 17 00:00:00 2001 From: Austin Drummond Date: Sat, 28 Mar 2026 17:32:58 -0400 Subject: [PATCH] fix global keybinds from not repsonding anymore --- .../Features/Global Keybinds/GlobalEventTap.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Features/Global Keybinds/GlobalEventTap.swift b/macos/Sources/Features/Global Keybinds/GlobalEventTap.swift index 9d4023c2e..d308e59ea 100644 --- a/macos/Sources/Features/Global Keybinds/GlobalEventTap.swift +++ b/macos/Sources/Features/Global Keybinds/GlobalEventTap.swift @@ -16,7 +16,7 @@ class GlobalEventTap { // The event tap used for global event listening. This is non-nil if it is // created. - private var eventTap: CFMachPort? + fileprivate var eventTap: CFMachPort? // This is the timer used to retry enabling the global event tap if we // don't have permissions. @@ -125,6 +125,17 @@ private func cgEventFlagsChangedHandler( ) -> Unmanaged? { let result = Unmanaged.passUnretained(cgEvent) + // macOS disables the event tap if the callback is too slow or for other + // internal reasons. When that happens it sends this event type. We need + // to re-enable the tap or it stays dead forever. + if type == .tapDisabledByTimeout || type == .tapDisabledByUserInput { + GlobalEventTap.logger.warning("global event tap was disabled by the system, re-enabling") + if let machPort = GlobalEventTap.shared.eventTap { + CGEvent.tapEnable(tap: machPort, enable: true) + } + return result + } + // We only care about keydown events guard type == .keyDown else { return result }