wl_client/test_protocols/core/
wl_root.rs1use {super::super::all_types::*, crate::builder::prelude::*};
2
3static INTERFACE: wl_interface = wl_interface {
4 name: c"wl_root".as_ptr(),
5 version: 1,
6 method_count: 7,
7 methods: {
8 static MESSAGES: [wl_message; 7] = [
9 wl_message {
10 name: c"create_dummy".as_ptr(),
11 signature: c"n".as_ptr(),
12 types: {
13 static TYPES: [Option<&'static wl_interface>; 1] =
14 [Some(WlDummy::WL_INTERFACE)];
15 TYPES.as_ptr().cast()
16 },
17 },
18 wl_message {
19 name: c"ping_dummy".as_ptr(),
20 signature: c"o".as_ptr(),
21 types: {
22 static TYPES: [Option<&'static wl_interface>; 1] =
23 [Some(WlDummy::WL_INTERFACE)];
24 TYPES.as_ptr().cast()
25 },
26 },
27 wl_message {
28 name: c"destroy".as_ptr(),
29 signature: c"".as_ptr(),
30 types: {
31 static TYPES: [Option<&'static wl_interface>; 0] = [];
32 TYPES.as_ptr().cast()
33 },
34 },
35 wl_message {
36 name: c"get_server_name".as_ptr(),
37 signature: c"n".as_ptr(),
38 types: {
39 static TYPES: [Option<&'static wl_interface>; 1] =
40 [Some(WlString::WL_INTERFACE)];
41 TYPES.as_ptr().cast()
42 },
43 },
44 wl_message {
45 name: c"send_new_dummy".as_ptr(),
46 signature: c"".as_ptr(),
47 types: {
48 static TYPES: [Option<&'static wl_interface>; 0] = [];
49 TYPES.as_ptr().cast()
50 },
51 },
52 wl_message {
53 name: c"echo".as_ptr(),
54 signature: c"ns".as_ptr(),
55 types: {
56 static TYPES: [Option<&'static wl_interface>; 2] =
57 [Some(WlString::WL_INTERFACE), None];
58 TYPES.as_ptr().cast()
59 },
60 },
61 wl_message {
62 name: c"bind".as_ptr(),
63 signature: c"sun".as_ptr(),
64 types: {
65 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
66 TYPES.as_ptr().cast()
67 },
68 },
69 ];
70 MESSAGES.as_ptr()
71 },
72 event_count: 2,
73 events: {
74 static MESSAGES: [wl_message; 2] = [
75 wl_message {
76 name: c"pong_dummy".as_ptr(),
77 signature: c"o".as_ptr(),
78 types: {
79 static TYPES: [Option<&'static wl_interface>; 1] =
80 [Some(WlDummy::WL_INTERFACE)];
81 TYPES.as_ptr().cast()
82 },
83 },
84 wl_message {
85 name: c"new_dummy".as_ptr(),
86 signature: c"n".as_ptr(),
87 types: {
88 static TYPES: [Option<&'static wl_interface>; 1] =
89 [Some(WlDummy::WL_INTERFACE)];
90 TYPES.as_ptr().cast()
91 },
92 },
93 ];
94 MESSAGES.as_ptr()
95 },
96};
97
98#[derive(Clone, Eq, PartialEq)]
102#[repr(transparent)]
103pub struct WlRoot {
104 proxy: UntypedOwnedProxy,
106}
107
108#[derive(Eq, PartialEq)]
112#[repr(transparent)]
113pub struct WlRootRef {
114 proxy: UntypedBorrowedProxy,
116}
117
118unsafe impl UntypedOwnedProxyWrapper for WlRoot {}
120
121unsafe impl OwnedProxy for WlRoot {
124 const INTERFACE: &'static str = "wl_root";
125 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
126 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
127 private::EventHandler(private::NoOpEventHandler);
128 const MAX_VERSION: u32 = 1;
129
130 type Borrowed = WlRootRef;
131 type Api = private::ProxyApi;
132 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
133}
134
135unsafe impl UntypedBorrowedProxyWrapper for WlRootRef {}
137
138unsafe impl BorrowedProxy for WlRootRef {
140 type Owned = WlRoot;
141}
142
143impl Deref for WlRoot {
144 type Target = WlRootRef;
145
146 fn deref(&self) -> &Self::Target {
147 proxy::low_level::deref(self)
148 }
149}
150
151mod private {
152 pub struct ProxyApi;
153
154 #[allow(dead_code)]
155 pub struct EventHandler<H>(pub(super) H);
156
157 #[allow(dead_code)]
158 pub struct NoOpEventHandler;
159}
160
161impl Debug for WlRoot {
162 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
163 write!(f, "wl_root#{}", self.proxy.id())
164 }
165}
166
167impl Debug for WlRootRef {
168 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
169 write!(f, "wl_root#{}", self.proxy.id())
170 }
171}
172
173impl PartialEq<WlRootRef> for WlRoot {
174 fn eq(&self, other: &WlRootRef) -> bool {
175 self.proxy == other.proxy
176 }
177}
178
179impl PartialEq<WlRoot> for WlRootRef {
180 fn eq(&self, other: &WlRoot) -> bool {
181 self.proxy == other.proxy
182 }
183}
184
185#[allow(dead_code)]
186impl WlRoot {
187 #[allow(dead_code)]
189 pub const REQ__CREATE_DUMMY__SINCE: u32 = 1;
190
191 #[inline]
192 pub fn create_dummy(&self) -> WlDummy {
193 let mut args = [wl_argument { n: 0 }];
194 let data = unsafe {
199 self.proxy
200 .send_constructor::<false>(0, &mut args, WlDummy::WL_INTERFACE, None)
201 };
202 unsafe { proxy::low_level::from_untyped_owned(data) }
204 }
205
206 #[allow(dead_code)]
208 pub const REQ__DESTROY__SINCE: u32 = 1;
209
210 #[inline]
211 pub fn destroy(&self) {
212 let mut args = [];
213 unsafe {
217 self.proxy.send_destructor(2, &mut args);
218 }
219 }
220
221 #[allow(dead_code)]
223 pub const REQ__GET_SERVER_NAME__SINCE: u32 = 1;
224
225 #[inline]
226 pub fn get_server_name(&self) -> WlString {
227 let mut args = [wl_argument { n: 0 }];
228 let data = unsafe {
233 self.proxy
234 .send_constructor::<false>(3, &mut args, WlString::WL_INTERFACE, None)
235 };
236 unsafe { proxy::low_level::from_untyped_owned(data) }
238 }
239
240 #[allow(dead_code)]
242 pub const REQ__ECHO__SINCE: u32 = 1;
243
244 #[inline]
248 pub fn echo(&self, str: &str) -> WlString {
249 let (arg1,) = (str,);
250 with_cstr_cache(|cache| {
251 let str1_offset = cache.len();
252 cache.extend_from_slice(arg1.as_bytes());
253 cache.push(0);
254 let str1 = cache[str1_offset..].as_ptr().cast();
255 let mut args = [wl_argument { n: 0 }, wl_argument { s: str1 }];
256 let data = unsafe {
261 self.proxy
262 .send_constructor::<false>(5, &mut args, WlString::WL_INTERFACE, None)
263 };
264 unsafe { proxy::low_level::from_untyped_owned(data) }
266 })
267 }
268
269 #[allow(dead_code)]
271 pub const REQ__BIND__SINCE: u32 = 1;
272
273 #[inline]
274 pub fn bind<P: OwnedProxy>(&self, version: u32) -> P {
275 let (arg0,) = (version,);
276 let mut args = [
277 wl_argument {
278 s: P::WL_INTERFACE.name,
279 },
280 wl_argument { u: arg0 },
281 wl_argument { n: 0 },
282 ];
283 let data = unsafe {
288 self.proxy
289 .send_constructor::<false>(6, &mut args, P::WL_INTERFACE, Some(version))
290 };
291 unsafe { proxy::low_level::from_untyped_owned(data) }
293 }
294}
295
296#[allow(dead_code)]
297impl WlRootRef {
298 #[inline]
302 pub fn create_dummy(&self, _queue: &Queue) -> WlDummy {
303 let mut args = [wl_argument { n: 0 }];
304 let data = unsafe {
309 self.proxy
310 .send_constructor(_queue, 0, &mut args, WlDummy::WL_INTERFACE, None)
311 };
312 unsafe { proxy::low_level::from_untyped_owned(data) }
314 }
315
316 #[inline]
320 pub fn ping_dummy(&self, id: &WlDummyRef) {
321 let (arg0,) = (id,);
322 let obj0_lock = proxy::lock(arg0);
323 let obj0 = check_argument_proxy("id", obj0_lock.wl_proxy());
324 let mut args = [wl_argument { o: obj0 }];
325 unsafe {
329 self.proxy.send_request(1, &mut args);
330 }
331 }
332
333 #[inline]
337 pub fn get_server_name(&self, _queue: &Queue) -> WlString {
338 let mut args = [wl_argument { n: 0 }];
339 let data = unsafe {
344 self.proxy
345 .send_constructor(_queue, 3, &mut args, WlString::WL_INTERFACE, None)
346 };
347 unsafe { proxy::low_level::from_untyped_owned(data) }
349 }
350
351 #[inline]
352 pub fn send_new_dummy(&self) {
353 let mut args = [];
354 unsafe {
358 self.proxy.send_request(4, &mut args);
359 }
360 }
361
362 #[inline]
367 pub fn echo(&self, _queue: &Queue, str: &str) -> WlString {
368 let (arg1,) = (str,);
369 with_cstr_cache(|cache| {
370 let str1_offset = cache.len();
371 cache.extend_from_slice(arg1.as_bytes());
372 cache.push(0);
373 let str1 = cache[str1_offset..].as_ptr().cast();
374 let mut args = [wl_argument { n: 0 }, wl_argument { s: str1 }];
375 let data = unsafe {
380 self.proxy
381 .send_constructor(_queue, 5, &mut args, WlString::WL_INTERFACE, None)
382 };
383 unsafe { proxy::low_level::from_untyped_owned(data) }
385 })
386 }
387
388 #[inline]
392 pub fn bind<P: OwnedProxy>(&self, _queue: &Queue, version: u32) -> P {
393 let (arg0,) = (version,);
394 let mut args = [
395 wl_argument {
396 s: P::WL_INTERFACE.name,
397 },
398 wl_argument { u: arg0 },
399 wl_argument { n: 0 },
400 ];
401 let data = unsafe {
406 self.proxy
407 .send_constructor(_queue, 6, &mut args, P::WL_INTERFACE, Some(version))
408 };
409 unsafe { proxy::low_level::from_untyped_owned(data) }
411 }
412}
413
414impl WlRoot {
415 #[allow(dead_code)]
417 pub const EVT__PONG_DUMMY__SINCE: u32 = 1;
418
419 #[allow(dead_code)]
421 pub const EVT__NEW_DUMMY__SINCE: u32 = 1;
422}
423
424#[allow(dead_code)]
426pub trait WlRootEventHandler {
427 #[inline]
434 fn pong_dummy(&self, _slf: &WlRootRef, id: Option<&WlDummyRef>) {
435 let _ = id;
436 }
437
438 #[inline]
442 fn new_dummy(&self, _slf: &WlRootRef, id: WlDummy) {
443 let _ = id;
444 }
445}
446
447impl WlRootEventHandler for private::NoOpEventHandler {}
448
449unsafe impl<H> EventHandler for private::EventHandler<H>
451where
452 H: WlRootEventHandler,
453{
454 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
455
456 #[allow(unused_variables)]
457 unsafe fn handle_event(
458 &self,
459 queue: &Queue,
460 slf: &UntypedBorrowedProxy,
461 opcode: u32,
462 args: *mut wl_argument,
463 ) {
464 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlRootRef>(slf) };
466 match opcode {
467 0 => {
468 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
470 let arg0 = unsafe {
472 if let Some(p) = NonNull::new(args[0].o.cast()) {
473 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
474 } else {
475 None
476 }
477 };
478 let arg0 = arg0.as_ref().map(|arg0| unsafe {
480 proxy::low_level::from_untyped_borrowed::<WlDummyRef>(arg0)
481 });
482 self.0.pong_dummy(slf, arg0);
483 }
484 1 => {
485 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
487 let arg0 = unsafe {
491 UntypedOwnedProxy::from_plain_wl_proxy(
492 queue,
493 NonNull::new_unchecked(args[0].o.cast()),
494 WlDummy::WL_INTERFACE,
495 )
496 };
497 let arg0 = unsafe { proxy::low_level::from_untyped_owned::<WlDummy>(arg0) };
499 self.0.new_dummy(slf, arg0);
500 }
501 _ => {
502 invalid_opcode("wl_root", opcode);
503 }
504 }
505 }
506}
507
508impl<H> CreateEventHandler<H> for private::ProxyApi
509where
510 H: WlRootEventHandler,
511{
512 type EventHandler = private::EventHandler<H>;
513
514 #[inline]
515 fn create_event_handler(handler: H) -> Self::EventHandler {
516 private::EventHandler(handler)
517 }
518}
519
520pub mod event_handlers {
522 use super::*;
523
524 pub struct PongDummy<F>(F);
526 impl<F> WlRootEventHandler for PongDummy<F>
527 where
528 F: Fn(&WlRootRef, Option<&WlDummyRef>),
529 {
530 #[inline]
531 fn pong_dummy(&self, _slf: &WlRootRef, id: Option<&WlDummyRef>) {
532 self.0(_slf, id)
533 }
534 }
535
536 pub struct NewDummy<F>(F);
538 impl<F> WlRootEventHandler for NewDummy<F>
539 where
540 F: Fn(&WlRootRef, WlDummy),
541 {
542 #[inline]
543 fn new_dummy(&self, _slf: &WlRootRef, id: WlDummy) {
544 self.0(_slf, id)
545 }
546 }
547
548 impl WlRoot {
549 #[allow(dead_code)]
553 pub fn on_pong_dummy<F>(f: F) -> PongDummy<F>
554 where
555 F: Fn(&WlRootRef, Option<&WlDummyRef>),
556 {
557 PongDummy(f)
558 }
559
560 #[allow(dead_code)]
564 pub fn on_new_dummy<F>(f: F) -> NewDummy<F>
565 where
566 F: Fn(&WlRootRef, WlDummy),
567 {
568 NewDummy(f)
569 }
570 }
571}