1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 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 ffi;
use glib::translate::*;
use glib_ffi;
use Gravity;

#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(C)]
pub struct Geometry {
    pub min_width: i32,
    pub min_height: i32,
    pub max_width: i32,
    pub max_height: i32,
    pub base_width: i32,
    pub base_height: i32,
    pub width_inc: i32,
    pub height_inc: i32,
    pub min_aspect: f64,
    pub max_aspect: f64,
    pub win_gravity: Gravity,
}

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

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

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

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

#[doc(hidden)]
impl FromGlibPtrNone<*const ffi::GdkGeometry> for Geometry {
    unsafe fn from_glib_none(ptr: *const ffi::GdkGeometry) -> Self {
        *(ptr as *const Geometry)
    }
}

#[doc(hidden)]
impl FromGlibPtrNone<*mut ffi::GdkGeometry> for Geometry {
    unsafe fn from_glib_none(ptr: *mut ffi::GdkGeometry) -> Self {
        *(ptr as *mut Geometry)
    }
}

#[doc(hidden)]
impl FromGlibPtrFull<*mut ffi::GdkGeometry> for Geometry {
    #[inline]
    unsafe fn from_glib_full(ptr: *mut ffi::GdkGeometry) -> Self {
        let geom = *(ptr as *mut Geometry);
        glib_ffi::g_free(ptr as *mut _);
        geom
    }
}