Skip to main content

euv_core/system/event/
struct.rs

1use super::*;
2
3/// Handle returned by scoped system event hooks allowing optional manual early unregistration.
4#[derive(Clone, Copy, Data, Debug, Eq, Hash, New, PartialEq)]
5pub struct SystemEventSubscription {
6    /// Monotonic listener identifier inside the thread-local `SystemEventHub`.
7    #[get(type(copy))]
8    pub(crate) id: u64,
9}
10
11/// Deterministic state machine deduplicating noisy OS callbacks and enforcing canonical cross-platform event ordering.
12#[derive(Clone, Data, Debug, PartialEq)]
13pub struct SystemEventNormalizer {
14    /// Current canonical application lifecycle state.
15    #[get(type(copy))]
16    pub(crate) state: AppState,
17    /// Whether the active application surface is currently visible (`Appear` emitted without matching `Disappear`).
18    #[get(type(copy))]
19    pub(crate) visible: bool,
20    /// Most recently emitted window focus state for deduplication.
21    #[get(skip)]
22    pub(crate) last_focused: Option<bool>,
23    /// Most recently emitted logical `(width, height, scale_factor)` resize tuple.
24    #[get(skip)]
25    pub(crate) last_resize: Option<(f32, f32, f32)>,
26    /// Most recently emitted safe-area insets.
27    #[get(skip)]
28    pub(crate) last_safe_area: Option<SafeAreaInsets>,
29    /// Most recently emitted screen orientation.
30    #[get(skip)]
31    pub(crate) last_orientation: Option<ScreenOrientation>,
32    /// Most recently emitted OS light/dark theme.
33    #[get(skip)]
34    pub(crate) last_theme: Option<SystemTheme>,
35    /// Most recently emitted OS locale string.
36    #[get(skip)]
37    pub(crate) last_locale: Option<String>,
38    /// Most recently emitted virtual keyboard `(visible, height)` state.
39    #[get(skip)]
40    pub(crate) last_keyboard: Option<(bool, f32)>,
41    /// Most recently emitted low-power mode flag.
42    #[get(skip)]
43    pub(crate) last_low_power: Option<bool>,
44    /// Most recently emitted network reachability state.
45    #[get(skip)]
46    pub(crate) last_network: Option<NetworkStatus>,
47}
48
49/// Internal scope-bound system event listener entry stored in `SystemEventHub`.
50#[derive(CustomDebug)]
51pub(crate) struct SystemEventListener {
52    /// Unique listener identifier.
53    pub(crate) id: u64,
54    /// Reactive scope owning this listener, if registered inside a scope.
55    pub(crate) owner_scope: Option<ScopeId>,
56    /// Type-erased callback invoked when matching system events arrive.
57    #[debug(skip)]
58    pub(crate) callback: SystemEventCallback,
59}
60
61/// Thread-local registry of active scoped system event listeners.
62#[derive(CustomDebug, Default)]
63pub(crate) struct SystemEventHub {
64    /// Monotonic listener identifier counter.
65    pub(crate) next_id: u64,
66    /// Active registered listeners in registration order.
67    pub(crate) listeners: Vec<SystemEventListener>,
68}