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
//#![deny(missing_docs)]
#![doc(html_root_url = "http://arcnmx.github.io/input-linux-rs/")]

pub extern crate input_linux_sys as sys;
extern crate nix;
#[cfg(feature = "with-serde")]
extern crate serde;
#[cfg(feature = "with-serde")]
#[macro_use]
extern crate serde_derive;

#[macro_use]
mod macros;

mod kinds;
pub use kinds::*;

mod time;
pub use time::EventTime;

mod events;
pub use events::*;

mod keys;
pub use keys::Key;

pub mod evdev;
pub use evdev::EvdevHandle;

pub mod uinput;
pub use uinput::UInputHandle;

pub mod enum_iterator;

pub mod bitmask;
pub use bitmask::Bitmask;

#[cfg(feature = "with-tokio")]
mod tokio;

#[cfg(feature = "with-tokio")]
pub use tokio::EventCodec;

#[repr(C)]
#[derive(Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct InputId {
    pub bustype: u16,
    pub vendor: u16,
    pub product: u16,
    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).clone()
    }
}

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

#[repr(C)]
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct AbsoluteInfoSetup {
    pub axis: AbsoluteAxis,
    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 = "with-serde", derive(Deserialize, Serialize))]
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).clone()
    }
}

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