#![deny(missing_docs)]
pub mod ffi {
pub use input_sys::*;
}
pub trait AsRaw<T> {
fn as_raw(&self) -> *const T;
#[doc(hidden)]
fn as_raw_mut(&self) -> *mut T {
self.as_raw() as *mut _
}
}
pub trait Context {
fn context(&self) -> &Libinput;
}
pub trait FromRaw<T> {
#[doc(hidden)]
unsafe fn try_from_raw(ffi: *mut T, context: &context::Libinput) -> Option<Self>
where
Self: Sized;
unsafe fn from_raw(ffi: *mut T, context: &context::Libinput) -> Self;
}
macro_rules! ffi_ref_struct {
($(#[$attr:meta])* struct $struct_name:ident, $ffi_name:path, $ref_fn:path, $unref_fn:path) => (
#[derive(Eq)]
$(#[$attr])*
pub struct $struct_name
{
ffi: *mut $ffi_name,
context: $crate::context::Libinput,
}
impl ::std::fmt::Debug for $struct_name {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "{} @{:p}", stringify!($struct_name), self.as_raw())
}
}
impl $crate::FromRaw<$ffi_name> for $struct_name
{
unsafe fn try_from_raw(ffi: *mut $ffi_name, context: &$crate::Libinput) -> Option<Self> {
Some(Self::from_raw(ffi, context))
}
unsafe fn from_raw(ffi: *mut $ffi_name, context: &$crate::Libinput) -> Self {
$struct_name {
ffi: $ref_fn(ffi),
context: context.clone(),
}
}
}
impl $crate::AsRaw<$ffi_name> for $struct_name
{
fn as_raw(&self) -> *const $ffi_name {
self.ffi as *const _
}
}
impl $crate::Context for $struct_name
{
fn context(&self) -> &$crate::Libinput {
&self.context
}
}
impl Clone for $struct_name {
fn clone(&self) -> Self {
unsafe { $struct_name::from_raw(self.as_raw_mut(), &self.context) }
}
}
impl Drop for $struct_name
{
fn drop(&mut self) {
unsafe {
$unref_fn(self.ffi);
}
}
}
impl PartialEq for $struct_name {
fn eq(&self, other: &Self) -> bool {
self.as_raw() == other.as_raw()
}
}
impl ::std::hash::Hash for $struct_name {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
self.as_raw().hash(state);
}
}
)
}
macro_rules! ffi_func {
($(#[$attr:meta])* fn $name:ident, $ffi_fn:path, bool) => (
$(#[$attr])*
fn $name(&self) -> bool {
unsafe { $ffi_fn(self.as_raw_mut()) != 0 }
}
);
($(#[$attr:meta])* pub fn $name:ident, $ffi_fn:path, bool) => (
$(#[$attr])*
pub fn $name(&self) -> bool {
unsafe { $ffi_fn(self.as_raw_mut()) != 0 }
}
);
($(#[$attr:meta])* fn $name:ident, $ffi_fn:path, $return_type:ty) => (
$(#[$attr])*
fn $name(&self) -> $return_type {
unsafe { $ffi_fn(self.as_raw_mut()) as $return_type }
}
);
($(#[$attr:meta])* pub fn $name:ident, $ffi_fn:path, $return_type:ty) => (
$(#[$attr])*
pub fn $name(&self) -> $return_type {
unsafe { $ffi_fn(self.as_raw_mut()) as $return_type }
}
);
}
mod context;
mod device;
pub mod event;
mod seat;
pub use context::*;
pub use device::*;
pub use event::Event;
pub use seat::*;
#[cfg(feature = "libinput_1_23")]
mod accel_config;
#[cfg(feature = "libinput_1_23")]
pub use accel_config::*;