use std::sync::Arc;
use wayland_sys::client::wl_proxy;
use wayland_sys::common::{wl_argument, wl_array};
use crate::protocol::{ArgumentType, Interface};
#[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"))]
use client::{ObjectData, ObjectId};
#[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()
}
#[inline]
pub unsafe fn manage_object(
&self,
interface: &'static Interface,
proxy: *mut wl_proxy,
data: Arc<dyn ObjectData>,
) -> ObjectId {
unsafe { self.backend.manage_object(interface, proxy, data) }
}
}
#[cfg(any(test, feature = "client_system"))]
impl client::ReadEventsGuard {
pub fn read_without_dispatch(mut self) -> Result<(), client::WaylandError> {
self.guard.read_non_dispatch()
}
}
#[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(all(feature = "rwh_06", feature = "client_system"))]
impl rwh_06::HasDisplayHandle for client::Backend {
fn display_handle(&self) -> Result<rwh_06::DisplayHandle<'_>, rwh_06::HandleError> {
use std::ptr::NonNull;
let ptr = unsafe { NonNull::new_unchecked(self.display_ptr().cast()) };
let handle = rwh_06::WaylandDisplayHandle::new(ptr);
let raw = rwh_06::RawDisplayHandle::Wayland(handle);
Ok(unsafe { rwh_06::DisplayHandle::borrow_raw(raw) })
}
}
#[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()
}
}