Skip to main content

uinput_tokio/event/
absolute.rs

1use super::{Code, Kind};
2use crate::Event;
3use ffi::*;
4use libc::c_int;
5
6#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
7pub enum Absolute {
8    Position(Position),
9    Wheel(Wheel),
10    Hat(Hat),
11    Digi(Digi),
12    Multi(Multi),
13}
14
15impl Into<Event> for Absolute {
16    fn into(self) -> Event {
17        Event::Absolute(self)
18    }
19}
20
21impl super::Position for Absolute {}
22
23impl Kind for Absolute {
24    fn kind(&self) -> c_int {
25        EV_ABS
26    }
27}
28
29impl Code for Absolute {
30    fn code(&self) -> c_int {
31        match self {
32            &Absolute::Position(ref v) => v.code(),
33            &Absolute::Wheel(ref v) => v.code(),
34            &Absolute::Hat(ref v) => v.code(),
35            &Absolute::Digi(ref v) => v.code(),
36            &Absolute::Multi(ref v) => v.code(),
37        }
38    }
39}
40
41custom_derive! {
42    #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(PositionVariants))]
43    pub enum Position {
44        X,
45        Y,
46        Z,
47        RX,
48        RY,
49        RZ,
50    }
51}
52
53impl Into<Event> for Position {
54    fn into(self) -> Event {
55        Event::Absolute(Absolute::Position(self))
56    }
57}
58
59impl super::Position for Position {}
60
61impl Kind for Position {
62    fn kind(&self) -> c_int {
63        EV_ABS
64    }
65}
66
67impl Code for Position {
68    fn code(&self) -> c_int {
69        match self {
70            &Position::X => ABS_X,
71            &Position::Y => ABS_Y,
72            &Position::Z => ABS_Z,
73            &Position::RX => ABS_RX,
74            &Position::RY => ABS_RY,
75            &Position::RZ => ABS_RZ,
76        }
77    }
78}
79
80custom_derive! {
81    #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(WheelVariants))]
82    pub enum Wheel {
83        Throttle,
84        Rudder,
85        Position,
86        Gas,
87        Brake,
88    }
89}
90
91impl Into<Event> for Wheel {
92    fn into(self) -> Event {
93        Event::Absolute(Absolute::Wheel(self))
94    }
95}
96
97impl super::Position for Wheel {}
98
99impl Kind for Wheel {
100    fn kind(&self) -> c_int {
101        EV_ABS
102    }
103}
104
105impl Code for Wheel {
106    fn code(&self) -> c_int {
107        match self {
108            &Wheel::Throttle => ABS_THROTTLE,
109            &Wheel::Rudder => ABS_RUDDER,
110            &Wheel::Position => ABS_WHEEL,
111            &Wheel::Gas => ABS_GAS,
112            &Wheel::Brake => ABS_BRAKE,
113        }
114    }
115}
116
117custom_derive! {
118    #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(HatVariants))]
119    pub enum Hat {
120        X0,
121        Y0,
122        X1,
123        Y1,
124        X2,
125        Y2,
126        X3,
127        Y3,
128    }
129}
130
131impl Into<Event> for Hat {
132    fn into(self) -> Event {
133        Event::Absolute(Absolute::Hat(self))
134    }
135}
136
137impl super::Position for Hat {}
138
139impl Kind for Hat {
140    fn kind(&self) -> c_int {
141        EV_ABS
142    }
143}
144
145impl Code for Hat {
146    fn code(&self) -> c_int {
147        match self {
148            &Hat::X0 => ABS_HAT0X,
149            &Hat::Y0 => ABS_HAT0Y,
150            &Hat::X1 => ABS_HAT1X,
151            &Hat::Y1 => ABS_HAT1Y,
152            &Hat::X2 => ABS_HAT2X,
153            &Hat::Y2 => ABS_HAT2Y,
154            &Hat::X3 => ABS_HAT3X,
155            &Hat::Y3 => ABS_HAT3Y,
156        }
157    }
158}
159
160custom_derive! {
161    #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(DigiVariants))]
162    pub enum Digi {
163        Pressure,
164        Distance,
165        TiltX,
166        TiltY,
167        ToolWidth,
168        Volume,
169    }
170}
171
172impl Into<Event> for Digi {
173    fn into(self) -> Event {
174        Event::Absolute(Absolute::Digi(self))
175    }
176}
177
178impl super::Position for Digi {}
179
180impl Kind for Digi {
181    fn kind(&self) -> c_int {
182        EV_ABS
183    }
184}
185
186impl Code for Digi {
187    fn code(&self) -> c_int {
188        match self {
189            &Digi::Pressure => ABS_PRESSURE,
190            &Digi::Distance => ABS_DISTANCE,
191            &Digi::TiltX => ABS_TILT_X,
192            &Digi::TiltY => ABS_TILT_Y,
193            &Digi::ToolWidth => ABS_TOOL_WIDTH,
194            &Digi::Volume => ABS_VOLUME,
195        }
196    }
197}
198
199custom_derive! {
200    #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(MultiVariants))]
201    pub enum Multi {
202        Slot,
203        TouchMajor,
204        TouchMinor,
205        WidthMajor,
206        WidthMinor,
207        Orientation,
208        PositionX,
209        PositionY,
210        ToolType,
211        BlobId,
212        TrackingId,
213        Pressure,
214        Distance,
215        ToolX,
216        ToolY,
217    }
218}
219
220impl Into<Event> for Multi {
221    fn into(self) -> Event {
222        Event::Absolute(Absolute::Multi(self))
223    }
224}
225
226impl super::Position for Multi {}
227
228impl Kind for Multi {
229    fn kind(&self) -> c_int {
230        EV_ABS
231    }
232}
233
234impl Code for Multi {
235    fn code(&self) -> c_int {
236        match self {
237            &Multi::Slot => ABS_MT_SLOT,
238            &Multi::TouchMajor => ABS_MT_TOUCH_MAJOR,
239            &Multi::TouchMinor => ABS_MT_TOUCH_MINOR,
240            &Multi::WidthMajor => ABS_MT_WIDTH_MAJOR,
241            &Multi::WidthMinor => ABS_MT_WIDTH_MINOR,
242            &Multi::Orientation => ABS_MT_ORIENTATION,
243            &Multi::PositionX => ABS_MT_POSITION_X,
244            &Multi::PositionY => ABS_MT_POSITION_Y,
245            &Multi::ToolType => ABS_MT_TOOL_TYPE,
246            &Multi::BlobId => ABS_MT_BLOB_ID,
247            &Multi::TrackingId => ABS_MT_TRACKING_ID,
248            &Multi::Pressure => ABS_MT_PRESSURE,
249            &Multi::Distance => ABS_MT_DISTANCE,
250            &Multi::ToolX => ABS_MT_TOOL_X,
251            &Multi::ToolY => ABS_MT_TOOL_Y,
252        }
253    }
254}