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
//! TODO Documentation
use wlroots_sys::{wlr_event_touch_cancel, wlr_event_touch_down, wlr_event_touch_motion,
wlr_event_touch_up};
#[derive(Debug)]
/// Event that is triggered when a touch down event occurs.
pub struct Down {
event: *mut wlr_event_touch_down
}
#[derive(Debug)]
/// Event that is triggered when a touch up event occurs.
pub struct Up {
event: *mut wlr_event_touch_up
}
#[derive(Debug)]
/// Event that is triggered when a touch motion event occurs.
pub struct Motion {
event: *mut wlr_event_touch_motion
}
#[derive(Debug)]
/// Event that is triggered when a touch cancel event occurs.
pub struct Cancel {
event: *mut wlr_event_touch_cancel
}
impl Down {
/// Constructs a `Down` from a raw event pointer.
pub(crate) unsafe fn from_ptr(event: *mut wlr_event_touch_down) -> Self {
Down { event }
}
/// Gets how long the touch event has been going on for.
pub fn time_msec(&self) -> u32 {
unsafe { (*self.event).time_msec }
}
/// Gets the touch id associated with this event.
pub fn touch_id(&self) -> i32 {
unsafe { (*self.event).touch_id }
}
/// Gets the location of the touch event in mm.
///
/// Return value is in (x, y) format.
pub fn location(&self) -> (f64, f64) {
unsafe { ((*self.event).x, (*self.event).y) }
}
}
impl Up {
/// Constructs a `Up` from a raw event pointer.
pub(crate) unsafe fn from_ptr(event: *mut wlr_event_touch_up) -> Self {
Up { event }
}
pub fn time_msec(&self) -> u32 {
unsafe { (*self.event).time_msec }
}
/// Gets the touch id associated with this event.
pub fn touch_id(&self) -> i32 {
unsafe { (*self.event).touch_id }
}
}
impl Motion {
/// Constructs a `Motion` from a raw event pointer.
pub(crate) unsafe fn from_ptr(event: *mut wlr_event_touch_motion) -> Self {
Motion { event }
}
/// Gets how long the touch event has been going on for.
pub fn time_msec(&self) -> u32 {
unsafe { (*self.event).time_msec }
}
/// Gets the touch id associated with this event.
pub fn touch_id(&self) -> i32 {
unsafe { (*self.event).touch_id }
}
/// Gets the location of the touch event in mm.
///
/// Return value is in (x, y) format.
pub fn location(&self) -> (f64, f64) {
unsafe { ((*self.event).x, (*self.event).y) }
}
}
impl Cancel {
/// Constructs a `Cancel` from a raw event pointe
pub(crate) unsafe fn from_ptr(event: *mut wlr_event_touch_cancel) -> Self {
Cancel { event }
}
pub fn time_msec(&self) -> u32 {
unsafe { (*self.event).time_msec }
}
/// Gets the touch id associated with this event.
pub fn touch_id(&self) -> i32 {
unsafe { (*self.event).touch_id }
}
}