1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Where the input being dispatched came from: the operating system, or
//! lurq's synthetic input (MCP tools and [`apply`](crate::app::synthetic_input::apply)).
//!
//! Synthetic input reaches the same entry points as OS input, so a handler
//! cannot tell the two apart by the event. While lurq delivers synthetic
//! input, [`input_source`] says so, and an app can ignore it on a control that
//! only a person may use.
use Cell;
/// Where the input whose handlers are running came from.
thread_local!
/// The source of the input whose handlers run now on this thread: `Synthetic`
/// while lurq delivers synthetic input, `Os` otherwise.
///
/// Read it in an event handler, an `on_input` or `on_change` callback, or a
/// focus handler, which lurq calls while it delivers the event. Work deferred
/// past the delivery (a spawned task, an effect of a later render, a timer)
/// sees `Os`. A left click that lurq holds back to see whether a double click
/// follows (under an `on_dblclick` handler) keeps the source of its input
/// when it is delivered later.
///
/// ```
/// use lurq::app::events::{MouseEvent, is_synthetic_input};
///
/// let on_click = |_: MouseEvent| {
/// if is_synthetic_input() {
/// return; // only a person may press this
/// }
/// // ...
/// };
/// # let _ = on_click;
/// ```
/// Whether the input whose handlers run now is lurq's synthetic input.
/// Runs `deliver` with its input marked as synthetic, for an automation layer
/// that drives a [`Tree`](crate::app::Tree) through its input methods
/// directly. lurq's own synthetic input does this already.
/// Runs `deliver` with its input marked as coming from `source`, for input
/// lurq delivers after the call that received it.
pub
/// Restores the previous source, also when a handler panics.
;