nativeview_abi/runtime/input.rs
1//! Input dispatch disposition ABI constants ([`super::NvRuntimeApi::dispatch_events_ex`]).
2
3nativeview_abi_macros::abi_consts! {
4 pub(super) const INPUT_CONSTS;
5
6 /// `NvRuntimeApi::dispatch_events_ex` disposition: neither interceptors, app `KeyDown`
7 /// handlers, static `#0 CloseRequestAction`, nor dynamic default actions consumed the batch
8 /// or requested `preventDefault()`. Passive non-`KeyDown` dispatches (e.g. `Press`/`Focus`
9 /// handled only by the app) also report `PASS_THROUGH`.
10 pub const NV_INPUT_DISPOSITION_PASS_THROUGH: u32 = 0;
11 /// `NvRuntimeApi::dispatch_events_ex` disposition: consumed without `preventDefault()` by an
12 /// interceptor, an app `KeyDown` listener (`dirty && !unconsumed_key && !close_req`), static
13 /// `#0 CloseRequestAction`, or a dynamic default action.
14 pub const NV_INPUT_DISPOSITION_CONSUMED: u32 = 1;
15 /// `NvRuntimeApi::dispatch_events_ex` disposition: any hook returned `ConsumedPreventDefault`
16 /// or set `prevent_default` (including pass-through interceptors such as shortcut matchers);
17 /// native hosts should suppress OS default handling (system beep, history/back navigation).
18 pub const NV_INPUT_DISPOSITION_CONSUMED_PREVENT_DEFAULT: u32 = 2;
19 /// Bits of the `dispatch_events_ex` disposition word holding the `NV_INPUT_DISPOSITION_*`
20 /// value; the `NV_POINTER_OUTCOME_*` bits above it describe the batch's raw pointer samples.
21 #[nativeview_abi(hex)]
22 pub const NV_INPUT_DISPOSITION_MASK: u32 = 0xFF;
23 /// A raw pointer sample of the batch reached an NV node (hit or capture target): the host
24 /// must not hand the gesture to its own toolkit.
25 #[nativeview_abi(hex)]
26 pub const NV_POINTER_OUTCOME_TARGETED: u32 = 1 << 8;
27 /// A raw pointer of the batch is captured by an NV node (implicit touch / pen or explicit).
28 #[nativeview_abi(hex)]
29 pub const NV_POINTER_OUTCOME_CAPTURED: u32 = 1 << 9;
30 /// An NV node claimed the pointer stream (declarative or app-requested capture, W3C
31 /// `touch-action: none`): native hosts disallow parent interception
32 /// (`requestDisallowInterceptTouchEvent`, Compose `consume()`, GTK `CLAIMED`).
33 #[nativeview_abi(hex)]
34 pub const NV_POINTER_OUTCOME_CLAIMED: u32 = 1 << 10;
35 /// A primary press landed outside the topmost modal: nothing below it saw the pointer.
36 #[nativeview_abi(hex)]
37 pub const NV_POINTER_OUTCOME_MODAL_BARRIER: u32 = 1 << 11;
38 /// The `PointerTable` was full: the contact was refused and cancelled.
39 #[nativeview_abi(hex)]
40 pub const NV_POINTER_OUTCOME_REFUSED: u32 = 1 << 12;
41}
42
43crate::define_bitflags! {
44 /// What the core pointer-resolution stage did with a batch's raw samples
45 /// (`NV_POINTER_OUTCOME_*`, bits 8.. of the `dispatch_events_ex` disposition word).
46 #[derive(Default)]
47 pub struct PointerOutcomeFlags(u32) {
48 const TARGETED = NV_POINTER_OUTCOME_TARGETED;
49 const CAPTURED = NV_POINTER_OUTCOME_CAPTURED;
50 const CLAIMED = NV_POINTER_OUTCOME_CLAIMED;
51 const MODAL_BARRIER = NV_POINTER_OUTCOME_MODAL_BARRIER;
52 const REFUSED = NV_POINTER_OUTCOME_REFUSED;
53 }
54}
55
56/// Typed input dispatch disposition matching `NV_INPUT_DISPOSITION_*`.
57#[repr(u32)]
58#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
59pub enum NvInputDisposition {
60 #[default]
61 PassThrough = NV_INPUT_DISPOSITION_PASS_THROUGH,
62 Consumed = NV_INPUT_DISPOSITION_CONSUMED,
63 ConsumedPreventDefault = NV_INPUT_DISPOSITION_CONSUMED_PREVENT_DEFAULT,
64}
65
66impl NvInputDisposition {
67 /// Converts a `dispatch_events_ex` disposition word (`NV_POINTER_OUTCOME_*` bits ignored)
68 /// into a typed [`NvInputDisposition`].
69 #[inline]
70 pub const fn from_raw(raw: u32) -> Option<Self> {
71 match raw & NV_INPUT_DISPOSITION_MASK {
72 NV_INPUT_DISPOSITION_PASS_THROUGH => Some(Self::PassThrough),
73 NV_INPUT_DISPOSITION_CONSUMED => Some(Self::Consumed),
74 NV_INPUT_DISPOSITION_CONSUMED_PREVENT_DEFAULT => Some(Self::ConsumedPreventDefault),
75 _ => None,
76 }
77 }
78
79 /// Returns the raw `NV_INPUT_DISPOSITION_*` word representation.
80 #[inline]
81 pub const fn as_u32(self) -> u32 {
82 self as u32
83 }
84}