gdk/device.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::AxisUse;
4use crate::Device;
5use crate::TimeCoord;
6use crate::Window;
7use glib::object::IsA;
8use glib::translate::*;
9
10use std::mem;
11use std::ptr;
12
13mod sealed {
14 pub trait Sealed {}
15 impl<T: glib::IsA<crate::Device>> Sealed for T {}
16}
17
18pub trait DeviceExtManual: IsA<Device> + sealed::Sealed + 'static {
19 #[doc(alias = "gdk_device_get_axis")]
20 #[doc(alias = "get_axis")]
21 fn is_axis(&self, axes: &mut [f64], use_: AxisUse, value: &mut f64) -> bool {
22 unsafe {
23 from_glib(ffi::gdk_device_get_axis(
24 self.as_ref().to_glib_none().0,
25 axes.as_mut_ptr(),
26 use_.into_glib(),
27 value,
28 ))
29 }
30 }
31
32 /// Obtains the motion history for a pointer device; given a starting and
33 /// ending timestamp, return all events in the motion history for
34 /// the device in the given range of time. Some windowing systems
35 /// do not support motion history, in which case, [`false`] will
36 /// be returned. (This is not distinguishable from the case where
37 /// motion history is supported and no events were found.)
38 ///
39 /// Note that there is also [`Window::set_event_compression()`][crate::Window::set_event_compression()] to get
40 /// more motion events delivered directly, independent of the windowing
41 /// system.
42 /// ## `window`
43 /// the window with respect to which which the event coordinates will be reported
44 /// ## `start`
45 /// starting timestamp for range of events to return
46 /// ## `stop`
47 /// ending timestamp for the range of events to return
48 ///
49 /// # Returns
50 ///
51 /// [`true`] if the windowing system supports motion history and
52 /// at least one event was found.
53 ///
54 /// ## `events`
55 ///
56 /// location to store a newly-allocated array of [`TimeCoord`][crate::TimeCoord], or
57 /// [`None`]
58 #[doc(alias = "gdk_device_get_history")]
59 #[doc(alias = "get_history")]
60 fn history<P: IsA<Window>>(&self, window: &P, start: u32, stop: u32) -> Vec<TimeCoord> {
61 unsafe {
62 let mut events = ptr::null_mut();
63 let mut n_events = mem::MaybeUninit::uninit();
64 let ret: bool = from_glib(ffi::gdk_device_get_history(
65 self.as_ref().to_glib_none().0,
66 window.as_ref().to_glib_none().0,
67 start,
68 stop,
69 &mut events,
70 n_events.as_mut_ptr(),
71 ));
72 if !ret {
73 return Vec::new();
74 }
75 let n_events = n_events.assume_init() as usize;
76 FromGlibContainer::from_glib_full_num(events, n_events)
77 }
78 }
79}
80
81impl<O: IsA<Device>> DeviceExtManual for O {}