// The still window the fan's painter waits for (`PagePainter`, architect, 14 // Oct 2026): nothing is drawn off screen until the window has been quiet, and // once a finger has gone down nothing more is drawn until it is quiet again. import SwiftUI #if os(iOS) import UIKit #endif enum StillWindow { /// How long the window must have been still before anything is drawn /// off screen. static let quiet: Duration = .milliseconds(300) } #if os(iOS) /// Whether a finger has gone down in the key window since it was installed: a /// recognizer that never recognizes, never delays a touch and never cancels /// one, so every control under it behaves exactly as without it. @MainActor final class TouchWatch: UIGestureRecognizer, UIGestureRecognizerDelegate { private(set) var touched = false /// Called as a finger lands, so work waiting on the still window stops at once. var onTouch: (() -> Void)? static func install() -> TouchWatch? { let window = UIApplication.shared.connectedScenes .compactMap { $0 as? UIWindowScene } .flatMap(\.windows) .first(where: \.isKeyWindow) guard let window else { return nil } let watch = TouchWatch(target: nil, action: nil) watch.cancelsTouchesInView = false watch.delaysTouchesBegan = false watch.delaysTouchesEnded = false watch.delegate = watch window.addGestureRecognizer(watch) return watch } func remove() { view?.removeGestureRecognizer(self) } override func touchesBegan(_ touches: Set, with event: UIEvent) { touched = true onTouch?() state = .failed } func gestureRecognizer(_ recognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith other: UIGestureRecognizer) -> Bool { true } } #endif