fix: use Swift CoreGraphics event tap APIs

This commit is contained in:
casona 2026-10-25 19:59:55 +03:00
parent 0289b73f2c
commit 3a620f89dc
2 changed files with 14 additions and 10 deletions

View file

@ -165,13 +165,13 @@ final class MacOSInputController {
let eventMask = CGEventMask(1 << CGEventType.flagsChanged.rawValue)
let refcon = Unmanaged.passUnretained(self).toOpaque()
guard let tap = CGEventTapCreate(
.cgSessionEventTap,
.headInsertEventTap,
.defaultTap,
eventMask,
Self.eventTapCallback,
refcon
guard let tap = CGEvent.tapCreate(
tap: .cgSessionEventTap,
place: .headInsertEventTap,
options: .defaultTap,
eventsOfInterest: eventMask,
callback: Self.eventTapCallback,
userInfo: refcon
) else {
throw InputControllerError.eventTapUnavailable
}
@ -191,14 +191,14 @@ final class MacOSInputController {
)
}
CGEventTapEnable(tap, true)
CGEvent.tapEnable(tap: tap, enable: true)
resetGestureState()
onStateChanged?()
}
func stop() {
if let eventTap {
CGEventTapEnable(eventTap, false)
CGEvent.tapEnable(tap: eventTap, enable: false)
}
if let runLoopSource {
@ -255,7 +255,7 @@ final class MacOSInputController {
if type == .tapDisabledByTimeout || type == .tapDisabledByUserInput {
resetGestureState()
if let eventTap {
CGEventTapEnable(eventTap, true)
CGEvent.tapEnable(tap: eventTap, enable: true)
}
return Unmanaged.passUnretained(event)
}

View file

@ -55,6 +55,10 @@ tasks:
- test -f Sources/CapswitchApp/MacOSInputController.swift
- grep -q "LSUIElement" Resources/Info.plist
- grep -q ".flagsChanged" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "CGEvent.tapCreate" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "CGEvent.tapEnable" Sources/CapswitchApp/MacOSInputController.swift
- test "$(grep -c "CGEventTapCreate" Sources/CapswitchApp/MacOSInputController.swift || true)" -eq 0
- test "$(grep -c "CGEventTapEnable" Sources/CapswitchApp/MacOSInputController.swift || true)" -eq 0
- grep -q "TISSelectInputSource" Sources/CapswitchApp/MacOSInputController.swift
- grep -q "switchToNextInputSource" Sources/Capswitch/CapsGestureMachine.swift