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
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use std::fmt;

#[macro_use]
mod support;
mod generated;

// Hand-written bindings for cases which are too few or weird to bother automating

wrapper! {
    #[derive(Copy, Clone, Eq, PartialEq)]
    Bool32(u32)
}
pub const TRUE: Bool32 = Bool32(1);
pub const FALSE: Bool32 = Bool32(0);
impl fmt::Display for Bool32 {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        (*self != FALSE).fmt(fmt)
    }
}

impl fmt::Debug for Bool32 {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        (*self != FALSE).fmt(fmt)
    }
}

impl From<Bool32> for bool {
    fn from(x: Bool32) -> Self {
        x != FALSE
    }
}

wrapper! {
    #[derive(Copy, Clone, Eq, PartialEq)]
    Time(i64)
}

impl fmt::Debug for Time {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        self.0.fmt(fmt)
    }
}

wrapper! {
    #[derive(Copy, Clone, Eq, PartialEq)]
    Duration(i64)
}

impl Duration {
    pub const NONE: Self = Self(0);
    pub const INFINITE: Self = Self(0x7fffffffffffffff);
    pub const MIN_HAPTIC: Self = Self(-1);
}

impl fmt::Debug for Duration {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        self.0.fmt(fmt)
    }
}

wrapper! {
    #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
    Path(u64)
}

impl Path {
    pub const NULL: Path = Path(0);
}

wrapper! {
    #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
    SystemId(u64)
}

impl SystemId {
    pub const NULL: SystemId = SystemId(0);
}

wrapper! {
    #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
    Version(u32)
}

impl Version {
    #[inline]
    pub const fn new(major: u32, minor: u32, patch: u32) -> Self {
        Self(major << 22 | minor << 12 | patch)
    }

    #[inline]
    pub const fn major(self) -> u32 {
        self.0 >> 22
    }

    #[inline]
    pub const fn minor(self) -> u32 {
        (self.0 >> 12) & 0x3fff
    }

    #[inline]
    pub const fn patch(self) -> u32 {
        self.0 & 0xfff
    }
}

impl fmt::Display for Version {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        write!(fmt, "{}.{}.{}", self.major(), self.minor(), self.patch())
    }
}


#[cfg(all(feature = "xlib", feature = "opengl"))]
mod xlib {
    use std::os::raw::{c_ulong, c_void};

    pub type XID = c_ulong;
    pub type GLXFBConfig = *mut c_void;
    pub type GLXDrawable = XID;
    pub type GLXContext = *mut c_void;
}
#[cfg(all(feature = "xlib", feature = "opengl"))]
pub use xlib::*;
#[cfg(feature = "xlib")]
pub type Display = std::os::raw::c_void;

// TODO: XCB, OpenGLES, D3D, windows

pub use generated::*;