Skip to main content

gdk/
event_motion.rs

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