1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
use {super::super::all_types::*, crate::builder::prelude::*};
static INTERFACE: wl_interface = wl_interface {
name: c"wl_root".as_ptr(),
version: 1,
method_count: 7,
methods: {
static MESSAGES: [wl_message; 7] = [
wl_message {
name: c"create_dummy".as_ptr(),
signature: c"n".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 1] =
[Some(WlDummy::WL_INTERFACE)];
TYPES.as_ptr().cast()
},
},
wl_message {
name: c"ping_dummy".as_ptr(),
signature: c"o".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 1] =
[Some(WlDummy::WL_INTERFACE)];
TYPES.as_ptr().cast()
},
},
wl_message {
name: c"destroy".as_ptr(),
signature: c"".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 0] = [];
TYPES.as_ptr().cast()
},
},
wl_message {
name: c"get_server_name".as_ptr(),
signature: c"n".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 1] =
[Some(WlString::WL_INTERFACE)];
TYPES.as_ptr().cast()
},
},
wl_message {
name: c"send_new_dummy".as_ptr(),
signature: c"".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 0] = [];
TYPES.as_ptr().cast()
},
},
wl_message {
name: c"echo".as_ptr(),
signature: c"ns".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 2] =
[Some(WlString::WL_INTERFACE), None];
TYPES.as_ptr().cast()
},
},
wl_message {
name: c"bind".as_ptr(),
signature: c"sun".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
TYPES.as_ptr().cast()
},
},
];
MESSAGES.as_ptr()
},
event_count: 2,
events: {
static MESSAGES: [wl_message; 2] = [
wl_message {
name: c"pong_dummy".as_ptr(),
signature: c"o".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 1] =
[Some(WlDummy::WL_INTERFACE)];
TYPES.as_ptr().cast()
},
},
wl_message {
name: c"new_dummy".as_ptr(),
signature: c"n".as_ptr(),
types: {
static TYPES: [Option<&'static wl_interface>; 1] =
[Some(WlDummy::WL_INTERFACE)];
TYPES.as_ptr().cast()
},
},
];
MESSAGES.as_ptr()
},
};
/// An owned wl_root proxy.
///
/// See the documentation of [the module][self] for the interface description.
#[derive(Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct WlRoot {
/// This proxy has the interface INTERFACE.
proxy: UntypedOwnedProxy,
}
/// A borrowed wl_root proxy.
///
/// See the documentation of [the module][self] for the interface description.
#[derive(Eq, PartialEq)]
#[repr(transparent)]
pub struct WlRootRef {
/// This proxy has the interface INTERFACE.
proxy: UntypedBorrowedProxy,
}
// SAFETY: WlRoot is a transparent wrapper around UntypedOwnedProxy
unsafe impl UntypedOwnedProxyWrapper for WlRoot {}
// SAFETY: - INTERFACE is a valid wl_interface
// - The only invariant is that self.proxy has a compatible interface
unsafe impl OwnedProxy for WlRoot {
const INTERFACE: &'static str = "wl_root";
const WL_INTERFACE: &'static wl_interface = &INTERFACE;
const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
private::EventHandler(private::NoOpEventHandler);
const MAX_VERSION: u32 = 1;
type Borrowed = WlRootRef;
type Api = private::ProxyApi;
type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
}
// SAFETY: WlRootRef is a transparent wrapper around UntypedBorrowedProxy
unsafe impl UntypedBorrowedProxyWrapper for WlRootRef {}
// SAFETY: - The only invariant is that self.proxy has a compatible interface
unsafe impl BorrowedProxy for WlRootRef {
type Owned = WlRoot;
}
impl Deref for WlRoot {
type Target = WlRootRef;
fn deref(&self) -> &Self::Target {
proxy::low_level::deref(self)
}
}
mod private {
pub struct ProxyApi;
#[allow(dead_code)]
pub struct EventHandler<H>(pub(super) H);
#[allow(dead_code)]
pub struct NoOpEventHandler;
}
impl Debug for WlRoot {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "wl_root#{}", self.proxy.id())
}
}
impl Debug for WlRootRef {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "wl_root#{}", self.proxy.id())
}
}
impl PartialEq<WlRootRef> for WlRoot {
fn eq(&self, other: &WlRootRef) -> bool {
self.proxy == other.proxy
}
}
impl PartialEq<WlRoot> for WlRootRef {
fn eq(&self, other: &WlRoot) -> bool {
self.proxy == other.proxy
}
}
#[allow(dead_code)]
impl WlRoot {
/// Since when the create_dummy request is available.
#[allow(dead_code)]
pub const REQ__CREATE_DUMMY__SINCE: u32 = 1;
#[inline]
pub fn create_dummy(&self) -> WlDummy {
let mut args = [wl_argument { n: 0 }];
// SAFETY: - self.proxy has the interface INTERFACE
// - 0 < INTERFACE.method_count = 7
// - the request signature is `n`
// - OwnedProxy::WL_INTERFACE is always a valid interface
let data = unsafe {
self.proxy
.send_constructor::<false>(0, &mut args, WlDummy::WL_INTERFACE, None)
};
// SAFETY: data has the interface WlDummy::WL_INTERFACE
unsafe { proxy::low_level::from_untyped_owned(data) }
}
/// Since when the destroy request is available.
#[allow(dead_code)]
pub const REQ__DESTROY__SINCE: u32 = 1;
#[inline]
pub fn destroy(&self) {
let mut args = [];
// SAFETY: - self.proxy has the interface INTERFACE
// - 2 < INTERFACE.method_count = 7
// - the request signature is ``
unsafe {
self.proxy.send_destructor(2, &mut args);
}
}
/// Since when the get_server_name request is available.
#[allow(dead_code)]
pub const REQ__GET_SERVER_NAME__SINCE: u32 = 1;
#[inline]
pub fn get_server_name(&self) -> WlString {
let mut args = [wl_argument { n: 0 }];
// SAFETY: - self.proxy has the interface INTERFACE
// - 3 < INTERFACE.method_count = 7
// - the request signature is `n`
// - OwnedProxy::WL_INTERFACE is always a valid interface
let data = unsafe {
self.proxy
.send_constructor::<false>(3, &mut args, WlString::WL_INTERFACE, None)
};
// SAFETY: data has the interface WlString::WL_INTERFACE
unsafe { proxy::low_level::from_untyped_owned(data) }
}
/// Since when the echo request is available.
#[allow(dead_code)]
pub const REQ__ECHO__SINCE: u32 = 1;
/// # Arguments
///
/// - `str`:
#[inline]
pub fn echo(&self, str: &str) -> WlString {
let (arg1,) = (str,);
with_cstr_cache(|cache| {
let str1_offset = cache.len();
cache.extend_from_slice(arg1.as_bytes());
cache.push(0);
let str1 = cache[str1_offset..].as_ptr().cast();
let mut args = [wl_argument { n: 0 }, wl_argument { s: str1 }];
// SAFETY: - self.proxy has the interface INTERFACE
// - 5 < INTERFACE.method_count = 7
// - the request signature is `ns`
// - OwnedProxy::WL_INTERFACE is always a valid interface
let data = unsafe {
self.proxy
.send_constructor::<false>(5, &mut args, WlString::WL_INTERFACE, None)
};
// SAFETY: data has the interface WlString::WL_INTERFACE
unsafe { proxy::low_level::from_untyped_owned(data) }
})
}
/// Since when the bind request is available.
#[allow(dead_code)]
pub const REQ__BIND__SINCE: u32 = 1;
#[inline]
pub fn bind<P: OwnedProxy>(&self, version: u32) -> P {
let (arg0,) = (version,);
let mut args = [
wl_argument {
s: P::WL_INTERFACE.name,
},
wl_argument { u: arg0 },
wl_argument { n: 0 },
];
// SAFETY: - self.proxy has the interface INTERFACE
// - 6 < INTERFACE.method_count = 7
// - the request signature is `sun`
// - OwnedProxy::WL_INTERFACE is always a valid interface
let data = unsafe {
self.proxy
.send_constructor::<false>(6, &mut args, P::WL_INTERFACE, Some(version))
};
// SAFETY: data has the interface P::WL_INTERFACE
unsafe { proxy::low_level::from_untyped_owned(data) }
}
}
#[allow(dead_code)]
impl WlRootRef {
/// # Arguments
///
/// - `_queue`: The queue that the returned proxy is assigned to.
#[inline]
pub fn create_dummy(&self, _queue: &Queue) -> WlDummy {
let mut args = [wl_argument { n: 0 }];
// SAFETY: - self.proxy has the interface INTERFACE
// - 0 < INTERFACE.method_count = 7
// - the request signature is `n`
// - OwnedProxy::WL_INTERFACE is always a valid interface
let data = unsafe {
self.proxy
.send_constructor(_queue, 0, &mut args, WlDummy::WL_INTERFACE, None)
};
// SAFETY: data has the interface WlDummy::WL_INTERFACE
unsafe { proxy::low_level::from_untyped_owned(data) }
}
/// # Arguments
///
/// - `id`:
#[inline]
pub fn ping_dummy(&self, id: &WlDummyRef) {
let (arg0,) = (id,);
let obj0_lock = proxy::lock(arg0);
let obj0 = check_argument_proxy("id", obj0_lock.wl_proxy());
let mut args = [wl_argument { o: obj0 }];
// SAFETY: - self.proxy has the interface INTERFACE
// - 1 < INTERFACE.method_count = 7
// - the request signature is `o`
unsafe {
self.proxy.send_request(1, &mut args);
}
}
/// # Arguments
///
/// - `_queue`: The queue that the returned proxy is assigned to.
#[inline]
pub fn get_server_name(&self, _queue: &Queue) -> WlString {
let mut args = [wl_argument { n: 0 }];
// SAFETY: - self.proxy has the interface INTERFACE
// - 3 < INTERFACE.method_count = 7
// - the request signature is `n`
// - OwnedProxy::WL_INTERFACE is always a valid interface
let data = unsafe {
self.proxy
.send_constructor(_queue, 3, &mut args, WlString::WL_INTERFACE, None)
};
// SAFETY: data has the interface WlString::WL_INTERFACE
unsafe { proxy::low_level::from_untyped_owned(data) }
}
#[inline]
pub fn send_new_dummy(&self) {
let mut args = [];
// SAFETY: - self.proxy has the interface INTERFACE
// - 4 < INTERFACE.method_count = 7
// - the request signature is ``
unsafe {
self.proxy.send_request(4, &mut args);
}
}
/// # Arguments
///
/// - `_queue`: The queue that the returned proxy is assigned to.
/// - `str`:
#[inline]
pub fn echo(&self, _queue: &Queue, str: &str) -> WlString {
let (arg1,) = (str,);
with_cstr_cache(|cache| {
let str1_offset = cache.len();
cache.extend_from_slice(arg1.as_bytes());
cache.push(0);
let str1 = cache[str1_offset..].as_ptr().cast();
let mut args = [wl_argument { n: 0 }, wl_argument { s: str1 }];
// SAFETY: - self.proxy has the interface INTERFACE
// - 5 < INTERFACE.method_count = 7
// - the request signature is `ns`
// - OwnedProxy::WL_INTERFACE is always a valid interface
let data = unsafe {
self.proxy
.send_constructor(_queue, 5, &mut args, WlString::WL_INTERFACE, None)
};
// SAFETY: data has the interface WlString::WL_INTERFACE
unsafe { proxy::low_level::from_untyped_owned(data) }
})
}
/// # Arguments
///
/// - `_queue`: The queue that the returned proxy is assigned to.
#[inline]
pub fn bind<P: OwnedProxy>(&self, _queue: &Queue, version: u32) -> P {
let (arg0,) = (version,);
let mut args = [
wl_argument {
s: P::WL_INTERFACE.name,
},
wl_argument { u: arg0 },
wl_argument { n: 0 },
];
// SAFETY: - self.proxy has the interface INTERFACE
// - 6 < INTERFACE.method_count = 7
// - the request signature is `sun`
// - OwnedProxy::WL_INTERFACE is always a valid interface
let data = unsafe {
self.proxy
.send_constructor(_queue, 6, &mut args, P::WL_INTERFACE, Some(version))
};
// SAFETY: data has the interface P::WL_INTERFACE
unsafe { proxy::low_level::from_untyped_owned(data) }
}
}
impl WlRoot {
/// Since when the pong_dummy event is available.
#[allow(dead_code)]
pub const EVT__PONG_DUMMY__SINCE: u32 = 1;
/// Since when the new_dummy event is available.
#[allow(dead_code)]
pub const EVT__NEW_DUMMY__SINCE: u32 = 1;
}
/// An event handler for [WlRoot] proxies.
#[allow(dead_code)]
pub trait WlRootEventHandler {
/// # Arguments
///
/// - `id`:
///
/// All borrowed proxies passed to this function are guaranteed to be
/// immutable and non-null.
#[inline]
fn pong_dummy(&self, _slf: &WlRootRef, id: Option<&WlDummyRef>) {
let _ = id;
}
/// # Arguments
///
/// - `id`:
#[inline]
fn new_dummy(&self, _slf: &WlRootRef, id: WlDummy) {
let _ = id;
}
}
impl WlRootEventHandler for private::NoOpEventHandler {}
// SAFETY: - INTERFACE is a valid wl_interface
unsafe impl<H> EventHandler for private::EventHandler<H>
where
H: WlRootEventHandler,
{
const WL_INTERFACE: &'static wl_interface = &INTERFACE;
#[allow(unused_variables)]
unsafe fn handle_event(
&self,
queue: &Queue,
data: *mut u8,
slf: &UntypedBorrowedProxy,
opcode: u32,
args: *mut wl_argument,
) {
// SAFETY: This function requires that slf has the interface INTERFACE
let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlRootRef>(slf) };
match opcode {
0 => {
// SAFETY: INTERFACE requires that there are 1 arguments
let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
// SAFETY: - INTERFACE requires that args[0] contains an object
let arg0 = unsafe {
if let Some(p) = NonNull::new(args[0].o.cast()) {
Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
} else {
None
}
};
// SAFETY: - INTERFACE requires that the object has the interface WlDummy::WL_INTERFACE
let arg0 = arg0.as_ref().map(|arg0| unsafe {
proxy::low_level::from_untyped_borrowed::<WlDummyRef>(arg0)
});
self.0.pong_dummy(slf, arg0);
}
1 => {
// SAFETY: INTERFACE requires that there are 1 arguments
let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
// SAFETY: - INTERFACE requires that args[0] contains an object
// - ownership is transferred to this function
// - INTERFACE requires that the object has the interface WlDummy::WL_INTERFACE
let arg0 = unsafe {
UntypedOwnedProxy::from_plain_wl_proxy(
queue,
NonNull::new_unchecked(args[0].o.cast()),
WlDummy::WL_INTERFACE,
)
};
// SAFETY: - INTERFACE requires that the object has the interface WlDummy::WL_INTERFACE
let arg0 = unsafe { proxy::low_level::from_untyped_owned::<WlDummy>(arg0) };
self.0.new_dummy(slf, arg0);
}
_ => {
invalid_opcode("wl_root", opcode);
}
}
}
}
impl<H> CreateEventHandler<H> for private::ProxyApi
where
H: WlRootEventHandler,
{
type EventHandler = private::EventHandler<H>;
#[inline]
fn create_event_handler(handler: H) -> Self::EventHandler {
private::EventHandler(handler)
}
}
/// Functional event handlers.
pub mod event_handlers {
use super::*;
/// Event handler for pong_dummy events.
pub struct PongDummy<F>(F);
impl<F> WlRootEventHandler for PongDummy<F>
where
F: Fn(&WlRootRef, Option<&WlDummyRef>),
{
#[inline]
fn pong_dummy(&self, _slf: &WlRootRef, id: Option<&WlDummyRef>) {
self.0(_slf, id)
}
}
/// Event handler for new_dummy events.
pub struct NewDummy<F>(F);
impl<F> WlRootEventHandler for NewDummy<F>
where
F: Fn(&WlRootRef, WlDummy),
{
#[inline]
fn new_dummy(&self, _slf: &WlRootRef, id: WlDummy) {
self.0(_slf, id)
}
}
impl WlRoot {
/// Creates an event handler for pong_dummy events.
///
/// The event handler ignores all other events.
#[allow(dead_code)]
pub fn on_pong_dummy<F>(f: F) -> PongDummy<F>
where
F: Fn(&WlRootRef, Option<&WlDummyRef>),
{
PongDummy(f)
}
/// Creates an event handler for new_dummy events.
///
/// The event handler ignores all other events.
#[allow(dead_code)]
pub fn on_new_dummy<F>(f: F) -> NewDummy<F>
where
F: Fn(&WlRootRef, WlDummy),
{
NewDummy(f)
}
}
}