Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Time coord #314

Merged
merged 4 commits into from Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Gir.toml
Expand Up @@ -96,6 +96,7 @@ manual = [
"Gdk.Geometry",
"Gdk.Rectangle",
"Gdk.RGBA",
"Gdk.TimeCoord",
"GdkPixbuf.Pixbuf",
"Gio.AppLaunchContext",
"Gio.Icon",
Expand Down Expand Up @@ -205,6 +206,12 @@ status = "generate"
name = "get_display"
[object.function.return]
nullable = false
[[object.function]]
name = "free_history"
ignore = true # cannot be used as is
[[object.function]]
name = "get_history"
ignore = true # need to call "free_history" function by hand
[[object.property]]
name = "tool"
version = "3.22"
Expand Down
2 changes: 1 addition & 1 deletion gir
Submodule gir updated 2 files
+4 −0 README.md
+20 −8 src/parser.rs
2 changes: 1 addition & 1 deletion gir-files
8 changes: 0 additions & 8 deletions src/auto/device.rs
Expand Up @@ -90,10 +90,6 @@ impl Device {
unsafe { from_glib(gdk_sys::gdk_device_get_has_cursor(self.to_glib_none().0)) }
}

//pub fn get_history<P: IsA<Window>>(&self, window: &P, start: u32, stop: u32, events: /*Ignored*/Vec<TimeCoord>) -> Option<i32> {
// unsafe { TODO: call gdk_sys:gdk_device_get_history() }
//}

pub fn get_key(&self, index_: u32) -> Option<(u32, ModifierType)> {
unsafe {
let mut keyval = mem::MaybeUninit::uninit();
Expand Down Expand Up @@ -409,10 +405,6 @@ impl Device {
}
}

//pub fn free_history(events: /*Ignored*/&[&TimeCoord]) {
// unsafe { TODO: call gdk_sys:gdk_device_free_history() }
//}

#[cfg_attr(feature = "v3_16", deprecated)]
pub fn grab_info_libgtk_only(display: &Display, device: &Device) -> Option<(Window, bool)> {
skip_assert_initialized!();
Expand Down
4 changes: 2 additions & 2 deletions src/auto/versions.txt
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ b869768)
from gir-files (https://github.com/gtk-rs/gir-files @ cae49a8)
Generated by gir (https://github.com/gtk-rs/gir @ 9e3cb65)
from gir-files (https://github.com/gtk-rs/gir-files @ f7e3c51)
36 changes: 36 additions & 0 deletions src/device.rs
Expand Up @@ -3,9 +3,15 @@
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

use gdk_sys;
use glib::object::IsA;
use glib::translate::*;
use AxisUse;
use Device;
use TimeCoord;
use Window;

use std::mem;
use std::ptr;

impl Device {
pub fn get_axis(&self, axes: &mut [f64], use_: AxisUse, value: &mut f64) -> bool {
Expand All @@ -18,4 +24,34 @@ impl Device {
))
}
}

pub fn get_history<P: IsA<Window>>(
&self,
window: &P,
start: u32,
stop: u32,
) -> Option<Vec<TimeCoord>> {
unsafe {
let mut events = ptr::null_mut();
let mut n_events = mem::MaybeUninit::uninit();
let ret: bool = from_glib(gdk_sys::gdk_device_get_history(
self.to_glib_none().0,
window.as_ref().to_glib_none().0,
start,
stop,
&mut events,
n_events.as_mut_ptr(),
));
if !ret {
return None;
}
let n_events = n_events.assume_init() as usize;
let mut r_events = Vec::with_capacity(n_events);
for i in 0..n_events {
r_events.push((*(events.offset(i as isize) as *mut TimeCoord)).clone());
}
gdk_sys::gdk_device_free_history(events, n_events as _);
Some(r_events)
}
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -83,6 +83,7 @@ mod keys;
mod rectangle;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in commit message: TimeDoord -> TimeCoord

mod rgba;
mod screen;
mod time_coord;
mod visual;
mod window;

Expand Down Expand Up @@ -143,6 +144,7 @@ pub use functions::*;
pub use geometry::Geometry;
pub use rectangle::Rectangle;
pub use rgba::{RgbaParseError, RGBA};
pub use time_coord::TimeCoord;
pub use window::WindowAttr;

#[allow(non_camel_case_types)]
Expand Down
127 changes: 127 additions & 0 deletions src/time_coord.rs
@@ -0,0 +1,127 @@
// Copyright 2013-2015, The Gtk-rs Project Developers.
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

use gdk_sys;
use glib::translate::*;
use glib_sys;
use std::mem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: unused import: `glib`

 --> src/time_coord.rs:6:5

  |

6 | use glib;

  |     ^^^^

warning: unused import: `glib_sys::gconstpointer`

 --> src/time_coord.rs:9:5

  |

9 | use glib_sys::gconstpointer;

  |     ^^^^^^^^^^^^^^^^^^^^^^^

warning: unused import: `gobject_sys`

  --> src/time_coord.rs:10:5

   |

10 | use gobject_sys;

   |     ^^^^^^^^^^^

warning: unused imports: `AsRef`, `From`

  --> src/time_coord.rs:11:20

   |

11 | use std::convert::{AsRef, From};

   |                    ^^^^^  ^^^^


#[derive(Clone)]
#[repr(C)]
pub struct TimeCoord {
pub time: u32,
pub axes: [f64; gdk_sys::GDK_MAX_TIMECOORD_AXES as usize],
}

#[doc(hidden)]
impl Uninitialized for TimeCoord {
#[inline]
unsafe fn uninitialized() -> Self {
mem::zeroed()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not MaybeUninit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it. Good catch!

}
}

#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const gdk_sys::GdkTimeCoord> for TimeCoord {
type Storage = &'a Self;

#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const gdk_sys::GdkTimeCoord, Self> {
let ptr: *const TimeCoord = &*self;
Stash(ptr as *const gdk_sys::GdkTimeCoord, self)
}
}

#[doc(hidden)]
impl<'a> ToGlibPtrMut<'a, *mut gdk_sys::GdkTimeCoord> for TimeCoord {
type Storage = &'a mut Self;

#[inline]
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut gdk_sys::GdkTimeCoord, Self> {
let ptr: *mut TimeCoord = &mut *self;
StashMut(ptr as *mut gdk_sys::GdkTimeCoord, self)
}
}

#[doc(hidden)]
impl FromGlibPtrNone<*const gdk_sys::GdkTimeCoord> for TimeCoord {
unsafe fn from_glib_none(ptr: *const gdk_sys::GdkTimeCoord) -> Self {
(*(ptr as *const TimeCoord)).clone()
}
}

#[doc(hidden)]
impl FromGlibPtrNone<*mut gdk_sys::GdkTimeCoord> for TimeCoord {
unsafe fn from_glib_none(ptr: *mut gdk_sys::GdkTimeCoord) -> Self {
(*(ptr as *mut TimeCoord)).clone()
}
}

#[doc(hidden)]
impl FromGlibPtrBorrow<*const gdk_sys::GdkTimeCoord> for TimeCoord {
unsafe fn from_glib_borrow(ptr: *const gdk_sys::GdkTimeCoord) -> Self {
(*(ptr as *const TimeCoord)).clone()
}
}

#[doc(hidden)]
impl FromGlibPtrBorrow<*mut gdk_sys::GdkTimeCoord> for TimeCoord {
unsafe fn from_glib_borrow(ptr: *mut gdk_sys::GdkTimeCoord) -> Self {
(*(ptr as *mut TimeCoord)).clone()
}
}

#[doc(hidden)]
impl FromGlibPtrFull<*mut gdk_sys::GdkTimeCoord> for TimeCoord {
unsafe fn from_glib_full(ptr: *mut gdk_sys::GdkTimeCoord) -> Self {
let time_coord = (*(ptr as *mut TimeCoord)).clone();
glib_sys::g_free(ptr as *mut _);
time_coord
}
}

#[doc(hidden)]
impl FromGlibPtrFull<*const gdk_sys::GdkTimeCoord> for TimeCoord {
unsafe fn from_glib_full(ptr: *const gdk_sys::GdkTimeCoord) -> Self {
let time_coord = (*(ptr as *const TimeCoord)).clone();
glib_sys::g_free(ptr as *mut _);
time_coord
}
}

impl FromGlibContainerAsVec<gdk_sys::GdkTimeCoord, *mut gdk_sys::GdkTimeCoord> for TimeCoord {
unsafe fn from_glib_none_num_as_vec(ptr: *mut gdk_sys::GdkTimeCoord, num: usize) -> Vec<Self> {
if num == 0 || ptr.is_null() {
return Vec::new();
}

let mut res = Vec::with_capacity(num);
for i in 0..num {
res.push((*(ptr.offset(i as isize) as *mut TimeCoord)).clone());
}
res
}

unsafe fn from_glib_container_num_as_vec(
ptr: *mut gdk_sys::GdkTimeCoord,
num: usize,
) -> Vec<Self> {
let res = FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num);
glib_sys::g_free(ptr as *mut _);
res
}

unsafe fn from_glib_full_num_as_vec(ptr: *mut gdk_sys::GdkTimeCoord, num: usize) -> Vec<Self> {
if num == 0 || ptr.is_null() {
return Vec::new();
}

let mut res = Vec::with_capacity(num);
for i in 0..num {
res.push((*(ptr.offset(i as isize) as *mut TimeCoord)).clone());
}
glib_sys::g_free(ptr as *mut _);
res
}
}