simple_window/common/protocols/wayland/
wl_callback.rs1use {super::super::all_types::*, ::wl_client::builder::prelude::*};
10
11static INTERFACE: wl_interface = wl_interface {
12 name: c"wl_callback".as_ptr(),
13 version: 1,
14 method_count: 0,
15 methods: ptr::null(),
16 event_count: 1,
17 events: {
18 static MESSAGES: [wl_message; 1] = [wl_message {
19 name: c"done".as_ptr(),
20 signature: c"u".as_ptr(),
21 types: {
22 static TYPES: [Option<&'static wl_interface>; 1] = [None];
23 TYPES.as_ptr().cast()
24 },
25 }];
26 MESSAGES.as_ptr()
27 },
28};
29
30#[derive(Clone, Eq, PartialEq)]
34#[repr(transparent)]
35pub struct WlCallback {
36 proxy: UntypedOwnedProxy,
38}
39
40#[derive(Eq, PartialEq)]
44#[repr(transparent)]
45pub struct WlCallbackRef {
46 proxy: UntypedBorrowedProxy,
48}
49
50unsafe impl UntypedOwnedProxyWrapper for WlCallback {}
52
53unsafe impl OwnedProxy for WlCallback {
56 const INTERFACE: &'static str = "wl_callback";
57 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
58 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
59 private::EventHandler(private::NoOpEventHandler);
60 const MAX_VERSION: u32 = 1;
61
62 type Borrowed = WlCallbackRef;
63 type Api = private::ProxyApi;
64 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
65}
66
67unsafe impl UntypedBorrowedProxyWrapper for WlCallbackRef {}
69
70unsafe impl BorrowedProxy for WlCallbackRef {
72 type Owned = WlCallback;
73}
74
75impl Deref for WlCallback {
76 type Target = WlCallbackRef;
77
78 fn deref(&self) -> &Self::Target {
79 proxy::low_level::deref(self)
80 }
81}
82
83mod private {
84 pub struct ProxyApi;
85
86 #[allow(dead_code)]
87 pub struct EventHandler<H>(pub(super) H);
88
89 #[allow(dead_code)]
90 pub struct NoOpEventHandler;
91}
92
93impl Debug for WlCallback {
94 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
95 write!(f, "wl_callback#{}", self.proxy.id())
96 }
97}
98
99impl Debug for WlCallbackRef {
100 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
101 write!(f, "wl_callback#{}", self.proxy.id())
102 }
103}
104
105impl PartialEq<WlCallbackRef> for WlCallback {
106 fn eq(&self, other: &WlCallbackRef) -> bool {
107 self.proxy == other.proxy
108 }
109}
110
111impl PartialEq<WlCallback> for WlCallbackRef {
112 fn eq(&self, other: &WlCallback) -> bool {
113 self.proxy == other.proxy
114 }
115}
116
117impl WlCallback {
118 #[allow(dead_code)]
120 pub const EVT__DONE__SINCE: u32 = 1;
121}
122
123#[allow(dead_code)]
125pub trait WlCallbackEventHandler {
126 #[inline]
134 fn done(&self, _slf: &WlCallbackRef, callback_data: u32) {
135 let _ = callback_data;
136 }
137}
138
139impl WlCallbackEventHandler for private::NoOpEventHandler {}
140
141unsafe impl<H> EventHandler for private::EventHandler<H>
143where
144 H: WlCallbackEventHandler,
145{
146 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
147
148 #[allow(unused_variables)]
149 unsafe fn handle_event(
150 &self,
151 queue: &Queue,
152 data: *mut u8,
153 slf: &UntypedBorrowedProxy,
154 opcode: u32,
155 args: *mut wl_argument,
156 ) {
157 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlCallbackRef>(slf) };
159 match opcode {
160 0 => {
161 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
163 let arg0 = unsafe { args[0].u };
165 self.0.done(slf, arg0);
166 }
167 _ => {
168 invalid_opcode("wl_callback", opcode);
169 }
170 }
171 }
172}
173
174impl<H> CreateEventHandler<H> for private::ProxyApi
175where
176 H: WlCallbackEventHandler,
177{
178 type EventHandler = private::EventHandler<H>;
179
180 #[inline]
181 fn create_event_handler(handler: H) -> Self::EventHandler {
182 private::EventHandler(handler)
183 }
184}
185
186pub mod event_handlers {
188 use super::*;
189
190 pub struct Done<F>(F);
192 impl<F> WlCallbackEventHandler for Done<F>
193 where
194 F: Fn(&WlCallbackRef, u32),
195 {
196 #[inline]
197 fn done(&self, _slf: &WlCallbackRef, callback_data: u32) {
198 self.0(_slf, callback_data)
199 }
200 }
201
202 impl WlCallback {
203 #[allow(dead_code)]
207 pub fn on_done<F>(f: F) -> Done<F>
208 where
209 F: Fn(&WlCallbackRef, u32),
210 {
211 Done(f)
212 }
213 }
214}