input_linux/
lib.rs

1#![deny(missing_docs)]
2#![doc(html_root_url = "https://docs.rs/input-linux/0.7.1/")]
3#![cfg_attr(feature = "dox", feature(doc_cfg))]
4
5//! Userspace bindings to the Linux evdev and uinput subsystems.
6//!
7//! Start by looking at the [`EvdevHandle`] and [`UInputHandle`] types.
8
9pub use input_linux_sys as sys;
10#[cfg(feature = "serde")]
11use serde::{Deserialize, Serialize, };
12
13#[macro_use]
14mod macros;
15
16mod kinds;
17pub use crate::kinds::*;
18
19mod time;
20pub use crate::time::EventTime;
21
22mod events;
23pub use crate::events::*;
24
25mod keys;
26pub use crate::keys::Key;
27
28pub mod evdev;
29pub use crate::evdev::EvdevHandle;
30
31pub mod uinput;
32pub use crate::uinput::UInputHandle;
33
34pub mod enum_iterator;
35
36pub mod bitmask;
37pub use crate::bitmask::Bitmask;
38
39#[cfg(feature = "codec")]
40#[cfg_attr(feature = "dox", doc(cfg(feature = "codec")))]
41mod codec;
42
43#[cfg(feature = "codec")]
44pub use crate::codec::EventCodec;
45
46#[repr(C)]
47#[derive(Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
48#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
49/// Identifies an input device.
50pub struct InputId {
51    /// Identifies the bus where the input device is found, see `sys::BUS_*`
52    pub bustype: u16,
53    /// The vendor ID of the input device.
54    pub vendor: u16,
55    /// The product ID of the input device.
56    pub product: u16,
57    /// The version of the input device.
58    pub version: u16,
59}
60
61impl<'a> From<&'a sys::input_id> for &'a InputId {
62    fn from(id: &'a sys::input_id) -> Self {
63        let raw = id as *const _ as *const _;
64        unsafe { &*raw }
65    }
66}
67
68impl<'a> From<&'a InputId> for &'a sys::input_id {
69    fn from(id: &'a InputId) -> Self {
70        let raw = id as *const _ as *const _;
71        unsafe { &*raw }
72    }
73}
74
75impl From<sys::input_id> for InputId {
76    fn from(id: sys::input_id) -> Self {
77        *<&InputId>::from(&id)
78    }
79}
80
81impl From<InputId> for sys::input_id {
82    fn from(id: InputId) -> Self {
83        *<&sys::input_id>::from(&id)
84    }
85}
86
87#[repr(C)]
88#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
89#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
90/// A descriptor used to create a virtual uinput absolute axis.
91pub struct AbsoluteInfoSetup {
92    /// The axis to attach the `AbsoluteInfo` constraints to.
93    pub axis: AbsoluteAxis,
94    /// Describes the capabilities of the absolute axis.
95    pub info: AbsoluteInfo,
96}
97
98impl<'a> From<&'a AbsoluteInfoSetup> for &'a sys::uinput_abs_setup {
99    fn from(info: &'a AbsoluteInfoSetup) -> Self {
100        let raw = info as *const _ as *const _;
101        unsafe { &*raw }
102    }
103}
104
105impl From<AbsoluteInfoSetup> for sys::uinput_abs_setup {
106    fn from(info: AbsoluteInfoSetup) -> Self {
107        use std::mem;
108        unsafe {
109            mem::transmute(info)
110        }
111    }
112}
113
114#[repr(C)]
115#[derive(Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
116#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
117/// Describes the capabilities and constraints of an input device's absolute axis.
118pub struct AbsoluteInfo {
119    /// latest reported value for the axis
120    pub value: i32,
121    /// specifies minimum value for the axis
122    pub minimum: i32,
123    /// specifies maximum value for the axis
124    pub maximum: i32,
125    /// specifies fuzz value that is used to filter noise from the event stream
126    pub fuzz: i32,
127    /// values that are within this value will be discarded by joydev interface and reported as 0 instead
128    pub flat: i32,
129    /// specifies resolution for the values reported for the axis
130    ///
131    /// Resolution for main axes (ABS_X, ABS_Y, ABS_Z) is reported in units per
132    /// millimeter (units/mm), resolution for rotational axes (ABS_RX, ABS_RY,
133    /// ABS_RZ) is reported in units per radian.
134    pub resolution: i32,
135}
136
137impl<'a> From<&'a sys::input_absinfo> for &'a AbsoluteInfo {
138    fn from(info: &'a sys::input_absinfo) -> Self {
139        let raw = info as *const _ as *const _;
140        unsafe { &*raw }
141    }
142}
143
144impl<'a> From<&'a AbsoluteInfo> for &'a sys::input_absinfo {
145    fn from(info: &'a AbsoluteInfo) -> Self {
146        let raw = info as *const _ as *const _;
147        unsafe { &*raw }
148    }
149}
150
151impl From<sys::input_absinfo> for AbsoluteInfo {
152    fn from(info: sys::input_absinfo) -> Self {
153        *<&AbsoluteInfo>::from(&info)
154    }
155}
156
157impl From<AbsoluteInfo> for sys::input_absinfo {
158    fn from(info: AbsoluteInfo) -> Self {
159        *<&sys::input_absinfo>::from(&info)
160    }
161}