get_registry/common/protocols_data/wayland/
wl_callback.rs1use super::super::all_types::*;
10use ::wl_client::builder::prelude::*;
11
12static INTERFACE: wl_interface = wl_interface {
13 name: c"wl_callback".as_ptr(),
14 version: 1,
15 method_count: 0,
16 methods: ptr::null(),
17 event_count: 1,
18 events: {
19 static MESSAGES: [wl_message; 1] = [wl_message {
20 name: c"done".as_ptr(),
21 signature: c"u".as_ptr(),
22 types: {
23 static TYPES: [Option<&'static wl_interface>; 1] = [None];
24 TYPES.as_ptr().cast()
25 },
26 }];
27 MESSAGES.as_ptr()
28 },
29};
30
31#[derive(Clone, Eq, PartialEq)]
35#[repr(transparent)]
36pub struct WlCallback {
37 proxy: UntypedOwnedProxy,
39}
40
41#[derive(Eq, PartialEq)]
45#[repr(transparent)]
46pub struct WlCallbackRef {
47 proxy: UntypedBorrowedProxy,
49}
50
51unsafe impl UntypedOwnedProxyWrapper for WlCallback {}
53
54unsafe impl OwnedProxy for WlCallback {
57 const INTERFACE: &'static str = "wl_callback";
58 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
59 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
60 private::EventHandler(private::NoOpEventHandler);
61 const MAX_VERSION: u32 = 1;
62
63 type Borrowed = WlCallbackRef;
64 type Api = private::ProxyApi;
65 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
66}
67
68unsafe impl UntypedBorrowedProxyWrapper for WlCallbackRef {}
70
71unsafe impl BorrowedProxy for WlCallbackRef {
73 type Owned = WlCallback;
74}
75
76impl Deref for WlCallback {
77 type Target = WlCallbackRef;
78
79 fn deref(&self) -> &Self::Target {
80 proxy::low_level::deref(self)
81 }
82}
83
84mod private {
85 pub struct ProxyApi;
86
87 #[allow(dead_code)]
88 pub struct EventHandler<H>(pub(super) H);
89
90 #[allow(dead_code)]
91 pub struct NoOpEventHandler;
92}
93
94impl Debug for WlCallback {
95 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
96 write!(f, "wl_callback#{}", self.proxy.id())
97 }
98}
99
100impl Debug for WlCallbackRef {
101 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
102 write!(f, "wl_callback#{}", self.proxy.id())
103 }
104}
105
106impl PartialEq<WlCallbackRef> for WlCallback {
107 fn eq(&self, other: &WlCallbackRef) -> bool {
108 self.proxy == other.proxy
109 }
110}
111
112impl PartialEq<WlCallback> for WlCallbackRef {
113 fn eq(&self, other: &WlCallback) -> bool {
114 self.proxy == other.proxy
115 }
116}
117
118impl WlCallback {
119 #[allow(dead_code)]
121 pub const EVT__DONE__SINCE: u32 = 1;
122}
123
124#[allow(dead_code)]
126pub trait WlCallbackEventHandler {
127 type Data: 'static;
128
129 #[inline]
137 fn done(&self, _data: &mut Self::Data, _slf: &WlCallbackRef, callback_data: u32) {
138 let _ = callback_data;
139 }
140}
141
142impl WlCallbackEventHandler for private::NoOpEventHandler {
143 type Data = ();
144}
145
146unsafe impl<H> EventHandler for private::EventHandler<H>
149where
150 H: WlCallbackEventHandler,
151{
152 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
153
154 #[inline]
155 fn mutable_type() -> Option<(TypeId, &'static str)> {
156 let id = TypeId::of::<H::Data>();
157 let name = std::any::type_name::<H::Data>();
158 Some((id, name))
159 }
160
161 #[allow(unused_variables)]
162 unsafe fn handle_event(
163 &self,
164 queue: &Queue,
165 data: *mut u8,
166 slf: &UntypedBorrowedProxy,
167 opcode: u32,
168 args: *mut wl_argument,
169 ) {
170 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlCallbackRef>(slf) };
172 let data: &mut H::Data = unsafe { &mut *data.cast() };
176 match opcode {
177 0 => {
178 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
180 let arg0 = unsafe { args[0].u };
182 self.0.done(data, slf, arg0);
183 }
184 _ => {
185 invalid_opcode("wl_callback", opcode);
186 }
187 }
188 }
189}
190
191impl<H> CreateEventHandler<H> for private::ProxyApi
192where
193 H: WlCallbackEventHandler,
194{
195 type EventHandler = private::EventHandler<H>;
196
197 #[inline]
198 fn create_event_handler(handler: H) -> Self::EventHandler {
199 private::EventHandler(handler)
200 }
201}
202
203pub mod event_handlers {
205 use super::*;
206
207 pub struct Done<T, F>(F, PhantomData<fn(&mut T)>);
209 impl<T, F> WlCallbackEventHandler for Done<T, F>
210 where
211 T: 'static,
212 F: Fn(&mut T, &WlCallbackRef, u32),
213 {
214 type Data = T;
215
216 #[inline]
217 fn done(&self, _data: &mut T, _slf: &WlCallbackRef, callback_data: u32) {
218 self.0(_data, _slf, callback_data)
219 }
220 }
221
222 impl WlCallback {
223 #[allow(dead_code)]
227 pub fn on_done<T, F>(f: F) -> Done<T, F>
228 where
229 T: 'static,
230 F: Fn(&mut T, &WlCallbackRef, u32),
231 {
232 Done(f, PhantomData)
233 }
234 }
235}