fix: use Swift CoreGraphics event tap APIs
This commit is contained in:
parent
0289b73f2c
commit
3a620f89dc
2 changed files with 14 additions and 10 deletions
|
|
@ -165,13 +165,13 @@ final class MacOSInputController {
|
||||||
|
|
||||||
let eventMask = CGEventMask(1 << CGEventType.flagsChanged.rawValue)
|
let eventMask = CGEventMask(1 << CGEventType.flagsChanged.rawValue)
|
||||||
let refcon = Unmanaged.passUnretained(self).toOpaque()
|
let refcon = Unmanaged.passUnretained(self).toOpaque()
|
||||||
guard let tap = CGEventTapCreate(
|
guard let tap = CGEvent.tapCreate(
|
||||||
.cgSessionEventTap,
|
tap: .cgSessionEventTap,
|
||||||
.headInsertEventTap,
|
place: .headInsertEventTap,
|
||||||
.defaultTap,
|
options: .defaultTap,
|
||||||
eventMask,
|
eventsOfInterest: eventMask,
|
||||||
Self.eventTapCallback,
|
callback: Self.eventTapCallback,
|
||||||
refcon
|
userInfo: refcon
|
||||||
) else {
|
) else {
|
||||||
throw InputControllerError.eventTapUnavailable
|
throw InputControllerError.eventTapUnavailable
|
||||||
}
|
}
|
||||||
|
|
@ -191,14 +191,14 @@ final class MacOSInputController {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
CGEventTapEnable(tap, true)
|
CGEvent.tapEnable(tap: tap, enable: true)
|
||||||
resetGestureState()
|
resetGestureState()
|
||||||
onStateChanged?()
|
onStateChanged?()
|
||||||
}
|
}
|
||||||
|
|
||||||
func stop() {
|
func stop() {
|
||||||
if let eventTap {
|
if let eventTap {
|
||||||
CGEventTapEnable(eventTap, false)
|
CGEvent.tapEnable(tap: eventTap, enable: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let runLoopSource {
|
if let runLoopSource {
|
||||||
|
|
@ -255,7 +255,7 @@ final class MacOSInputController {
|
||||||
if type == .tapDisabledByTimeout || type == .tapDisabledByUserInput {
|
if type == .tapDisabledByTimeout || type == .tapDisabledByUserInput {
|
||||||
resetGestureState()
|
resetGestureState()
|
||||||
if let eventTap {
|
if let eventTap {
|
||||||
CGEventTapEnable(eventTap, true)
|
CGEvent.tapEnable(tap: eventTap, enable: true)
|
||||||
}
|
}
|
||||||
return Unmanaged.passUnretained(event)
|
return Unmanaged.passUnretained(event)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,10 @@ tasks:
|
||||||
- test -f Sources/CapswitchApp/MacOSInputController.swift
|
- test -f Sources/CapswitchApp/MacOSInputController.swift
|
||||||
- grep -q "LSUIElement" Resources/Info.plist
|
- grep -q "LSUIElement" Resources/Info.plist
|
||||||
- grep -q ".flagsChanged" Sources/CapswitchApp/MacOSInputController.swift
|
- 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 "TISSelectInputSource" Sources/CapswitchApp/MacOSInputController.swift
|
||||||
- grep -q "switchToNextInputSource" Sources/Capswitch/CapsGestureMachine.swift
|
- grep -q "switchToNextInputSource" Sources/Capswitch/CapsGestureMachine.swift
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue