use {super::super::all_types::*, crate::builder::prelude::*};
static INTERFACE: wl_interface = wl_interface {
name: c"wl_callback".as_ptr(),
version: 1,
method_count: 0,
methods: ptr::null(),
event_count: 1,
events: {
static MESSAGES: [wl_message; 1] = [wl_message {
name: c"done".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 WlCallback {
proxy: UntypedOwnedProxy,
}
#[derive(Eq, PartialEq)]
#[repr(transparent)]
pub struct WlCallbackRef {
proxy: UntypedBorrowedProxy,
}
unsafe impl UntypedOwnedProxyWrapper for WlCallback {}
unsafe impl OwnedProxy for WlCallback {
const INTERFACE: &'static str = "wl_callback";
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 = WlCallbackRef;
type Api = private::ProxyApi;
type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
}
unsafe impl UntypedBorrowedProxyWrapper for WlCallbackRef {}
unsafe impl BorrowedProxy for WlCallbackRef {
type Owned = WlCallback;
}
impl Deref for WlCallback {
type Target = WlCallbackRef;
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 WlCallback {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "wl_callback#{}", self.proxy.id())
}
}
impl Debug for WlCallbackRef {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "wl_callback#{}", self.proxy.id())
}
}
impl PartialEq<WlCallbackRef> for WlCallback {
fn eq(&self, other: &WlCallbackRef) -> bool {
self.proxy == other.proxy
}
}
impl PartialEq<WlCallback> for WlCallbackRef {
fn eq(&self, other: &WlCallback) -> bool {
self.proxy == other.proxy
}
}
impl WlCallback {
#[allow(dead_code)]
pub const EVT__DONE__SINCE: u32 = 1;
}
#[allow(dead_code)]
pub trait WlCallbackEventHandler {
type Data: 'static;
#[inline]
fn done(&self, _data: &mut Self::Data, _slf: &WlCallbackRef, callback_data: u32) {
let _ = callback_data;
}
}
impl WlCallbackEventHandler for private::NoOpEventHandler {
type Data = ();
}
unsafe impl<H> EventHandler for private::EventHandler<H>
where
H: WlCallbackEventHandler,
{
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::<WlCallbackRef>(slf) };
let data: &mut H::Data = unsafe { &mut *data.cast() };
match opcode {
0 => {
let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
let arg0 = unsafe { args[0].u };
self.0.done(data, slf, arg0);
}
_ => {
invalid_opcode("wl_callback", opcode);
}
}
}
}
impl<H> CreateEventHandler<H> for private::ProxyApi
where
H: WlCallbackEventHandler,
{
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 Done<T, F>(F, PhantomData<fn(&mut T)>);
impl<T, F> WlCallbackEventHandler for Done<T, F>
where
T: 'static,
F: Fn(&mut T, &WlCallbackRef, u32),
{
type Data = T;
#[inline]
fn done(&self, _data: &mut T, _slf: &WlCallbackRef, callback_data: u32) {
self.0(_data, _slf, callback_data)
}
}
impl WlCallback {
#[allow(dead_code)]
pub fn on_done<T, F>(f: F) -> Done<T, F>
where
T: 'static,
F: Fn(&mut T, &WlCallbackRef, u32),
{
Done(f, PhantomData)
}
}
}