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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
use super::EventTrait;
pub use super::pointer::ButtonState;
use {ffi, AsRaw, Context, FromRaw};
mod mode_group;
pub use self::mode_group::*;
pub trait TabletPadEventTrait: AsRaw<ffi::libinput_event_tablet_pad> + Context {
ffi_func!(
fn time, ffi::libinput_event_tablet_pad_get_time, u32);
ffi_func!(
fn time_usec, ffi::libinput_event_tablet_pad_get_time_usec, u64);
ffi_func!(
fn mode, ffi::libinput_event_tablet_pad_get_mode, u32);
fn mode_group(&self) -> TabletPadModeGroup {
unsafe {
TabletPadModeGroup::from_raw(
ffi::libinput_event_tablet_pad_get_mode_group(self.as_raw_mut()),
self.context(),
)
}
}
fn into_tablet_pad_event(self) -> TabletPadEvent
where
Self: Sized,
{
unsafe { TabletPadEvent::from_raw(self.as_raw_mut(), self.context()) }
}
}
impl<T: AsRaw<ffi::libinput_event_tablet_pad> + Context> TabletPadEventTrait for T {}
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum TabletPadEvent {
Button(TabletPadButtonEvent),
Ring(TabletPadRingEvent),
Strip(TabletPadStripEvent),
}
impl EventTrait for TabletPadEvent {
#[doc(hidden)]
fn as_raw_event(&self) -> *mut ffi::libinput_event {
match *self {
TabletPadEvent::Button(ref event) => event.as_raw_event(),
TabletPadEvent::Ring(ref event) => event.as_raw_event(),
TabletPadEvent::Strip(ref event) => event.as_raw_event(),
}
}
}
impl FromRaw<ffi::libinput_event_tablet_pad> for TabletPadEvent {
unsafe fn from_raw(event: *mut ffi::libinput_event_tablet_pad, context: &::Libinput) -> Self {
let base = ffi::libinput_event_tablet_pad_get_base_event(event);
match ffi::libinput_event_get_type(base) {
ffi::libinput_event_type_LIBINPUT_EVENT_TABLET_PAD_BUTTON => {
TabletPadEvent::Button(TabletPadButtonEvent::from_raw(event, context))
}
ffi::libinput_event_type_LIBINPUT_EVENT_TABLET_PAD_RING => {
TabletPadEvent::Ring(TabletPadRingEvent::from_raw(event, context))
}
ffi::libinput_event_type_LIBINPUT_EVENT_TABLET_PAD_STRIP => {
TabletPadEvent::Strip(TabletPadStripEvent::from_raw(event, context))
}
_ => unreachable!(),
}
}
}
impl AsRaw<ffi::libinput_event_tablet_pad> for TabletPadEvent {
fn as_raw(&self) -> *const ffi::libinput_event_tablet_pad {
match *self {
TabletPadEvent::Button(ref event) => event.as_raw(),
TabletPadEvent::Ring(ref event) => event.as_raw(),
TabletPadEvent::Strip(ref event) => event.as_raw(),
}
}
}
impl Context for TabletPadEvent {
fn context(&self) -> &::Libinput {
match *self {
TabletPadEvent::Button(ref event) => event.context(),
TabletPadEvent::Ring(ref event) => event.context(),
TabletPadEvent::Strip(ref event) => event.context(),
}
}
}
ffi_event_struct!(
struct TabletPadButtonEvent, ffi::libinput_event_tablet_pad, ffi::libinput_event_tablet_pad_get_base_event);
impl TabletPadButtonEvent {
ffi_func!(
pub fn button_number, ffi::libinput_event_tablet_pad_get_button_number, u32);
pub fn button_state(&self) -> ButtonState {
match unsafe { ffi::libinput_event_tablet_pad_get_button_state(self.as_raw_mut()) } {
ffi::libinput_button_state_LIBINPUT_BUTTON_STATE_PRESSED => ButtonState::Pressed,
ffi::libinput_button_state_LIBINPUT_BUTTON_STATE_RELEASED => ButtonState::Released,
_ => panic!("libinput returned invalid 'libinput_button_state'"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RingAxisSource {
Unknown,
Finger,
}
ffi_event_struct!(
struct TabletPadRingEvent, ffi::libinput_event_tablet_pad, ffi::libinput_event_tablet_pad_get_base_event);
impl TabletPadRingEvent {
ffi_func!(
pub fn number, ffi::libinput_event_tablet_pad_get_ring_number, u32);
ffi_func!(
pub fn position, ffi::libinput_event_tablet_pad_get_ring_position, f64);
pub fn source(&self) -> RingAxisSource {
match unsafe { ffi::libinput_event_tablet_pad_get_ring_source(self.as_raw_mut()) } {
ffi::libinput_tablet_pad_ring_axis_source_LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN => {
RingAxisSource::Unknown
}
ffi::libinput_tablet_pad_ring_axis_source_LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER => {
RingAxisSource::Finger
}
_ => panic!("libinput returned invalid 'libinput_tablet_pad_ring_axis_source'"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StripAxisSource {
Unknown,
Finger,
}
ffi_event_struct!(
struct TabletPadStripEvent, ffi::libinput_event_tablet_pad, ffi::libinput_event_tablet_pad_get_base_event);
impl TabletPadStripEvent {
ffi_func!(
pub fn number, ffi::libinput_event_tablet_pad_get_strip_number, u32);
ffi_func!(
pub fn position, ffi::libinput_event_tablet_pad_get_strip_position, f64);
pub fn source(&self) -> StripAxisSource {
match unsafe { ffi::libinput_event_tablet_pad_get_strip_source(self.as_raw_mut()) } {
ffi::libinput_tablet_pad_strip_axis_source_LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN => {
StripAxisSource::Unknown
}
ffi::libinput_tablet_pad_strip_axis_source_LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER => {
StripAxisSource::Finger
}
_ => panic!("libinput returned invalid 'libinput_tablet_pad_strip_axis_source'"),
}
}
}