Skip to content

Commit 171fa82

Browse files
committed
⚡ improve multitouch gesture lifecycle handling
1 parent 082ba3b commit 171fa82

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

Loop/Core/LoopManager.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ final class LoopManager {
131131
)
132132

133133
func start() {
134-
multitouchTrigger.prepare()
135-
136134
accessibilityCheckerTask = Task(priority: .background) { [weak self] in
137135
for await status in AccessibilityManager.shared.stream(initial: true) {
138136
guard let self, !Task.isCancelled else {

Loop/Core/Multitouch/MultitouchGestureBlocker.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ final class MultitouchGestureBlocker {
1818
private var activeCount: Int = 0
1919

2020
func start() {
21-
activeCount += 1
22-
guard monitor == nil else { return }
21+
if let monitor, monitor.isEnabled {
22+
activeCount += 1
23+
return
24+
}
25+
26+
monitor?.stop()
27+
monitor = nil
28+
activeCount = 0
2329

2430
log.info("Starting gesture blocker")
2531

@@ -32,11 +38,22 @@ final class MultitouchGestureBlocker {
3238
CGEventType(rawValue: UInt32(NSEvent.EventType.smartMagnify.rawValue))
3339
].compactMap(\.self)
3440

35-
monitor = ActiveEventMonitor("gesture_blocker", events: eventTypes) { _ in .ignore }
36-
monitor?.start()
41+
let newMonitor = ActiveEventMonitor("gesture_blocker", events: eventTypes) { _ in .ignore }
42+
newMonitor.start()
43+
44+
guard newMonitor.isEnabled else {
45+
log.warn("Failed to start gesture blocker")
46+
newMonitor.stop()
47+
return
48+
}
49+
50+
monitor = newMonitor
51+
activeCount = 1
3752
}
3853

3954
func stop() {
55+
guard activeCount > 0 || monitor != nil else { return }
56+
4057
activeCount = max(0, activeCount - 1)
4158
guard activeCount == 0 else { return }
4259

0 commit comments

Comments
 (0)