rust_webvr_api/vr_event.rs
1use {VRDisplayData, VRGamepadData, VRGamepadState};
2
3#[derive(Debug, Clone)]
4#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))]
5pub enum VREvent {
6 Display(VRDisplayEvent),
7 Gamepad(VRGamepadEvent),
8}
9
10#[derive(Debug, Clone, Copy)]
11#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))]
12pub enum VRDisplayEventReason {
13 Navigation,
14 /// The VRDisplay has detected that the user has put it on.
15 Mounted,
16
17 /// The VRDisplay has detected that the user has taken it off.
18 Unmounted
19}
20
21#[derive(Debug, Clone)]
22#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))]
23pub enum VRDisplayEvent {
24 /// Indicates that a VRDisplay has been connected.
25 Connect(VRDisplayData),
26
27 /// Indicates that a VRDisplay has been disconnected.
28 /// param: display_id
29 Disconnect(u32),
30
31 /// Indicates that something has occured which suggests the VRDisplay should be presented to
32 Activate(VRDisplayData, VRDisplayEventReason),
33
34 /// Indicates that something has occured which suggests the VRDisplay should exit presentation
35 Deactivate(VRDisplayData, VRDisplayEventReason),
36
37 /// Indicates that some of the VRDisplay's data has changed (eye parameters, tracking data, chaperone, ipd, etc.)
38 Change(VRDisplayData),
39
40 /// Indicates that presentation to the display by the page is paused by the user agent, OS, or VR hardware
41 Blur(VRDisplayData),
42
43 /// Indicates that presentation to the display by the page has resumed after being blurred.
44 Focus(VRDisplayData),
45
46 /// Indicates that a VRDisplay has begun or ended VR presentation
47 PresentChange(VRDisplayData, bool),
48
49 /// Indicates that VRDisplay presentation loop must be paused (i.e Android app goes to background)
50 Pause(u32),
51
52 /// Indicates that VRDisplay presentation loop must be resumed (i.e Android app goes to foreground)
53 Resume(u32),
54
55 /// Indicates that user has exited VRDisplay presentation (i.e. User clicked back key on android)
56 Exit(u32)
57}
58
59impl Into<VREvent> for VRDisplayEvent {
60 fn into(self) -> VREvent {
61 VREvent::Display(self)
62 }
63}
64
65
66#[derive(Debug, Clone)]
67#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))]
68pub enum VRGamepadEvent {
69 /// Indicates that a VRGamepad has been connected.
70 /// params: name, displa_id, state
71 Connect(VRGamepadData, VRGamepadState),
72
73 /// Indicates that a VRGamepad has been disconnected.
74 /// param: gamepad_id
75 Disconnect(u32)
76}
77
78impl Into<VREvent> for VRGamepadEvent {
79 fn into(self) -> VREvent {
80 VREvent::Gamepad(self)
81 }
82}