use {Geometry, Output, Size, View, WeakOutput, WeakView};
use ffi;
use std::mem;
use std::slice;
use wayland_server::Resource;
use wayland_server::protocol::wl_output::WlOutput;
use wayland_server::protocol::wl_surface::WlSurface;
#[allow(missing_docs)]
pub mod sys {
pub use ffi::wlc_get_wl_display;
pub use ffi::wlc_view_from_surface;
pub use ffi::wlc_view_get_role;
}
pub fn view_from_wl_surface(surface: &WlSurface) -> WeakView {
let view: &View =
unsafe { &*(ffi::wlc_handle_from_wl_surface_resource(surface.ptr() as *mut _) as *const View) };
view.weak_reference()
}
pub fn output_from_wl_surface(output: &WlOutput) -> WeakOutput {
let output: &Output =
unsafe { &*(ffi::wlc_handle_from_wl_output_resource(output.ptr() as *mut _) as *const Output) };
output.weak_reference()
}
#[repr(C)]
#[derive(Clone, Debug)]
pub struct WlcSurface;
#[cfg(not(feature = "unsafe-stable"))]
impl !Sync for WlcSurface {}
#[cfg(not(feature = "unsafe-stable"))]
impl !Send for WlcSurface {}
pub fn wlc_resource_from_wl_surface(surface: &WlSurface) -> &WlcSurface {
unsafe { &*(ffi::wlc_resource_from_wl_surface_resource(surface.ptr() as *mut _) as *const WlcSurface) }
}
impl WlcSurface {
pub fn size(&self) -> Size {
unsafe { Size::from_ffi(&*ffi::wlc_surface_get_size(handle(self))) }
}
pub fn wl_surface(&self) -> WlSurface {
unsafe { WlSurface::from_ptr_new(ffi::wlc_surface_get_wl_resource(handle(self)) as *mut _) }
}
pub fn sub_surfaces(&self) -> &[&WlcSubSurface] {
unsafe {
let mut size = 0;
let ptr = ffi::wlc_surface_get_subsurfaces(handle(self), &mut size as *mut _) as *const _;
slice::from_raw_parts(ptr, size)
}
}
#[cfg(feature = "render")]
pub fn flush_frame_callbacks(&self) {
unsafe { ffi::wlc_surface_flush_frame_callbacks(handle(self)) }
}
}
fn handle(surface: &WlcSurface) -> ffi::wlc_resource {
unsafe { mem::transmute(surface) }
}
#[repr(C)]
pub struct WlcSubSurface;
#[cfg(not(feature = "unsafe-stable"))]
impl !Sync for WlcSubSurface {}
#[cfg(not(feature = "unsafe-stable"))]
impl !Send for WlcSubSurface {}
impl WlcSubSurface {
pub fn geometry(&self) -> Geometry {
unsafe {
let mut geo: ffi::wlc_geometry = mem::uninitialized();
ffi::wlc_get_subsurface_geometry(mem::transmute(self), &mut geo as *mut _);
Geometry::from_ffi(&geo)
}
}
}