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