use crate::protocol::ArgumentType;
use wayland_sys::common::{wl_argument, wl_array};
#[cfg(any(test, feature = "client_system"))]
mod client_impl;
#[cfg(any(test, feature = "server_system"))]
mod server_impl;
static RUST_MANAGED: u8 = 42;
unsafe fn free_arrays(signature: &[ArgumentType], arglist: &[wl_argument]) {
for (typ, arg) in signature.iter().zip(arglist.iter()) {
if let ArgumentType::Array = typ {
let _ = unsafe { Box::from_raw(arg.a as *mut wl_array) };
}
}
}
#[cfg(any(test, feature = "client_system"))]
#[path = "../client_api.rs"]
pub mod client;
#[cfg(any(test, feature = "client_system"))]
impl client::ObjectId {
pub unsafe fn from_ptr(
interface: &'static crate::protocol::Interface,
ptr: *mut wayland_sys::client::wl_proxy,
) -> Result<Self, client::InvalidId> {
Ok(Self { id: unsafe { client_impl::InnerObjectId::from_ptr(interface, ptr) }? })
}
pub fn as_ptr(&self) -> *mut wayland_sys::client::wl_proxy {
self.id.as_ptr()
}
}
#[cfg(any(test, feature = "client_system"))]
impl client::Backend {
pub unsafe fn from_foreign_display(display: *mut wayland_sys::client::wl_display) -> Self {
Self { backend: unsafe { client_impl::InnerBackend::from_foreign_display(display) } }
}
pub fn display_ptr(&self) -> *mut wayland_sys::client::wl_display {
self.backend.display_ptr()
}
}
#[cfg(feature = "raw-window-handle")]
unsafe impl raw_window_handle::HasRawDisplayHandle for client::Backend {
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
let mut handle = raw_window_handle::WaylandDisplayHandle::empty();
handle.display = self.display_ptr().cast();
raw_window_handle::RawDisplayHandle::Wayland(handle)
}
}
#[cfg(any(test, feature = "server_system"))]
#[path = "../server_api.rs"]
pub mod server;
#[cfg(any(test, feature = "server_system"))]
impl server::ObjectId {
pub unsafe fn from_ptr(
interface: &'static crate::protocol::Interface,
ptr: *mut wayland_sys::server::wl_resource,
) -> Result<Self, server::InvalidId> {
Ok(Self { id: unsafe { server_impl::InnerObjectId::from_ptr(Some(interface), ptr) }? })
}
pub fn as_ptr(&self) -> *mut wayland_sys::server::wl_resource {
self.id.as_ptr()
}
}
#[cfg(any(test, feature = "server_system"))]
impl server::Handle {
pub fn display_ptr(&self) -> *mut wayland_sys::server::wl_display {
self.handle.display_ptr()
}
}