get_registry/common/protocols/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 #[inline]
135 fn done(&self, _slf: &WlCallbackRef, callback_data: u32) {
136 let _ = callback_data;
137 }
138}
139
140impl WlCallbackEventHandler for private::NoOpEventHandler {}
141
142unsafe impl<H> EventHandler for private::EventHandler<H>
144where
145 H: WlCallbackEventHandler,
146{
147 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
148
149 #[allow(unused_variables)]
150 unsafe fn handle_event(
151 &self,
152 queue: &Queue,
153 data: *mut u8,
154 slf: &UntypedBorrowedProxy,
155 opcode: u32,
156 args: *mut wl_argument,
157 ) {
158 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlCallbackRef>(slf) };
160 match opcode {
161 0 => {
162 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
164 let arg0 = unsafe { args[0].u };
166 self.0.done(slf, arg0);
167 }
168 _ => {
169 invalid_opcode("wl_callback", opcode);
170 }
171 }
172 }
173}
174
175impl<H> CreateEventHandler<H> for private::ProxyApi
176where
177 H: WlCallbackEventHandler,
178{
179 type EventHandler = private::EventHandler<H>;
180
181 #[inline]
182 fn create_event_handler(handler: H) -> Self::EventHandler {
183 private::EventHandler(handler)
184 }
185}
186
187pub mod event_handlers {
189 use super::*;
190
191 pub struct Done<F>(F);
193 impl<F> WlCallbackEventHandler for Done<F>
194 where
195 F: Fn(&WlCallbackRef, u32),
196 {
197 #[inline]
198 fn done(&self, _slf: &WlCallbackRef, callback_data: u32) {
199 self.0(_slf, callback_data)
200 }
201 }
202
203 impl WlCallback {
204 #[allow(dead_code)]
208 pub fn on_done<F>(f: F) -> Done<F>
209 where
210 F: Fn(&WlCallbackRef, u32),
211 {
212 Done(f)
213 }
214 }
215}