wl_client/test_protocols/core/
wl_display.rs1use {super::super::all_types::*, crate::builder::prelude::*};
2
3static INTERFACE: wl_interface = wl_interface {
4 name: c"wl_display".as_ptr(),
5 version: 1,
6 method_count: 2,
7 methods: {
8 static MESSAGES: [wl_message; 2] = [
9 wl_message {
10 name: c"sync".as_ptr(),
11 signature: c"n".as_ptr(),
12 types: {
13 static TYPES: [Option<&'static wl_interface>; 1] =
14 [Some(WlCallback::WL_INTERFACE)];
15 TYPES.as_ptr().cast()
16 },
17 },
18 wl_message {
19 name: c"get_registry".as_ptr(),
20 signature: c"n".as_ptr(),
21 types: {
22 static TYPES: [Option<&'static wl_interface>; 1] =
23 [Some(WlRegistry::WL_INTERFACE)];
24 TYPES.as_ptr().cast()
25 },
26 },
27 ];
28 MESSAGES.as_ptr()
29 },
30 event_count: 2,
31 events: {
32 static MESSAGES: [wl_message; 2] = [
33 wl_message {
34 name: c"error".as_ptr(),
35 signature: c"ous".as_ptr(),
36 types: {
37 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
38 TYPES.as_ptr().cast()
39 },
40 },
41 wl_message {
42 name: c"delete_id".as_ptr(),
43 signature: c"u".as_ptr(),
44 types: {
45 static TYPES: [Option<&'static wl_interface>; 1] = [None];
46 TYPES.as_ptr().cast()
47 },
48 },
49 ];
50 MESSAGES.as_ptr()
51 },
52};
53
54#[derive(Clone, Eq, PartialEq)]
58#[repr(transparent)]
59pub struct WlDisplay {
60 proxy: UntypedOwnedProxy,
62}
63
64#[derive(Eq, PartialEq)]
68#[repr(transparent)]
69pub struct WlDisplayRef {
70 proxy: UntypedBorrowedProxy,
72}
73
74unsafe impl UntypedOwnedProxyWrapper for WlDisplay {}
76
77unsafe impl OwnedProxy for WlDisplay {
80 const INTERFACE: &'static str = "wl_display";
81 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
82 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
83 private::EventHandler(private::NoOpEventHandler);
84 const MAX_VERSION: u32 = 1;
85
86 type Borrowed = WlDisplayRef;
87 type Api = private::ProxyApi;
88 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
89}
90
91unsafe impl UntypedBorrowedProxyWrapper for WlDisplayRef {}
93
94unsafe impl BorrowedProxy for WlDisplayRef {
96 type Owned = WlDisplay;
97}
98
99impl Deref for WlDisplay {
100 type Target = WlDisplayRef;
101
102 fn deref(&self) -> &Self::Target {
103 proxy::low_level::deref(self)
104 }
105}
106
107mod private {
108 pub struct ProxyApi;
109
110 #[allow(dead_code)]
111 pub struct EventHandler<H>(pub(super) H);
112
113 #[allow(dead_code)]
114 pub struct NoOpEventHandler;
115}
116
117impl Debug for WlDisplay {
118 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
119 write!(f, "wl_display#{}", self.proxy.id())
120 }
121}
122
123impl Debug for WlDisplayRef {
124 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
125 write!(f, "wl_display#{}", self.proxy.id())
126 }
127}
128
129impl PartialEq<WlDisplayRef> for WlDisplay {
130 fn eq(&self, other: &WlDisplayRef) -> bool {
131 self.proxy == other.proxy
132 }
133}
134
135impl PartialEq<WlDisplay> for WlDisplayRef {
136 fn eq(&self, other: &WlDisplay) -> bool {
137 self.proxy == other.proxy
138 }
139}
140
141#[allow(dead_code)]
142impl WlDisplay {
143 #[allow(dead_code)]
145 pub const REQ__SYNC__SINCE: u32 = 1;
146
147 #[inline]
148 pub fn sync(&self) -> WlCallback {
149 let mut args = [wl_argument { n: 0 }];
150 let data = unsafe {
155 self.proxy
156 .send_constructor::<false>(0, &mut args, WlCallback::WL_INTERFACE, None)
157 };
158 unsafe { proxy::low_level::from_untyped_owned(data) }
160 }
161
162 #[allow(dead_code)]
164 pub const REQ__GET_REGISTRY__SINCE: u32 = 1;
165
166 #[inline]
167 pub fn get_registry(&self) -> WlRegistry {
168 let mut args = [wl_argument { n: 0 }];
169 let data = unsafe {
174 self.proxy
175 .send_constructor::<false>(1, &mut args, WlRegistry::WL_INTERFACE, None)
176 };
177 unsafe { proxy::low_level::from_untyped_owned(data) }
179 }
180}
181
182#[allow(dead_code)]
183impl WlDisplayRef {
184 #[inline]
188 pub fn sync(&self, _queue: &Queue) -> WlCallback {
189 let mut args = [wl_argument { n: 0 }];
190 let data = unsafe {
195 self.proxy
196 .send_constructor(_queue, 0, &mut args, WlCallback::WL_INTERFACE, None)
197 };
198 unsafe { proxy::low_level::from_untyped_owned(data) }
200 }
201
202 #[inline]
206 pub fn get_registry(&self, _queue: &Queue) -> WlRegistry {
207 let mut args = [wl_argument { n: 0 }];
208 let data = unsafe {
213 self.proxy
214 .send_constructor(_queue, 1, &mut args, WlRegistry::WL_INTERFACE, None)
215 };
216 unsafe { proxy::low_level::from_untyped_owned(data) }
218 }
219}
220
221impl WlDisplay {
222 #[allow(dead_code)]
224 pub const EVT__ERROR__SINCE: u32 = 1;
225
226 #[allow(dead_code)]
228 pub const EVT__DELETE_ID__SINCE: u32 = 1;
229}
230
231#[allow(dead_code)]
233pub trait WlDisplayEventHandler {
234 #[inline]
243 fn error(
244 &self,
245 _slf: &WlDisplayRef,
246 object_id: Option<&UntypedBorrowedProxy>,
247 code: u32,
248 message: &str,
249 ) {
250 let _ = object_id;
251 let _ = code;
252 let _ = message;
253 }
254
255 #[inline]
259 fn delete_id(&self, _slf: &WlDisplayRef, id: u32) {
260 let _ = id;
261 }
262}
263
264impl WlDisplayEventHandler for private::NoOpEventHandler {}
265
266unsafe impl<H> EventHandler for private::EventHandler<H>
268where
269 H: WlDisplayEventHandler,
270{
271 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
272
273 #[allow(unused_variables)]
274 unsafe fn handle_event(
275 &self,
276 queue: &Queue,
277 slf: &UntypedBorrowedProxy,
278 opcode: u32,
279 args: *mut wl_argument,
280 ) {
281 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlDisplayRef>(slf) };
283 match opcode {
284 0 => {
285 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
287 let arg0 = unsafe {
289 if let Some(p) = NonNull::new(args[0].o.cast()) {
290 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
291 } else {
292 None
293 }
294 };
295 let arg0 = arg0.as_ref();
296 let arg1 = unsafe { args[1].u };
298 let arg2 = unsafe { convert_string_arg("wl_display", "message", args[2].s) };
301 self.0.error(slf, arg0, arg1, arg2);
302 }
303 1 => {
304 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
306 let arg0 = unsafe { args[0].u };
308 self.0.delete_id(slf, arg0);
309 }
310 _ => {
311 invalid_opcode("wl_display", opcode);
312 }
313 }
314 }
315}
316
317impl<H> CreateEventHandler<H> for private::ProxyApi
318where
319 H: WlDisplayEventHandler,
320{
321 type EventHandler = private::EventHandler<H>;
322
323 #[inline]
324 fn create_event_handler(handler: H) -> Self::EventHandler {
325 private::EventHandler(handler)
326 }
327}
328
329pub mod event_handlers {
331 use super::*;
332
333 pub struct Error<F>(F);
335 impl<F> WlDisplayEventHandler for Error<F>
336 where
337 F: Fn(&WlDisplayRef, Option<&UntypedBorrowedProxy>, u32, &str),
338 {
339 #[inline]
340 fn error(
341 &self,
342 _slf: &WlDisplayRef,
343 object_id: Option<&UntypedBorrowedProxy>,
344 code: u32,
345 message: &str,
346 ) {
347 self.0(_slf, object_id, code, message)
348 }
349 }
350
351 pub struct DeleteId<F>(F);
353 impl<F> WlDisplayEventHandler for DeleteId<F>
354 where
355 F: Fn(&WlDisplayRef, u32),
356 {
357 #[inline]
358 fn delete_id(&self, _slf: &WlDisplayRef, id: u32) {
359 self.0(_slf, id)
360 }
361 }
362
363 impl WlDisplay {
364 #[allow(dead_code)]
368 pub fn on_error<F>(f: F) -> Error<F>
369 where
370 F: Fn(&WlDisplayRef, Option<&UntypedBorrowedProxy>, u32, &str),
371 {
372 Error(f)
373 }
374
375 #[allow(dead_code)]
379 pub fn on_delete_id<F>(f: F) -> DeleteId<F>
380 where
381 F: Fn(&WlDisplayRef, u32),
382 {
383 DeleteId(f)
384 }
385 }
386}