use {super::super::all_types::*, crate::builder::prelude::*};
static INTERFACE: wl_interface = wl_interface {
name: c"wl_display".as_ptr(),
version: 1,
method_count: 2,
methods: {
static MESSAGES: [wl_message; 2] = [
wl_message {
name: c"sync".as_ptr(),
signature: c"n".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 1] =
[Some(WlCallback::WL_INTERFACE)];
TYPES.as_ptr().cast()
},
},
wl_message {
name: c"get_registry".as_ptr(),
signature: c"n".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 1] =
[Some(WlRegistry::WL_INTERFACE)];
TYPES.as_ptr().cast()
},
},
];
MESSAGES.as_ptr()
},
event_count: 2,
events: {
static MESSAGES: [wl_message; 2] = [
wl_message {
name: c"error".as_ptr(),
signature: c"ous".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
TYPES.as_ptr().cast()
},
},
wl_message {
name: c"delete_id".as_ptr(),
signature: c"u".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 1] = [None];
TYPES.as_ptr().cast()
},
},
];
MESSAGES.as_ptr()
},
};
#[derive(Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct WlDisplay {
proxy: UntypedOwnedProxy,
}
#[derive(Eq, PartialEq)]
#[repr(transparent)]
pub struct WlDisplayRef {
proxy: UntypedBorrowedProxy,
}
unsafe impl UntypedOwnedProxyWrapper for WlDisplay {}
unsafe impl OwnedProxy for WlDisplay {
const INTERFACE: &'static str = "wl_display";
const WL_INTERFACE: &'static wl_interface = &INTERFACE;
const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
private::EventHandler(private::NoOpEventHandler);
const MAX_VERSION: u32 = 1;
type Borrowed = WlDisplayRef;
type Api = private::ProxyApi;
type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
}
unsafe impl UntypedBorrowedProxyWrapper for WlDisplayRef {}
unsafe impl BorrowedProxy for WlDisplayRef {
type Owned = WlDisplay;
}
impl Deref for WlDisplay {
type Target = WlDisplayRef;
fn deref(&self) -> &Self::Target {
proxy::low_level::deref(self)
}
}
mod private {
pub struct ProxyApi;
#[allow(dead_code)]
pub struct EventHandler<H>(pub(super) H);
#[allow(dead_code)]
pub struct NoOpEventHandler;
}
impl Debug for WlDisplay {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "wl_display#{}", self.proxy.id())
}
}
impl Debug for WlDisplayRef {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "wl_display#{}", self.proxy.id())
}
}
impl PartialEq<WlDisplayRef> for WlDisplay {
fn eq(&self, other: &WlDisplayRef) -> bool {
self.proxy == other.proxy
}
}
impl PartialEq<WlDisplay> for WlDisplayRef {
fn eq(&self, other: &WlDisplay) -> bool {
self.proxy == other.proxy
}
}
#[allow(dead_code)]
impl WlDisplay {
#[allow(dead_code)]
pub const REQ__SYNC__SINCE: u32 = 1;
#[inline]
pub fn sync(&self) -> WlCallback {
let mut args = [wl_argument { n: 0 }];
let data = unsafe {
self.proxy
.send_constructor::<false>(0, &mut args, WlCallback::WL_INTERFACE, None)
};
unsafe { proxy::low_level::from_untyped_owned(data) }
}
#[allow(dead_code)]
pub const REQ__GET_REGISTRY__SINCE: u32 = 1;
#[inline]
pub fn get_registry(&self) -> WlRegistry {
let mut args = [wl_argument { n: 0 }];
let data = unsafe {
self.proxy
.send_constructor::<false>(1, &mut args, WlRegistry::WL_INTERFACE, None)
};
unsafe { proxy::low_level::from_untyped_owned(data) }
}
}
#[allow(dead_code)]
impl WlDisplayRef {
#[inline]
pub fn sync(&self, _queue: &Queue) -> WlCallback {
let mut args = [wl_argument { n: 0 }];
let data = unsafe {
self.proxy
.send_constructor(_queue, 0, &mut args, WlCallback::WL_INTERFACE, None)
};
unsafe { proxy::low_level::from_untyped_owned(data) }
}
#[inline]
pub fn get_registry(&self, _queue: &Queue) -> WlRegistry {
let mut args = [wl_argument { n: 0 }];
let data = unsafe {
self.proxy
.send_constructor(_queue, 1, &mut args, WlRegistry::WL_INTERFACE, None)
};
unsafe { proxy::low_level::from_untyped_owned(data) }
}
}
impl WlDisplay {
#[allow(dead_code)]
pub const EVT__ERROR__SINCE: u32 = 1;
#[allow(dead_code)]
pub const EVT__DELETE_ID__SINCE: u32 = 1;
}
#[allow(dead_code)]
pub trait WlDisplayEventHandler {
type Data: 'static;
#[inline]
fn error(
&self,
_data: &mut Self::Data,
_slf: &WlDisplayRef,
object_id: Option<&UntypedBorrowedProxy>,
code: u32,
message: &str,
) {
let _ = object_id;
let _ = code;
let _ = message;
}
#[inline]
fn delete_id(&self, _data: &mut Self::Data, _slf: &WlDisplayRef, id: u32) {
let _ = id;
}
}
impl WlDisplayEventHandler for private::NoOpEventHandler {
type Data = ();
}
unsafe impl<H> EventHandler for private::EventHandler<H>
where
H: WlDisplayEventHandler,
{
const WL_INTERFACE: &'static wl_interface = &INTERFACE;
#[inline]
fn mutable_type() -> Option<(TypeId, &'static str)> {
let id = TypeId::of::<H::Data>();
let name = std::any::type_name::<H::Data>();
Some((id, name))
}
#[allow(unused_variables)]
unsafe fn handle_event(
&self,
queue: &Queue,
data: *mut u8,
slf: &UntypedBorrowedProxy,
opcode: u32,
args: *mut wl_argument,
) {
let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlDisplayRef>(slf) };
let data: &mut H::Data = unsafe { &mut *data.cast() };
match opcode {
0 => {
let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
let arg0 = unsafe {
if let Some(p) = NonNull::new(args[0].o.cast()) {
Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
} else {
None
}
};
let arg0 = arg0.as_ref();
let arg1 = unsafe { args[1].u };
let arg2 = unsafe { convert_string_arg("wl_display", "message", args[2].s) };
self.0.error(data, slf, arg0, arg1, arg2);
}
1 => {
let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
let arg0 = unsafe { args[0].u };
self.0.delete_id(data, slf, arg0);
}
_ => {
invalid_opcode("wl_display", opcode);
}
}
}
}
impl<H> CreateEventHandler<H> for private::ProxyApi
where
H: WlDisplayEventHandler,
{
type EventHandler = private::EventHandler<H>;
#[inline]
fn create_event_handler(handler: H) -> Self::EventHandler {
private::EventHandler(handler)
}
}
pub mod event_handlers {
use super::*;
pub struct Error<T, F>(F, PhantomData<fn(&mut T)>);
impl<T, F> WlDisplayEventHandler for Error<T, F>
where
T: 'static,
F: Fn(&mut T, &WlDisplayRef, Option<&UntypedBorrowedProxy>, u32, &str),
{
type Data = T;
#[inline]
fn error(
&self,
_data: &mut T,
_slf: &WlDisplayRef,
object_id: Option<&UntypedBorrowedProxy>,
code: u32,
message: &str,
) {
self.0(_data, _slf, object_id, code, message)
}
}
pub struct DeleteId<T, F>(F, PhantomData<fn(&mut T)>);
impl<T, F> WlDisplayEventHandler for DeleteId<T, F>
where
T: 'static,
F: Fn(&mut T, &WlDisplayRef, u32),
{
type Data = T;
#[inline]
fn delete_id(&self, _data: &mut T, _slf: &WlDisplayRef, id: u32) {
self.0(_data, _slf, id)
}
}
impl WlDisplay {
#[allow(dead_code)]
pub fn on_error<T, F>(f: F) -> Error<T, F>
where
T: 'static,
F: Fn(&mut T, &WlDisplayRef, Option<&UntypedBorrowedProxy>, u32, &str),
{
Error(f, PhantomData)
}
#[allow(dead_code)]
pub fn on_delete_id<T, F>(f: F) -> DeleteId<T, F>
where
T: 'static,
F: Fn(&mut T, &WlDisplayRef, u32),
{
DeleteId(f, PhantomData)
}
}
}