fix global keybinds from not repsonding anymore

This commit is contained in:
Austin Drummond
2026-03-28 17:32:58 -04:00
parent 0a492fdb33
commit 3c2c596dc7

View File

@@ -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<CGEvent>? {
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 }