get_registry/common/protocols_data/wayland/
wl_registry.rs1use super::super::all_types::*;
25use ::wl_client::builder::prelude::*;
26
27static INTERFACE: wl_interface = wl_interface {
28 name: c"wl_registry".as_ptr(),
29 version: 1,
30 method_count: 1,
31 methods: {
32 static MESSAGES: [wl_message; 1] = [wl_message {
33 name: c"bind".as_ptr(),
34 signature: c"usun".as_ptr(),
35 types: {
36 static TYPES: [Option<&'static wl_interface>; 4] = [None, None, None, None];
37 TYPES.as_ptr().cast()
38 },
39 }];
40 MESSAGES.as_ptr()
41 },
42 event_count: 2,
43 events: {
44 static MESSAGES: [wl_message; 2] = [
45 wl_message {
46 name: c"global".as_ptr(),
47 signature: c"usu".as_ptr(),
48 types: {
49 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
50 TYPES.as_ptr().cast()
51 },
52 },
53 wl_message {
54 name: c"global_remove".as_ptr(),
55 signature: c"u".as_ptr(),
56 types: {
57 static TYPES: [Option<&'static wl_interface>; 1] = [None];
58 TYPES.as_ptr().cast()
59 },
60 },
61 ];
62 MESSAGES.as_ptr()
63 },
64};
65
66#[derive(Clone, Eq, PartialEq)]
70#[repr(transparent)]
71pub struct WlRegistry {
72 proxy: UntypedOwnedProxy,
74}
75
76#[derive(Eq, PartialEq)]
80#[repr(transparent)]
81pub struct WlRegistryRef {
82 proxy: UntypedBorrowedProxy,
84}
85
86unsafe impl UntypedOwnedProxyWrapper for WlRegistry {}
88
89unsafe impl OwnedProxy for WlRegistry {
92 const INTERFACE: &'static str = "wl_registry";
93 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
94 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
95 private::EventHandler(private::NoOpEventHandler);
96 const MAX_VERSION: u32 = 1;
97
98 type Borrowed = WlRegistryRef;
99 type Api = private::ProxyApi;
100 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
101}
102
103unsafe impl UntypedBorrowedProxyWrapper for WlRegistryRef {}
105
106unsafe impl BorrowedProxy for WlRegistryRef {
108 type Owned = WlRegistry;
109}
110
111impl Deref for WlRegistry {
112 type Target = WlRegistryRef;
113
114 fn deref(&self) -> &Self::Target {
115 proxy::low_level::deref(self)
116 }
117}
118
119mod private {
120 pub struct ProxyApi;
121
122 #[allow(dead_code)]
123 pub struct EventHandler<H>(pub(super) H);
124
125 #[allow(dead_code)]
126 pub struct NoOpEventHandler;
127}
128
129impl Debug for WlRegistry {
130 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
131 write!(f, "wl_registry#{}", self.proxy.id())
132 }
133}
134
135impl Debug for WlRegistryRef {
136 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
137 write!(f, "wl_registry#{}", self.proxy.id())
138 }
139}
140
141impl PartialEq<WlRegistryRef> for WlRegistry {
142 fn eq(&self, other: &WlRegistryRef) -> bool {
143 self.proxy == other.proxy
144 }
145}
146
147impl PartialEq<WlRegistry> for WlRegistryRef {
148 fn eq(&self, other: &WlRegistry) -> bool {
149 self.proxy == other.proxy
150 }
151}
152
153#[allow(dead_code)]
154impl WlRegistry {
155 #[allow(dead_code)]
157 pub const REQ__BIND__SINCE: u32 = 1;
158}
159
160#[allow(dead_code)]
161impl WlRegistry {
162 #[inline]
171 pub fn bind<P: OwnedProxy>(&self, name: u32, version: u32) -> P {
172 let (arg0, arg1) = (name, version);
173 let mut args = [
174 wl_argument { u: arg0 },
175 wl_argument {
176 s: P::WL_INTERFACE.name,
177 },
178 wl_argument { u: arg1 },
179 wl_argument { n: 0 },
180 ];
181 let data = unsafe {
186 self.proxy
187 .send_constructor::<false>(0, &mut args, P::WL_INTERFACE, Some(version))
188 };
189 unsafe { proxy::low_level::from_untyped_owned(data) }
191 }
192}
193
194#[allow(dead_code)]
195impl WlRegistryRef {
196 #[inline]
206 pub fn bind<P: OwnedProxy>(&self, _queue: &Queue, name: u32, version: u32) -> P {
207 let (arg0, arg1) = (name, version);
208 let mut args = [
209 wl_argument { u: arg0 },
210 wl_argument {
211 s: P::WL_INTERFACE.name,
212 },
213 wl_argument { u: arg1 },
214 wl_argument { n: 0 },
215 ];
216 let data = unsafe {
221 self.proxy
222 .send_constructor(_queue, 0, &mut args, P::WL_INTERFACE, Some(version))
223 };
224 unsafe { proxy::low_level::from_untyped_owned(data) }
226 }
227}
228
229impl WlRegistry {
230 #[allow(dead_code)]
232 pub const EVT__GLOBAL__SINCE: u32 = 1;
233
234 #[allow(dead_code)]
236 pub const EVT__GLOBAL_REMOVE__SINCE: u32 = 1;
237}
238
239#[allow(dead_code)]
241pub trait WlRegistryEventHandler {
242 type Data: 'static;
243
244 #[inline]
258 fn global(
259 &self,
260 _data: &mut Self::Data,
261 _slf: &WlRegistryRef,
262 name: u32,
263 interface: &str,
264 version: u32,
265 ) {
266 let _ = name;
267 let _ = interface;
268 let _ = version;
269 }
270
271 #[inline]
288 fn global_remove(&self, _data: &mut Self::Data, _slf: &WlRegistryRef, name: u32) {
289 let _ = name;
290 }
291}
292
293impl WlRegistryEventHandler for private::NoOpEventHandler {
294 type Data = ();
295}
296
297unsafe impl<H> EventHandler for private::EventHandler<H>
300where
301 H: WlRegistryEventHandler,
302{
303 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
304
305 #[inline]
306 fn mutable_type() -> Option<(TypeId, &'static str)> {
307 let id = TypeId::of::<H::Data>();
308 let name = std::any::type_name::<H::Data>();
309 Some((id, name))
310 }
311
312 #[allow(unused_variables)]
313 unsafe fn handle_event(
314 &self,
315 queue: &Queue,
316 data: *mut u8,
317 slf: &UntypedBorrowedProxy,
318 opcode: u32,
319 args: *mut wl_argument,
320 ) {
321 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlRegistryRef>(slf) };
323 let data: &mut H::Data = unsafe { &mut *data.cast() };
327 match opcode {
328 0 => {
329 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
331 let arg0 = unsafe { args[0].u };
333 let arg1 = unsafe { convert_string_arg("wl_registry", "interface", args[1].s) };
336 let arg2 = unsafe { args[2].u };
338 self.0.global(data, slf, arg0, arg1, arg2);
339 }
340 1 => {
341 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
343 let arg0 = unsafe { args[0].u };
345 self.0.global_remove(data, slf, arg0);
346 }
347 _ => {
348 invalid_opcode("wl_registry", opcode);
349 }
350 }
351 }
352}
353
354impl<H> CreateEventHandler<H> for private::ProxyApi
355where
356 H: WlRegistryEventHandler,
357{
358 type EventHandler = private::EventHandler<H>;
359
360 #[inline]
361 fn create_event_handler(handler: H) -> Self::EventHandler {
362 private::EventHandler(handler)
363 }
364}
365
366pub mod event_handlers {
368 use super::*;
369
370 pub struct Global<T, F>(F, PhantomData<fn(&mut T)>);
372 impl<T, F> WlRegistryEventHandler for Global<T, F>
373 where
374 T: 'static,
375 F: Fn(&mut T, &WlRegistryRef, u32, &str, u32),
376 {
377 type Data = T;
378
379 #[inline]
380 fn global(
381 &self,
382 _data: &mut T,
383 _slf: &WlRegistryRef,
384 name: u32,
385 interface: &str,
386 version: u32,
387 ) {
388 self.0(_data, _slf, name, interface, version)
389 }
390 }
391
392 pub struct GlobalRemove<T, F>(F, PhantomData<fn(&mut T)>);
394 impl<T, F> WlRegistryEventHandler for GlobalRemove<T, F>
395 where
396 T: 'static,
397 F: Fn(&mut T, &WlRegistryRef, u32),
398 {
399 type Data = T;
400
401 #[inline]
402 fn global_remove(&self, _data: &mut T, _slf: &WlRegistryRef, name: u32) {
403 self.0(_data, _slf, name)
404 }
405 }
406
407 impl WlRegistry {
408 #[allow(dead_code)]
412 pub fn on_global<T, F>(f: F) -> Global<T, F>
413 where
414 T: 'static,
415 F: Fn(&mut T, &WlRegistryRef, u32, &str, u32),
416 {
417 Global(f, PhantomData)
418 }
419
420 #[allow(dead_code)]
424 pub fn on_global_remove<T, F>(f: F) -> GlobalRemove<T, F>
425 where
426 T: 'static,
427 F: Fn(&mut T, &WlRegistryRef, u32),
428 {
429 GlobalRemove(f, PhantomData)
430 }
431 }
432}