pub unsafe fn during_tracking(delay: f64, interval: f64, body: fn() -> bool)Expand description
Run body once, delay seconds from now, inside whatever loop is running.
A context menu, a drag or a modal sheet does not return to the caller: AppKit
enters its own event loop in NSEventTrackingRunLoopMode and stays there
until the user dismisses it. pump_events never gets a turn while that is
happening, which is why anything that opens a menu cannot be observed from
the outside at all โ and why forcing the window closed from another thread
takes the process down.
A CFRunLoopTimer added to the common modes is the way in. Common modes
include event tracking, so the timer fires while the menu is up, on the main
thread, between events โ exactly where it is safe to look at the window list
and to post the key event that dismisses it.
The timer repeats every interval seconds until body returns true, so a
dismissal that does not take the first time is simply tried again.
ยงSafety
Must be called on the main thread, and body runs on it too.