wl_client/test_protocols/core/
wl_registry.rs1use {super::super::all_types::*, crate::builder::prelude::*};
2
3static INTERFACE: wl_interface = wl_interface {
4 name: c"wl_registry".as_ptr(),
5 version: 1,
6 method_count: 1,
7 methods: {
8 static MESSAGES: [wl_message; 1] = [wl_message {
9 name: c"bind".as_ptr(),
10 signature: c"usun".as_ptr(),
11 types: {
12 static TYPES: [Option<&'static wl_interface>; 4] = [None, None, None, None];
13 TYPES.as_ptr().cast()
14 },
15 }];
16 MESSAGES.as_ptr()
17 },
18 event_count: 2,
19 events: {
20 static MESSAGES: [wl_message; 2] = [
21 wl_message {
22 name: c"global".as_ptr(),
23 signature: c"usu".as_ptr(),
24 types: {
25 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
26 TYPES.as_ptr().cast()
27 },
28 },
29 wl_message {
30 name: c"global_remove".as_ptr(),
31 signature: c"u".as_ptr(),
32 types: {
33 static TYPES: [Option<&'static wl_interface>; 1] = [None];
34 TYPES.as_ptr().cast()
35 },
36 },
37 ];
38 MESSAGES.as_ptr()
39 },
40};
41
42#[derive(Clone, Eq, PartialEq)]
46#[repr(transparent)]
47pub struct WlRegistry {
48 proxy: UntypedOwnedProxy,
50}
51
52#[derive(Eq, PartialEq)]
56#[repr(transparent)]
57pub struct WlRegistryRef {
58 proxy: UntypedBorrowedProxy,
60}
61
62unsafe impl UntypedOwnedProxyWrapper for WlRegistry {}
64
65unsafe impl OwnedProxy for WlRegistry {
68 const INTERFACE: &'static str = "wl_registry";
69 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
70 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
71 private::EventHandler(private::NoOpEventHandler);
72 const MAX_VERSION: u32 = 1;
73
74 type Borrowed = WlRegistryRef;
75 type Api = private::ProxyApi;
76 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
77}
78
79unsafe impl UntypedBorrowedProxyWrapper for WlRegistryRef {}
81
82unsafe impl BorrowedProxy for WlRegistryRef {
84 type Owned = WlRegistry;
85}
86
87impl Deref for WlRegistry {
88 type Target = WlRegistryRef;
89
90 fn deref(&self) -> &Self::Target {
91 proxy::low_level::deref(self)
92 }
93}
94
95mod private {
96 pub struct ProxyApi;
97
98 #[allow(dead_code)]
99 pub struct EventHandler<H>(pub(super) H);
100
101 #[allow(dead_code)]
102 pub struct NoOpEventHandler;
103}
104
105impl Debug for WlRegistry {
106 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
107 write!(f, "wl_registry#{}", self.proxy.id())
108 }
109}
110
111impl Debug for WlRegistryRef {
112 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
113 write!(f, "wl_registry#{}", self.proxy.id())
114 }
115}
116
117impl PartialEq<WlRegistryRef> for WlRegistry {
118 fn eq(&self, other: &WlRegistryRef) -> bool {
119 self.proxy == other.proxy
120 }
121}
122
123impl PartialEq<WlRegistry> for WlRegistryRef {
124 fn eq(&self, other: &WlRegistry) -> bool {
125 self.proxy == other.proxy
126 }
127}
128
129#[allow(dead_code)]
130impl WlRegistry {
131 #[allow(dead_code)]
133 pub const REQ__BIND__SINCE: u32 = 1;
134
135 #[inline]
139 pub fn bind<P: OwnedProxy>(&self, name: u32, version: u32) -> P {
140 let (arg0, arg1) = (name, version);
141 let mut args = [
142 wl_argument { u: arg0 },
143 wl_argument {
144 s: P::WL_INTERFACE.name,
145 },
146 wl_argument { u: arg1 },
147 wl_argument { n: 0 },
148 ];
149 let data = unsafe {
154 self.proxy
155 .send_constructor::<false>(0, &mut args, P::WL_INTERFACE, Some(version))
156 };
157 unsafe { proxy::low_level::from_untyped_owned(data) }
159 }
160}
161
162#[allow(dead_code)]
163impl WlRegistryRef {
164 #[inline]
169 pub fn bind<P: OwnedProxy>(&self, _queue: &Queue, name: u32, version: u32) -> P {
170 let (arg0, arg1) = (name, version);
171 let mut args = [
172 wl_argument { u: arg0 },
173 wl_argument {
174 s: P::WL_INTERFACE.name,
175 },
176 wl_argument { u: arg1 },
177 wl_argument { n: 0 },
178 ];
179 let data = unsafe {
184 self.proxy
185 .send_constructor(_queue, 0, &mut args, P::WL_INTERFACE, Some(version))
186 };
187 unsafe { proxy::low_level::from_untyped_owned(data) }
189 }
190}
191
192impl WlRegistry {
193 #[allow(dead_code)]
195 pub const EVT__GLOBAL__SINCE: u32 = 1;
196
197 #[allow(dead_code)]
199 pub const EVT__GLOBAL_REMOVE__SINCE: u32 = 1;
200}
201
202#[allow(dead_code)]
204pub trait WlRegistryEventHandler {
205 #[inline]
211 fn global(&self, _slf: &WlRegistryRef, name: u32, interface: &str, version: u32) {
212 let _ = name;
213 let _ = interface;
214 let _ = version;
215 }
216
217 #[inline]
221 fn global_remove(&self, _slf: &WlRegistryRef, name: u32) {
222 let _ = name;
223 }
224}
225
226impl WlRegistryEventHandler for private::NoOpEventHandler {}
227
228unsafe impl<H> EventHandler for private::EventHandler<H>
230where
231 H: WlRegistryEventHandler,
232{
233 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
234
235 #[allow(unused_variables)]
236 unsafe fn handle_event(
237 &self,
238 queue: &Queue,
239 slf: &UntypedBorrowedProxy,
240 opcode: u32,
241 args: *mut wl_argument,
242 ) {
243 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlRegistryRef>(slf) };
245 match opcode {
246 0 => {
247 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
249 let arg0 = unsafe { args[0].u };
251 let arg1 = unsafe { convert_string_arg("wl_registry", "interface", args[1].s) };
254 let arg2 = unsafe { args[2].u };
256 self.0.global(slf, arg0, arg1, arg2);
257 }
258 1 => {
259 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
261 let arg0 = unsafe { args[0].u };
263 self.0.global_remove(slf, arg0);
264 }
265 _ => {
266 invalid_opcode("wl_registry", opcode);
267 }
268 }
269 }
270}
271
272impl<H> CreateEventHandler<H> for private::ProxyApi
273where
274 H: WlRegistryEventHandler,
275{
276 type EventHandler = private::EventHandler<H>;
277
278 #[inline]
279 fn create_event_handler(handler: H) -> Self::EventHandler {
280 private::EventHandler(handler)
281 }
282}
283
284pub mod event_handlers {
286 use super::*;
287
288 pub struct Global<F>(F);
290 impl<F> WlRegistryEventHandler for Global<F>
291 where
292 F: Fn(&WlRegistryRef, u32, &str, u32),
293 {
294 #[inline]
295 fn global(&self, _slf: &WlRegistryRef, name: u32, interface: &str, version: u32) {
296 self.0(_slf, name, interface, version)
297 }
298 }
299
300 pub struct GlobalRemove<F>(F);
302 impl<F> WlRegistryEventHandler for GlobalRemove<F>
303 where
304 F: Fn(&WlRegistryRef, u32),
305 {
306 #[inline]
307 fn global_remove(&self, _slf: &WlRegistryRef, name: u32) {
308 self.0(_slf, name)
309 }
310 }
311
312 impl WlRegistry {
313 #[allow(dead_code)]
317 pub fn on_global<F>(f: F) -> Global<F>
318 where
319 F: Fn(&WlRegistryRef, u32, &str, u32),
320 {
321 Global(f)
322 }
323
324 #[allow(dead_code)]
328 pub fn on_global_remove<F>(f: F) -> GlobalRemove<F>
329 where
330 F: Fn(&WlRegistryRef, u32),
331 {
332 GlobalRemove(f)
333 }
334 }
335}