fret_runtime/injected_event_scope.rs
1thread_local! {
2 static INJECTED_EVENT_SCOPE: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
3}
4
5/// Marks a call stack as delivering a synthetic event owned by tooling/runtime plumbing.
6///
7/// Consumers that normally ignore external input while scripted playback is active can use
8/// [`in_injected_event_scope`] to distinguish those synthetic deliveries from real platform input.
9pub fn with_injected_event_scope<R>(f: impl FnOnce() -> R) -> R {
10 INJECTED_EVENT_SCOPE.with(|cell| {
11 let prev = cell.replace(true);
12 let out = f();
13 cell.set(prev);
14 out
15 })
16}
17
18/// Returns `true` while the current thread is delivering a tooling-owned synthetic event.
19pub fn in_injected_event_scope() -> bool {
20 INJECTED_EVENT_SCOPE.with(|cell| cell.get())
21}