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
use super::EventTrait;
use {AsRaw, Context, FromRaw};
use ffi;
pub trait DeviceEventTrait: AsRaw<ffi::libinput_event_device_notify> + Context {
fn into_device_event(self) -> DeviceEvent
where
Self: Sized,
{
unsafe { DeviceEvent::from_raw(self.as_raw_mut(), self.context()) }
}
}
impl<T: AsRaw<ffi::libinput_event_device_notify> + Context> DeviceEventTrait for T {}
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum DeviceEvent {
Added(DeviceAddedEvent),
Removed(DeviceRemovedEvent),
}
impl EventTrait for DeviceEvent {
#[doc(hidden)]
fn as_raw_event(&self) -> *mut ffi::libinput_event {
match *self {
DeviceEvent::Added(ref event) => event.as_raw_event(),
DeviceEvent::Removed(ref event) => event.as_raw_event(),
}
}
}
impl FromRaw<ffi::libinput_event_device_notify> for DeviceEvent {
unsafe fn from_raw(event: *mut ffi::libinput_event_device_notify, context: &::context::Libinput) -> Self {
let base = ffi::libinput_event_device_notify_get_base_event(event);
match ffi::libinput_event_get_type(base) {
ffi::libinput_event_type_LIBINPUT_EVENT_DEVICE_ADDED => {
DeviceEvent::Added(DeviceAddedEvent::from_raw(event, context))
}
ffi::libinput_event_type_LIBINPUT_EVENT_DEVICE_REMOVED => {
DeviceEvent::Removed(DeviceRemovedEvent::from_raw(event, context))
}
_ => unreachable!(),
}
}
}
impl AsRaw<ffi::libinput_event_device_notify> for DeviceEvent {
fn as_raw(&self) -> *const ffi::libinput_event_device_notify {
match *self {
DeviceEvent::Added(ref event) => event.as_raw(),
DeviceEvent::Removed(ref event) => event.as_raw(),
}
}
}
impl Context for DeviceEvent {
fn context(&self) -> &::Libinput {
match *self {
DeviceEvent::Added(ref event) => event.context(),
DeviceEvent::Removed(ref event) => event.context(),
}
}
}
ffi_event_struct!(
struct DeviceAddedEvent, ffi::libinput_event_device_notify, ffi::libinput_event_device_notify_get_base_event);
ffi_event_struct!(
struct DeviceRemovedEvent, ffi::libinput_event_device_notify, ffi::libinput_event_device_notify_get_base_event);