1use crate::ffi;
4use glib::translate::*;
5
6#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub struct EventMotion(crate::Event);
9
10event_wrapper!(EventMotion, GdkEventMotion);
11event_subtype!(EventMotion, ffi::GDK_MOTION_NOTIFY);
12
13impl EventMotion {
14 #[doc(alias = "get_position")]
15 pub fn position(&self) -> (f64, f64) {
16 let x = self.as_ref().x;
17 let y = self.as_ref().y;
18 (x, y)
19 }
20
21 #[doc(alias = "get_state")]
22 pub fn state(&self) -> crate::ModifierType {
23 unsafe { from_glib(self.as_ref().state) }
24 }
25
26 #[doc(alias = "get_time")]
27 pub fn time(&self) -> u32 {
28 self.as_ref().time
29 }
30
31 #[doc(alias = "gdk_event_request_motions")]
32 pub fn request_motions(&self) {
33 unsafe { ffi::gdk_event_request_motions(self.as_ref()) }
34 }
35
36 #[doc(alias = "get_device")]
37 pub fn device(&self) -> Option<crate::Device> {
38 unsafe { from_glib_none(self.as_ref().device) }
39 }
40
41 #[doc(alias = "get_axes")]
42 pub fn axes(&self) -> Option<(f64, f64)> {
43 let axes = self.as_ref().axes;
44
45 if axes.is_null() {
46 None
47 } else {
48 unsafe { Some((*axes, *axes.offset(1))) }
49 }
50 }
51
52 #[doc(alias = "get_root")]
53 pub fn root(&self) -> (f64, f64) {
54 let x_root = self.as_ref().x_root;
55 let y_root = self.as_ref().y_root;
56 (x_root, y_root)
57 }
58
59 #[doc(alias = "get_is_hint")]
60 pub fn is_hint(&self) -> bool {
61 unsafe { from_glib(self.as_ref().is_hint as _) }
62 }
63}