get_registry/common/protocols_data/xdg_shell/xdg_surface.rs
1//! desktop user interface surface base interface
2//!
3//! An interface that may be implemented by a wl_surface, for
4//! implementations that provide a desktop-style user interface.
5//!
6//! It provides a base set of functionality required to construct user
7//! interface elements requiring management by the compositor, such as
8//! toplevel windows, menus, etc. The types of functionality are split into
9//! xdg_surface roles.
10//!
11//! Creating an xdg_surface does not set the role for a wl_surface. In order
12//! to map an xdg_surface, the client must create a role-specific object
13//! using, e.g., get_toplevel, get_popup. The wl_surface for any given
14//! xdg_surface can have at most one role, and may not be assigned any role
15//! not based on xdg_surface.
16//!
17//! A role must be assigned before any other requests are made to the
18//! xdg_surface object.
19//!
20//! The client must call wl_surface.commit on the corresponding wl_surface
21//! for the xdg_surface state to take effect.
22//!
23//! Creating an xdg_surface from a wl_surface which has a buffer attached or
24//! committed is a client error, and any attempts by a client to attach or
25//! manipulate a buffer prior to the first xdg_surface.configure call must
26//! also be treated as errors.
27//!
28//! After creating a role-specific object and setting it up (e.g. by sending
29//! the title, app ID, size constraints, parent, etc), the client must
30//! perform an initial commit without any buffer attached. The compositor
31//! will reply with initial wl_surface state such as
32//! wl_surface.preferred_buffer_scale followed by an xdg_surface.configure
33//! event. The client must acknowledge it and is then allowed to attach a
34//! buffer to map the surface.
35//!
36//! Mapping an xdg_surface-based role surface is defined as making it
37//! possible for the surface to be shown by the compositor. Note that
38//! a mapped surface is not guaranteed to be visible once it is mapped.
39//!
40//! For an xdg_surface to be mapped by the compositor, the following
41//! conditions must be met:
42//! (1) the client has assigned an xdg_surface-based role to the surface
43//! (2) the client has set and committed the xdg_surface state and the
44//! role-dependent state to the surface
45//! (3) the client has committed a buffer to the surface
46//!
47//! A newly-unmapped surface is considered to have met condition (1) out
48//! of the 3 required conditions for mapping a surface if its role surface
49//! has not been destroyed, i.e. the client must perform the initial commit
50//! again before attaching a buffer.
51
52use super::super::all_types::*;
53use ::wl_client::builder::prelude::*;
54
55static INTERFACE: wl_interface = wl_interface {
56 name: c"xdg_surface".as_ptr(),
57 version: 6,
58 method_count: 5,
59 methods: {
60 static MESSAGES: [wl_message; 5] = [
61 wl_message {
62 name: c"destroy".as_ptr(),
63 signature: c"".as_ptr(),
64 types: {
65 static TYPES: [Option<&'static wl_interface>; 0] = [];
66 TYPES.as_ptr().cast()
67 },
68 },
69 wl_message {
70 name: c"get_toplevel".as_ptr(),
71 signature: c"n".as_ptr(),
72 types: {
73 static TYPES: [Option<&'static wl_interface>; 1] =
74 [Some(XdgToplevel::WL_INTERFACE)];
75 TYPES.as_ptr().cast()
76 },
77 },
78 wl_message {
79 name: c"get_popup".as_ptr(),
80 signature: c"n?oo".as_ptr(),
81 types: {
82 static TYPES: [Option<&'static wl_interface>; 3] = [
83 Some(XdgPopup::WL_INTERFACE),
84 Some(XdgSurface::WL_INTERFACE),
85 Some(XdgPositioner::WL_INTERFACE),
86 ];
87 TYPES.as_ptr().cast()
88 },
89 },
90 wl_message {
91 name: c"set_window_geometry".as_ptr(),
92 signature: c"iiii".as_ptr(),
93 types: {
94 static TYPES: [Option<&'static wl_interface>; 4] = [None, None, None, None];
95 TYPES.as_ptr().cast()
96 },
97 },
98 wl_message {
99 name: c"ack_configure".as_ptr(),
100 signature: c"u".as_ptr(),
101 types: {
102 static TYPES: [Option<&'static wl_interface>; 1] = [None];
103 TYPES.as_ptr().cast()
104 },
105 },
106 ];
107 MESSAGES.as_ptr()
108 },
109 event_count: 1,
110 events: {
111 static MESSAGES: [wl_message; 1] = [wl_message {
112 name: c"configure".as_ptr(),
113 signature: c"u".as_ptr(),
114 types: {
115 static TYPES: [Option<&'static wl_interface>; 1] = [None];
116 TYPES.as_ptr().cast()
117 },
118 }];
119 MESSAGES.as_ptr()
120 },
121};
122
123/// An owned xdg_surface proxy.
124///
125/// See the documentation of [the module][self] for the interface description.
126#[derive(Clone, Eq, PartialEq)]
127#[repr(transparent)]
128pub struct XdgSurface {
129 /// This proxy has the interface INTERFACE.
130 proxy: UntypedOwnedProxy,
131}
132
133/// A borrowed xdg_surface proxy.
134///
135/// See the documentation of [the module][self] for the interface description.
136#[derive(Eq, PartialEq)]
137#[repr(transparent)]
138pub struct XdgSurfaceRef {
139 /// This proxy has the interface INTERFACE.
140 proxy: UntypedBorrowedProxy,
141}
142
143// SAFETY: XdgSurface is a transparent wrapper around UntypedOwnedProxy
144unsafe impl UntypedOwnedProxyWrapper for XdgSurface {}
145
146// SAFETY: - INTERFACE is a valid wl_interface
147// - The only invariant is that self.proxy has a compatible interface
148unsafe impl OwnedProxy for XdgSurface {
149 const INTERFACE: &'static str = "xdg_surface";
150 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
151 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
152 private::EventHandler(private::NoOpEventHandler);
153 const MAX_VERSION: u32 = 6;
154
155 type Borrowed = XdgSurfaceRef;
156 type Api = private::ProxyApi;
157 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
158}
159
160// SAFETY: XdgSurfaceRef is a transparent wrapper around UntypedBorrowedProxy
161unsafe impl UntypedBorrowedProxyWrapper for XdgSurfaceRef {}
162
163// SAFETY: - The only invariant is that self.proxy has a compatible interface
164unsafe impl BorrowedProxy for XdgSurfaceRef {
165 type Owned = XdgSurface;
166}
167
168impl Deref for XdgSurface {
169 type Target = XdgSurfaceRef;
170
171 fn deref(&self) -> &Self::Target {
172 proxy::low_level::deref(self)
173 }
174}
175
176mod private {
177 pub struct ProxyApi;
178
179 #[allow(dead_code)]
180 pub struct EventHandler<H>(pub(super) H);
181
182 #[allow(dead_code)]
183 pub struct NoOpEventHandler;
184}
185
186impl Debug for XdgSurface {
187 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
188 write!(f, "xdg_surface#{}", self.proxy.id())
189 }
190}
191
192impl Debug for XdgSurfaceRef {
193 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
194 write!(f, "xdg_surface#{}", self.proxy.id())
195 }
196}
197
198impl PartialEq<XdgSurfaceRef> for XdgSurface {
199 fn eq(&self, other: &XdgSurfaceRef) -> bool {
200 self.proxy == other.proxy
201 }
202}
203
204impl PartialEq<XdgSurface> for XdgSurfaceRef {
205 fn eq(&self, other: &XdgSurface) -> bool {
206 self.proxy == other.proxy
207 }
208}
209
210#[allow(dead_code)]
211impl XdgSurface {
212 /// Since when the destroy request is available.
213 #[allow(dead_code)]
214 pub const REQ__DESTROY__SINCE: u32 = 1;
215
216 /// Since when the get_toplevel request is available.
217 #[allow(dead_code)]
218 pub const REQ__GET_TOPLEVEL__SINCE: u32 = 1;
219
220 /// Since when the get_popup request is available.
221 #[allow(dead_code)]
222 pub const REQ__GET_POPUP__SINCE: u32 = 1;
223
224 /// Since when the set_window_geometry request is available.
225 #[allow(dead_code)]
226 pub const REQ__SET_WINDOW_GEOMETRY__SINCE: u32 = 1;
227
228 /// Since when the ack_configure request is available.
229 #[allow(dead_code)]
230 pub const REQ__ACK_CONFIGURE__SINCE: u32 = 1;
231}
232
233#[allow(dead_code)]
234impl XdgSurface {
235 /// destroy the xdg_surface
236 ///
237 /// Destroy the xdg_surface object. An xdg_surface must only be destroyed
238 /// after its role object has been destroyed, otherwise
239 /// a defunct_role_object error is raised.
240 #[inline]
241 pub fn destroy(&self) {
242 let mut args = [];
243 // SAFETY: - self.proxy has the interface INTERFACE
244 // - 0 < INTERFACE.method_count = 5
245 // - the request signature is ``
246 unsafe {
247 self.proxy.send_destructor(0, &mut args);
248 }
249 }
250
251 /// assign the xdg_toplevel surface role
252 ///
253 /// This creates an xdg_toplevel object for the given xdg_surface and gives
254 /// the associated wl_surface the xdg_toplevel role.
255 ///
256 /// See the documentation of xdg_toplevel for more details about what an
257 /// xdg_toplevel is and how it is used.
258 #[inline]
259 pub fn get_toplevel(&self) -> XdgToplevel {
260 let mut args = [wl_argument { n: 0 }];
261 // SAFETY: - self.proxy has the interface INTERFACE
262 // - 1 < INTERFACE.method_count = 5
263 // - the request signature is `n`
264 // - OwnedProxy::WL_INTERFACE is always a valid interface
265 let data = unsafe {
266 self.proxy
267 .send_constructor::<false>(1, &mut args, XdgToplevel::WL_INTERFACE, None)
268 };
269 // SAFETY: data has the interface XdgToplevel::WL_INTERFACE
270 unsafe { proxy::low_level::from_untyped_owned(data) }
271 }
272
273 /// assign the xdg_popup surface role
274 ///
275 /// This creates an xdg_popup object for the given xdg_surface and gives
276 /// the associated wl_surface the xdg_popup role.
277 ///
278 /// If null is passed as a parent, a parent surface must be specified using
279 /// some other protocol, before committing the initial state.
280 ///
281 /// See the documentation of xdg_popup for more details about what an
282 /// xdg_popup is and how it is used.
283 ///
284 /// # Arguments
285 ///
286 /// - `parent`:
287 /// - `positioner`:
288 #[inline]
289 pub fn get_popup(
290 &self,
291 parent: Option<&XdgSurfaceRef>,
292 positioner: &XdgPositionerRef,
293 ) -> XdgPopup {
294 let (arg1, arg2) = (parent, positioner);
295 let obj1_lock = arg1.map(|arg1| proxy::lock(arg1));
296 let obj1 = obj1_lock
297 .map(|obj1_lock| check_argument_proxy("parent", obj1_lock.wl_proxy()))
298 .unwrap_or(ptr::null_mut());
299 let obj2_lock = proxy::lock(arg2);
300 let obj2 = check_argument_proxy("positioner", obj2_lock.wl_proxy());
301 let mut args = [
302 wl_argument { n: 0 },
303 wl_argument { o: obj1 },
304 wl_argument { o: obj2 },
305 ];
306 // SAFETY: - self.proxy has the interface INTERFACE
307 // - 2 < INTERFACE.method_count = 5
308 // - the request signature is `n?oo`
309 // - OwnedProxy::WL_INTERFACE is always a valid interface
310 let data = unsafe {
311 self.proxy
312 .send_constructor::<false>(2, &mut args, XdgPopup::WL_INTERFACE, None)
313 };
314 // SAFETY: data has the interface XdgPopup::WL_INTERFACE
315 unsafe { proxy::low_level::from_untyped_owned(data) }
316 }
317}
318
319#[allow(dead_code)]
320impl XdgSurfaceRef {
321 /// assign the xdg_toplevel surface role
322 ///
323 /// This creates an xdg_toplevel object for the given xdg_surface and gives
324 /// the associated wl_surface the xdg_toplevel role.
325 ///
326 /// See the documentation of xdg_toplevel for more details about what an
327 /// xdg_toplevel is and how it is used.
328 ///
329 /// # Arguments
330 ///
331 /// - `_queue`: The queue that the returned proxy is assigned to.
332 #[inline]
333 pub fn get_toplevel(&self, _queue: &Queue) -> XdgToplevel {
334 let mut args = [wl_argument { n: 0 }];
335 // SAFETY: - self.proxy has the interface INTERFACE
336 // - 1 < INTERFACE.method_count = 5
337 // - the request signature is `n`
338 // - OwnedProxy::WL_INTERFACE is always a valid interface
339 let data = unsafe {
340 self.proxy
341 .send_constructor(_queue, 1, &mut args, XdgToplevel::WL_INTERFACE, None)
342 };
343 // SAFETY: data has the interface XdgToplevel::WL_INTERFACE
344 unsafe { proxy::low_level::from_untyped_owned(data) }
345 }
346
347 /// assign the xdg_popup surface role
348 ///
349 /// This creates an xdg_popup object for the given xdg_surface and gives
350 /// the associated wl_surface the xdg_popup role.
351 ///
352 /// If null is passed as a parent, a parent surface must be specified using
353 /// some other protocol, before committing the initial state.
354 ///
355 /// See the documentation of xdg_popup for more details about what an
356 /// xdg_popup is and how it is used.
357 ///
358 /// # Arguments
359 ///
360 /// - `_queue`: The queue that the returned proxy is assigned to.
361 /// - `parent`:
362 /// - `positioner`:
363 #[inline]
364 pub fn get_popup(
365 &self,
366 _queue: &Queue,
367 parent: Option<&XdgSurfaceRef>,
368 positioner: &XdgPositionerRef,
369 ) -> XdgPopup {
370 let (arg1, arg2) = (parent, positioner);
371 let obj1_lock = arg1.map(|arg1| proxy::lock(arg1));
372 let obj1 = obj1_lock
373 .map(|obj1_lock| check_argument_proxy("parent", obj1_lock.wl_proxy()))
374 .unwrap_or(ptr::null_mut());
375 let obj2_lock = proxy::lock(arg2);
376 let obj2 = check_argument_proxy("positioner", obj2_lock.wl_proxy());
377 let mut args = [
378 wl_argument { n: 0 },
379 wl_argument { o: obj1 },
380 wl_argument { o: obj2 },
381 ];
382 // SAFETY: - self.proxy has the interface INTERFACE
383 // - 2 < INTERFACE.method_count = 5
384 // - the request signature is `n?oo`
385 // - OwnedProxy::WL_INTERFACE is always a valid interface
386 let data = unsafe {
387 self.proxy
388 .send_constructor(_queue, 2, &mut args, XdgPopup::WL_INTERFACE, None)
389 };
390 // SAFETY: data has the interface XdgPopup::WL_INTERFACE
391 unsafe { proxy::low_level::from_untyped_owned(data) }
392 }
393
394 /// set the new window geometry
395 ///
396 /// The window geometry of a surface is its "visible bounds" from the
397 /// user's perspective. Client-side decorations often have invisible
398 /// portions like drop-shadows which should be ignored for the
399 /// purposes of aligning, placing and constraining windows.
400 ///
401 /// The window geometry is double-buffered state, see wl_surface.commit.
402 ///
403 /// When maintaining a position, the compositor should treat the (x, y)
404 /// coordinate of the window geometry as the top left corner of the window.
405 /// A client changing the (x, y) window geometry coordinate should in
406 /// general not alter the position of the window.
407 ///
408 /// Once the window geometry of the surface is set, it is not possible to
409 /// unset it, and it will remain the same until set_window_geometry is
410 /// called again, even if a new subsurface or buffer is attached.
411 ///
412 /// If never set, the value is the full bounds of the surface,
413 /// including any subsurfaces. This updates dynamically on every
414 /// commit. This unset is meant for extremely simple clients.
415 ///
416 /// The arguments are given in the surface-local coordinate space of
417 /// the wl_surface associated with this xdg_surface, and may extend outside
418 /// of the wl_surface itself to mark parts of the subsurface tree as part of
419 /// the window geometry.
420 ///
421 /// When applied, the effective window geometry will be the set window
422 /// geometry clamped to the bounding rectangle of the combined
423 /// geometry of the surface of the xdg_surface and the associated
424 /// subsurfaces.
425 ///
426 /// The effective geometry will not be recalculated unless a new call to
427 /// set_window_geometry is done and the new pending surface state is
428 /// subsequently applied.
429 ///
430 /// The width and height of the effective window geometry must be
431 /// greater than zero. Setting an invalid size will raise an
432 /// invalid_size error.
433 ///
434 /// # Arguments
435 ///
436 /// - `x`:
437 /// - `y`:
438 /// - `width`:
439 /// - `height`:
440 #[inline]
441 pub fn set_window_geometry(&self, x: i32, y: i32, width: i32, height: i32) {
442 let (arg0, arg1, arg2, arg3) = (x, y, width, height);
443 let mut args = [
444 wl_argument { i: arg0 },
445 wl_argument { i: arg1 },
446 wl_argument { i: arg2 },
447 wl_argument { i: arg3 },
448 ];
449 // SAFETY: - self.proxy has the interface INTERFACE
450 // - 3 < INTERFACE.method_count = 5
451 // - the request signature is `iiii`
452 unsafe {
453 self.proxy.send_request(3, &mut args);
454 }
455 }
456
457 /// ack a configure event
458 ///
459 /// When a configure event is received, if a client commits the
460 /// surface in response to the configure event, then the client
461 /// must make an ack_configure request sometime before the commit
462 /// request, passing along the serial of the configure event.
463 ///
464 /// For instance, for toplevel surfaces the compositor might use this
465 /// information to move a surface to the top left only when the client has
466 /// drawn itself for the maximized or fullscreen state.
467 ///
468 /// If the client receives multiple configure events before it
469 /// can respond to one, it only has to ack the last configure event.
470 /// Acking a configure event that was never sent raises an invalid_serial
471 /// error.
472 ///
473 /// A client is not required to commit immediately after sending
474 /// an ack_configure request - it may even ack_configure several times
475 /// before its next surface commit.
476 ///
477 /// A client may send multiple ack_configure requests before committing, but
478 /// only the last request sent before a commit indicates which configure
479 /// event the client really is responding to.
480 ///
481 /// Sending an ack_configure request consumes the serial number sent with
482 /// the request, as well as serial numbers sent by all configure events
483 /// sent on this xdg_surface prior to the configure event referenced by
484 /// the committed serial.
485 ///
486 /// It is an error to issue multiple ack_configure requests referencing a
487 /// serial from the same configure event, or to issue an ack_configure
488 /// request referencing a serial from a configure event issued before the
489 /// event identified by the last ack_configure request for the same
490 /// xdg_surface. Doing so will raise an invalid_serial error.
491 ///
492 /// # Arguments
493 ///
494 /// - `serial`: the serial from the configure event
495 #[inline]
496 pub fn ack_configure(&self, serial: u32) {
497 let (arg0,) = (serial,);
498 let mut args = [wl_argument { u: arg0 }];
499 // SAFETY: - self.proxy has the interface INTERFACE
500 // - 4 < INTERFACE.method_count = 5
501 // - the request signature is `u`
502 unsafe {
503 self.proxy.send_request(4, &mut args);
504 }
505 }
506}
507
508impl XdgSurface {
509 /// Since when the configure event is available.
510 #[allow(dead_code)]
511 pub const EVT__CONFIGURE__SINCE: u32 = 1;
512}
513
514/// An event handler for [XdgSurface] proxies.
515#[allow(dead_code)]
516pub trait XdgSurfaceEventHandler {
517 type Data: 'static;
518
519 /// suggest a surface change
520 ///
521 /// The configure event marks the end of a configure sequence. A configure
522 /// sequence is a set of one or more events configuring the state of the
523 /// xdg_surface, including the final xdg_surface.configure event.
524 ///
525 /// Where applicable, xdg_surface surface roles will during a configure
526 /// sequence extend this event as a latched state sent as events before the
527 /// xdg_surface.configure event. Such events should be considered to make up
528 /// a set of atomically applied configuration states, where the
529 /// xdg_surface.configure commits the accumulated state.
530 ///
531 /// Clients should arrange their surface for the new states, and then send
532 /// an ack_configure request with the serial sent in this configure event at
533 /// some point before committing the new surface.
534 ///
535 /// If the client receives multiple configure events before it can respond
536 /// to one, it is free to discard all but the last event it received.
537 ///
538 /// # Arguments
539 ///
540 /// - `serial`: serial of the configure event
541 #[inline]
542 fn configure(&self, _data: &mut Self::Data, _slf: &XdgSurfaceRef, serial: u32) {
543 let _ = serial;
544 }
545}
546
547impl XdgSurfaceEventHandler for private::NoOpEventHandler {
548 type Data = ();
549}
550
551// SAFETY: - INTERFACE is a valid wl_interface
552// - mutable_type always returns the same value
553unsafe impl<H> EventHandler for private::EventHandler<H>
554where
555 H: XdgSurfaceEventHandler,
556{
557 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
558
559 #[inline]
560 fn mutable_type() -> Option<(TypeId, &'static str)> {
561 let id = TypeId::of::<H::Data>();
562 let name = std::any::type_name::<H::Data>();
563 Some((id, name))
564 }
565
566 #[allow(unused_variables)]
567 unsafe fn handle_event(
568 &self,
569 queue: &Queue,
570 data: *mut u8,
571 slf: &UntypedBorrowedProxy,
572 opcode: u32,
573 args: *mut wl_argument,
574 ) {
575 // SAFETY: This function requires that slf has the interface INTERFACE
576 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<XdgSurfaceRef>(slf) };
577 // SAFETY: This function requires that data is `&mut T` where `T`
578 // has the type id returned by `Self::mutable_type`, i.e.,
579 // `T = H::Data`.
580 let data: &mut H::Data = unsafe { &mut *data.cast() };
581 match opcode {
582 0 => {
583 // SAFETY: INTERFACE requires that there are 1 arguments
584 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
585 // SAFETY: - INTERFACE requires that args[0] contains a uint
586 let arg0 = unsafe { args[0].u };
587 self.0.configure(data, slf, arg0);
588 }
589 _ => {
590 invalid_opcode("xdg_surface", opcode);
591 }
592 }
593 }
594}
595
596impl<H> CreateEventHandler<H> for private::ProxyApi
597where
598 H: XdgSurfaceEventHandler,
599{
600 type EventHandler = private::EventHandler<H>;
601
602 #[inline]
603 fn create_event_handler(handler: H) -> Self::EventHandler {
604 private::EventHandler(handler)
605 }
606}
607
608impl XdgSurface {
609 /// Since when the error.not_constructed enum variant is available.
610 #[allow(dead_code)]
611 pub const ENM__ERROR_NOT_CONSTRUCTED__SINCE: u32 = 1;
612 /// Since when the error.already_constructed enum variant is available.
613 #[allow(dead_code)]
614 pub const ENM__ERROR_ALREADY_CONSTRUCTED__SINCE: u32 = 1;
615 /// Since when the error.unconfigured_buffer enum variant is available.
616 #[allow(dead_code)]
617 pub const ENM__ERROR_UNCONFIGURED_BUFFER__SINCE: u32 = 1;
618 /// Since when the error.invalid_serial enum variant is available.
619 #[allow(dead_code)]
620 pub const ENM__ERROR_INVALID_SERIAL__SINCE: u32 = 1;
621 /// Since when the error.invalid_size enum variant is available.
622 #[allow(dead_code)]
623 pub const ENM__ERROR_INVALID_SIZE__SINCE: u32 = 1;
624 /// Since when the error.defunct_role_object enum variant is available.
625 #[allow(dead_code)]
626 pub const ENM__ERROR_DEFUNCT_ROLE_OBJECT__SINCE: u32 = 1;
627}
628
629#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
630#[allow(dead_code)]
631pub struct XdgSurfaceError(pub u32);
632
633impl XdgSurfaceError {
634 /// Surface was not fully constructed
635 #[allow(dead_code)]
636 pub const NOT_CONSTRUCTED: Self = Self(1);
637
638 /// Surface was already constructed
639 #[allow(dead_code)]
640 pub const ALREADY_CONSTRUCTED: Self = Self(2);
641
642 /// Attaching a buffer to an unconfigured surface
643 #[allow(dead_code)]
644 pub const UNCONFIGURED_BUFFER: Self = Self(3);
645
646 /// Invalid serial number when acking a configure event
647 #[allow(dead_code)]
648 pub const INVALID_SERIAL: Self = Self(4);
649
650 /// Width or height was zero or negative
651 #[allow(dead_code)]
652 pub const INVALID_SIZE: Self = Self(5);
653
654 /// Surface was destroyed before its role object
655 #[allow(dead_code)]
656 pub const DEFUNCT_ROLE_OBJECT: Self = Self(6);
657}
658
659impl Debug for XdgSurfaceError {
660 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
661 let name = match *self {
662 Self::NOT_CONSTRUCTED => "NOT_CONSTRUCTED",
663 Self::ALREADY_CONSTRUCTED => "ALREADY_CONSTRUCTED",
664 Self::UNCONFIGURED_BUFFER => "UNCONFIGURED_BUFFER",
665 Self::INVALID_SERIAL => "INVALID_SERIAL",
666 Self::INVALID_SIZE => "INVALID_SIZE",
667 Self::DEFUNCT_ROLE_OBJECT => "DEFUNCT_ROLE_OBJECT",
668 _ => return Debug::fmt(&self.0, f),
669 };
670 f.write_str(name)
671 }
672}
673
674/// Functional event handlers.
675pub mod event_handlers {
676 use super::*;
677
678 /// Event handler for configure events.
679 pub struct Configure<T, F>(F, PhantomData<fn(&mut T)>);
680 impl<T, F> XdgSurfaceEventHandler for Configure<T, F>
681 where
682 T: 'static,
683 F: Fn(&mut T, &XdgSurfaceRef, u32),
684 {
685 type Data = T;
686
687 #[inline]
688 fn configure(&self, _data: &mut T, _slf: &XdgSurfaceRef, serial: u32) {
689 self.0(_data, _slf, serial)
690 }
691 }
692
693 impl XdgSurface {
694 /// Creates an event handler for configure events.
695 ///
696 /// The event handler ignores all other events.
697 #[allow(dead_code)]
698 pub fn on_configure<T, F>(f: F) -> Configure<T, F>
699 where
700 T: 'static,
701 F: Fn(&mut T, &XdgSurfaceRef, u32),
702 {
703 Configure(f, PhantomData)
704 }
705 }
706}