webxr_api/
input.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use euclid::RigidTransform3D;
6
7use crate::{Hand, Input, JointFrame, Native};
8
9#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
10#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
11pub struct InputId(pub u32);
12
13#[derive(Clone, Copy, Debug)]
14#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
15pub enum Handedness {
16    None,
17    Left,
18    Right,
19}
20
21#[derive(Clone, Copy, Debug)]
22#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
23pub enum TargetRayMode {
24    Gaze,
25    TrackedPointer,
26    Screen,
27    TransientPointer,
28}
29
30#[derive(Clone, Debug)]
31#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
32pub struct InputSource {
33    pub handedness: Handedness,
34    pub target_ray_mode: TargetRayMode,
35    pub id: InputId,
36    pub supports_grip: bool,
37    pub hand_support: Option<Hand<()>>,
38    pub profiles: Vec<String>,
39}
40
41#[derive(Clone, Debug)]
42#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
43pub struct InputFrame {
44    pub id: InputId,
45    pub target_ray_origin: Option<RigidTransform3D<f32, Input, Native>>,
46    pub grip_origin: Option<RigidTransform3D<f32, Input, Native>>,
47    pub pressed: bool,
48    pub hand: Option<Box<Hand<JointFrame>>>,
49    pub squeezed: bool,
50    pub button_values: Vec<f32>,
51    pub axis_values: Vec<f32>,
52    pub input_changed: bool,
53}
54
55#[derive(Clone, Copy, Debug, Eq, PartialEq)]
56#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
57pub enum SelectEvent {
58    /// Selection started
59    Start,
60    /// Selection ended *without* it being a contiguous select event
61    End,
62    /// Selection ended *with* it being a contiguous select event
63    Select,
64}
65
66#[derive(Clone, Copy, Debug, Eq, PartialEq)]
67#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
68pub enum SelectKind {
69    Select,
70    Squeeze,
71}