1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#![deny(missing_docs)]
#![doc(html_root_url = "https://docs.rs/input-linux/0.6.0/")]
#![cfg_attr(feature = "dox", feature(doc_cfg))]

//! Userspace bindings to the Linux evdev and uinput subsystems.
//!
//! Start by looking at the [`EvdevHandle`] and [`UInputHandle`] types.

pub use input_linux_sys as sys;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize, };

#[macro_use]
mod macros;

mod kinds;
pub use crate::kinds::*;

mod time;
pub use crate::time::EventTime;

mod events;
pub use crate::events::*;

mod keys;
pub use crate::keys::Key;

pub mod evdev;
pub use crate::evdev::EvdevHandle;

pub mod uinput;
pub use crate::uinput::UInputHandle;

pub mod enum_iterator;

pub mod bitmask;
pub use crate::bitmask::Bitmask;

#[cfg(feature = "codec")]
#[cfg_attr(feature = "dox", doc(cfg(feature = "codec")))]
mod codec;

#[cfg(feature = "codec")]
pub use crate::codec::EventCodec;

#[repr(C)]
#[derive(Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
/// Identifies an input device.
pub struct InputId {
	/// Identifies the bus where the input device is found, see `sys::BUS_*`
	pub bustype: u16,
	/// The vendor ID of the input device.
	pub vendor: u16,
	/// The product ID of the input device.
	pub product: u16,
	/// The version of the input device.
	pub version: u16,
}

impl<'a> From<&'a sys::input_id> for &'a InputId {
	fn from(id: &'a sys::input_id) -> Self {
		let raw = id as *const _ as *const _;
		unsafe { &*raw }
	}
}

impl<'a> From<&'a InputId> for &'a sys::input_id {
	fn from(id: &'a InputId) -> Self {
		let raw = id as *const _ as *const _;
		unsafe { &*raw }
	}
}

impl From<sys::input_id> for InputId {
	fn from(id: sys::input_id) -> Self {
		*<&InputId>::from(&id)
	}
}

impl From<InputId> for sys::input_id {
	fn from(id: InputId) -> Self {
		*<&sys::input_id>::from(&id)
	}
}

#[repr(C)]
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
/// A descriptor used to create a virtual uinput absolute axis.
pub struct AbsoluteInfoSetup {
	/// The axis to attach the `AbsoluteInfo` constraints to.
	pub axis: AbsoluteAxis,
	/// Describes the capabilities of the absolute axis.
	pub info: AbsoluteInfo,
}

impl<'a> From<&'a AbsoluteInfoSetup> for &'a sys::uinput_abs_setup {
	fn from(info: &'a AbsoluteInfoSetup) -> Self {
		let raw = info as *const _ as *const _;
		unsafe { &*raw }
	}
}

impl From<AbsoluteInfoSetup> for sys::uinput_abs_setup {
	fn from(info: AbsoluteInfoSetup) -> Self {
		use std::mem;
		unsafe {
			mem::transmute(info)
		}
	}
}

#[repr(C)]
#[derive(Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
/// Describes the capabilities and constraints of an input device's absolute axis.
pub struct AbsoluteInfo {
	/// latest reported value for the axis
	pub value: i32,
	/// specifies minimum value for the axis
	pub minimum: i32,
	/// specifies maximum value for the axis
	pub maximum: i32,
	/// specifies fuzz value that is used to filter noise from the event stream
	pub fuzz: i32,
	/// values that are within this value will be discarded by joydev interface and reported as 0 instead
	pub flat: i32,
	/// specifies resolution for the values reported for the axis
	///
	/// Resolution for main axes (ABS_X, ABS_Y, ABS_Z) is reported in units per
	/// millimeter (units/mm), resolution for rotational axes (ABS_RX, ABS_RY,
	/// ABS_RZ) is reported in units per radian.
	pub resolution: i32,
}

impl<'a> From<&'a sys::input_absinfo> for &'a AbsoluteInfo {
	fn from(info: &'a sys::input_absinfo) -> Self {
		let raw = info as *const _ as *const _;
		unsafe { &*raw }
	}
}

impl<'a> From<&'a AbsoluteInfo> for &'a sys::input_absinfo {
	fn from(info: &'a AbsoluteInfo) -> Self {
		let raw = info as *const _ as *const _;
		unsafe { &*raw }
	}
}

impl From<sys::input_absinfo> for AbsoluteInfo {
	fn from(info: sys::input_absinfo) -> Self {
		*<&AbsoluteInfo>::from(&info)
	}
}

impl From<AbsoluteInfo> for sys::input_absinfo {
	fn from(info: AbsoluteInfo) -> Self {
		*<&sys::input_absinfo>::from(&info)
	}
}