Skip to main content

uinput_tokio/event/
relative.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 Relative {
8    Position(Position),
9    Wheel(Wheel),
10}
11
12impl Into<Event> for Relative {
13    fn into(self) -> Event {
14        Event::Relative(self)
15    }
16}
17
18impl super::Position for Relative {}
19
20impl Kind for Relative {
21    fn kind(&self) -> c_int {
22        EV_REL
23    }
24}
25
26impl Code for Relative {
27    fn code(&self) -> c_int {
28        match self {
29            &Relative::Position(ref v) => v.code(),
30            &Relative::Wheel(ref v) => v.code(),
31        }
32    }
33}
34
35custom_derive! {
36    #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(PositionVariants))]
37    pub enum Position {
38        X,
39        Y,
40        Z,
41        RX,
42        RY,
43        RZ,
44    }
45}
46
47impl Into<Event> for Position {
48    fn into(self) -> Event {
49        Event::Relative(Relative::Position(self))
50    }
51}
52
53impl super::Position for Position {}
54
55impl Kind for Position {
56    fn kind(&self) -> c_int {
57        EV_REL
58    }
59}
60
61impl Code for Position {
62    fn code(&self) -> c_int {
63        match self {
64            &Position::X => REL_X,
65            &Position::Y => REL_Y,
66            &Position::Z => REL_Z,
67            &Position::RX => REL_RX,
68            &Position::RY => REL_RY,
69            &Position::RZ => REL_RZ,
70        }
71    }
72}
73
74custom_derive! {
75    #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(WheelVariants))]
76    pub enum Wheel {
77        Horizontal,
78        Dial,
79        Vertical,
80    }
81}
82
83impl Into<Event> for Wheel {
84    fn into(self) -> Event {
85        Event::Relative(Relative::Wheel(self))
86    }
87}
88
89impl super::Position for Wheel {}
90
91impl Kind for Wheel {
92    fn kind(&self) -> c_int {
93        EV_REL
94    }
95}
96
97impl Code for Wheel {
98    fn code(&self) -> c_int {
99        match self {
100            &Wheel::Horizontal => REL_HWHEEL,
101            &Wheel::Dial => REL_DIAL,
102            &Wheel::Vertical => REL_WHEEL,
103        }
104    }
105}