Skip to main content

get_registry/common/protocols_data/xdg_shell/
xdg_toplevel.rs

1//! toplevel surface
2//!
3//! This interface defines an xdg_surface role which allows a surface to,
4//! among other things, set window-like properties such as maximize,
5//! fullscreen, and minimize, set application-specific metadata like title and
6//! id, and well as trigger user interactive operations such as interactive
7//! resize and move.
8//!
9//! A xdg_toplevel by default is responsible for providing the full intended
10//! visual representation of the toplevel, which depending on the window
11//! state, may mean things like a title bar, window controls and drop shadow.
12//!
13//! Unmapping an xdg_toplevel means that the surface cannot be shown
14//! by the compositor until it is explicitly mapped again.
15//! All active operations (e.g., move, resize) are canceled and all
16//! attributes (e.g. title, state, stacking, ...) are discarded for
17//! an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to
18//! the state it had right after xdg_surface.get_toplevel. The client
19//! can re-map the toplevel by performing a commit without any buffer
20//! attached, waiting for a configure event and handling it as usual (see
21//! xdg_surface description).
22//!
23//! Attaching a null buffer to a toplevel unmaps the surface.
24
25use super::super::all_types::*;
26use ::wl_client::builder::prelude::*;
27
28static INTERFACE: wl_interface = wl_interface {
29    name: c"xdg_toplevel".as_ptr(),
30    version: 6,
31    method_count: 14,
32    methods: {
33        static MESSAGES: [wl_message; 14] = [
34            wl_message {
35                name: c"destroy".as_ptr(),
36                signature: c"".as_ptr(),
37                types: {
38                    static TYPES: [Option<&'static wl_interface>; 0] = [];
39                    TYPES.as_ptr().cast()
40                },
41            },
42            wl_message {
43                name: c"set_parent".as_ptr(),
44                signature: c"?o".as_ptr(),
45                types: {
46                    static TYPES: [Option<&'static wl_interface>; 1] =
47                        [Some(XdgToplevel::WL_INTERFACE)];
48                    TYPES.as_ptr().cast()
49                },
50            },
51            wl_message {
52                name: c"set_title".as_ptr(),
53                signature: c"s".as_ptr(),
54                types: {
55                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
56                    TYPES.as_ptr().cast()
57                },
58            },
59            wl_message {
60                name: c"set_app_id".as_ptr(),
61                signature: c"s".as_ptr(),
62                types: {
63                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
64                    TYPES.as_ptr().cast()
65                },
66            },
67            wl_message {
68                name: c"show_window_menu".as_ptr(),
69                signature: c"ouii".as_ptr(),
70                types: {
71                    static TYPES: [Option<&'static wl_interface>; 4] =
72                        [Some(WlSeat::WL_INTERFACE), None, None, None];
73                    TYPES.as_ptr().cast()
74                },
75            },
76            wl_message {
77                name: c"move".as_ptr(),
78                signature: c"ou".as_ptr(),
79                types: {
80                    static TYPES: [Option<&'static wl_interface>; 2] =
81                        [Some(WlSeat::WL_INTERFACE), None];
82                    TYPES.as_ptr().cast()
83                },
84            },
85            wl_message {
86                name: c"resize".as_ptr(),
87                signature: c"ouu".as_ptr(),
88                types: {
89                    static TYPES: [Option<&'static wl_interface>; 3] =
90                        [Some(WlSeat::WL_INTERFACE), None, None];
91                    TYPES.as_ptr().cast()
92                },
93            },
94            wl_message {
95                name: c"set_max_size".as_ptr(),
96                signature: c"ii".as_ptr(),
97                types: {
98                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
99                    TYPES.as_ptr().cast()
100                },
101            },
102            wl_message {
103                name: c"set_min_size".as_ptr(),
104                signature: c"ii".as_ptr(),
105                types: {
106                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
107                    TYPES.as_ptr().cast()
108                },
109            },
110            wl_message {
111                name: c"set_maximized".as_ptr(),
112                signature: c"".as_ptr(),
113                types: {
114                    static TYPES: [Option<&'static wl_interface>; 0] = [];
115                    TYPES.as_ptr().cast()
116                },
117            },
118            wl_message {
119                name: c"unset_maximized".as_ptr(),
120                signature: c"".as_ptr(),
121                types: {
122                    static TYPES: [Option<&'static wl_interface>; 0] = [];
123                    TYPES.as_ptr().cast()
124                },
125            },
126            wl_message {
127                name: c"set_fullscreen".as_ptr(),
128                signature: c"?o".as_ptr(),
129                types: {
130                    static TYPES: [Option<&'static wl_interface>; 1] =
131                        [Some(WlOutput::WL_INTERFACE)];
132                    TYPES.as_ptr().cast()
133                },
134            },
135            wl_message {
136                name: c"unset_fullscreen".as_ptr(),
137                signature: c"".as_ptr(),
138                types: {
139                    static TYPES: [Option<&'static wl_interface>; 0] = [];
140                    TYPES.as_ptr().cast()
141                },
142            },
143            wl_message {
144                name: c"set_minimized".as_ptr(),
145                signature: c"".as_ptr(),
146                types: {
147                    static TYPES: [Option<&'static wl_interface>; 0] = [];
148                    TYPES.as_ptr().cast()
149                },
150            },
151        ];
152        MESSAGES.as_ptr()
153    },
154    event_count: 4,
155    events: {
156        static MESSAGES: [wl_message; 4] = [
157            wl_message {
158                name: c"configure".as_ptr(),
159                signature: c"iia".as_ptr(),
160                types: {
161                    static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
162                    TYPES.as_ptr().cast()
163                },
164            },
165            wl_message {
166                name: c"close".as_ptr(),
167                signature: c"".as_ptr(),
168                types: {
169                    static TYPES: [Option<&'static wl_interface>; 0] = [];
170                    TYPES.as_ptr().cast()
171                },
172            },
173            wl_message {
174                name: c"configure_bounds".as_ptr(),
175                signature: c"ii".as_ptr(),
176                types: {
177                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
178                    TYPES.as_ptr().cast()
179                },
180            },
181            wl_message {
182                name: c"wm_capabilities".as_ptr(),
183                signature: c"a".as_ptr(),
184                types: {
185                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
186                    TYPES.as_ptr().cast()
187                },
188            },
189        ];
190        MESSAGES.as_ptr()
191    },
192};
193
194/// An owned xdg_toplevel proxy.
195///
196/// See the documentation of [the module][self] for the interface description.
197#[derive(Clone, Eq, PartialEq)]
198#[repr(transparent)]
199pub struct XdgToplevel {
200    /// This proxy has the interface INTERFACE.
201    proxy: UntypedOwnedProxy,
202}
203
204/// A borrowed xdg_toplevel proxy.
205///
206/// See the documentation of [the module][self] for the interface description.
207#[derive(Eq, PartialEq)]
208#[repr(transparent)]
209pub struct XdgToplevelRef {
210    /// This proxy has the interface INTERFACE.
211    proxy: UntypedBorrowedProxy,
212}
213
214// SAFETY: XdgToplevel is a transparent wrapper around UntypedOwnedProxy
215unsafe impl UntypedOwnedProxyWrapper for XdgToplevel {}
216
217// SAFETY: - INTERFACE is a valid wl_interface
218//         - The only invariant is that self.proxy has a compatible interface
219unsafe impl OwnedProxy for XdgToplevel {
220    const INTERFACE: &'static str = "xdg_toplevel";
221    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
222    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
223        private::EventHandler(private::NoOpEventHandler);
224    const MAX_VERSION: u32 = 6;
225
226    type Borrowed = XdgToplevelRef;
227    type Api = private::ProxyApi;
228    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
229}
230
231// SAFETY: XdgToplevelRef is a transparent wrapper around UntypedBorrowedProxy
232unsafe impl UntypedBorrowedProxyWrapper for XdgToplevelRef {}
233
234// SAFETY: - The only invariant is that self.proxy has a compatible interface
235unsafe impl BorrowedProxy for XdgToplevelRef {
236    type Owned = XdgToplevel;
237}
238
239impl Deref for XdgToplevel {
240    type Target = XdgToplevelRef;
241
242    fn deref(&self) -> &Self::Target {
243        proxy::low_level::deref(self)
244    }
245}
246
247mod private {
248    pub struct ProxyApi;
249
250    #[allow(dead_code)]
251    pub struct EventHandler<H>(pub(super) H);
252
253    #[allow(dead_code)]
254    pub struct NoOpEventHandler;
255}
256
257impl Debug for XdgToplevel {
258    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
259        write!(f, "xdg_toplevel#{}", self.proxy.id())
260    }
261}
262
263impl Debug for XdgToplevelRef {
264    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
265        write!(f, "xdg_toplevel#{}", self.proxy.id())
266    }
267}
268
269impl PartialEq<XdgToplevelRef> for XdgToplevel {
270    fn eq(&self, other: &XdgToplevelRef) -> bool {
271        self.proxy == other.proxy
272    }
273}
274
275impl PartialEq<XdgToplevel> for XdgToplevelRef {
276    fn eq(&self, other: &XdgToplevel) -> bool {
277        self.proxy == other.proxy
278    }
279}
280
281#[allow(dead_code)]
282impl XdgToplevel {
283    /// Since when the destroy request is available.
284    #[allow(dead_code)]
285    pub const REQ__DESTROY__SINCE: u32 = 1;
286
287    /// Since when the set_parent request is available.
288    #[allow(dead_code)]
289    pub const REQ__SET_PARENT__SINCE: u32 = 1;
290
291    /// Since when the set_title request is available.
292    #[allow(dead_code)]
293    pub const REQ__SET_TITLE__SINCE: u32 = 1;
294
295    /// Since when the set_app_id request is available.
296    #[allow(dead_code)]
297    pub const REQ__SET_APP_ID__SINCE: u32 = 1;
298
299    /// Since when the show_window_menu request is available.
300    #[allow(dead_code)]
301    pub const REQ__SHOW_WINDOW_MENU__SINCE: u32 = 1;
302
303    /// Since when the move request is available.
304    #[allow(dead_code)]
305    pub const REQ__MOVE__SINCE: u32 = 1;
306
307    /// Since when the resize request is available.
308    #[allow(dead_code)]
309    pub const REQ__RESIZE__SINCE: u32 = 1;
310
311    /// Since when the set_max_size request is available.
312    #[allow(dead_code)]
313    pub const REQ__SET_MAX_SIZE__SINCE: u32 = 1;
314
315    /// Since when the set_min_size request is available.
316    #[allow(dead_code)]
317    pub const REQ__SET_MIN_SIZE__SINCE: u32 = 1;
318
319    /// Since when the set_maximized request is available.
320    #[allow(dead_code)]
321    pub const REQ__SET_MAXIMIZED__SINCE: u32 = 1;
322
323    /// Since when the unset_maximized request is available.
324    #[allow(dead_code)]
325    pub const REQ__UNSET_MAXIMIZED__SINCE: u32 = 1;
326
327    /// Since when the set_fullscreen request is available.
328    #[allow(dead_code)]
329    pub const REQ__SET_FULLSCREEN__SINCE: u32 = 1;
330
331    /// Since when the unset_fullscreen request is available.
332    #[allow(dead_code)]
333    pub const REQ__UNSET_FULLSCREEN__SINCE: u32 = 1;
334
335    /// Since when the set_minimized request is available.
336    #[allow(dead_code)]
337    pub const REQ__SET_MINIMIZED__SINCE: u32 = 1;
338}
339
340#[allow(dead_code)]
341impl XdgToplevel {
342    /// destroy the xdg_toplevel
343    ///
344    /// This request destroys the role surface and unmaps the surface;
345    /// see "Unmapping" behavior in interface section for details.
346    #[inline]
347    pub fn destroy(&self) {
348        let mut args = [];
349        // SAFETY: - self.proxy has the interface INTERFACE
350        //         - 0 < INTERFACE.method_count = 14
351        //         - the request signature is ``
352        unsafe {
353            self.proxy.send_destructor(0, &mut args);
354        }
355    }
356}
357
358#[allow(dead_code)]
359impl XdgToplevelRef {
360    /// set the parent of this surface
361    ///
362    /// Set the "parent" of this surface. This surface should be stacked
363    /// above the parent surface and all other ancestor surfaces.
364    ///
365    /// Parent surfaces should be set on dialogs, toolboxes, or other
366    /// "auxiliary" surfaces, so that the parent is raised when the dialog
367    /// is raised.
368    ///
369    /// Setting a null parent for a child surface unsets its parent. Setting
370    /// a null parent for a surface which currently has no parent is a no-op.
371    ///
372    /// Only mapped surfaces can have child surfaces. Setting a parent which
373    /// is not mapped is equivalent to setting a null parent. If a surface
374    /// becomes unmapped, its children's parent is set to the parent of
375    /// the now-unmapped surface. If the now-unmapped surface has no parent,
376    /// its children's parent is unset. If the now-unmapped surface becomes
377    /// mapped again, its parent-child relationship is not restored.
378    ///
379    /// The parent toplevel must not be one of the child toplevel's
380    /// descendants, and the parent must be different from the child toplevel,
381    /// otherwise the invalid_parent protocol error is raised.
382    ///
383    /// # Arguments
384    ///
385    /// - `parent`:
386    #[inline]
387    pub fn set_parent(&self, parent: Option<&XdgToplevelRef>) {
388        let (arg0,) = (parent,);
389        let obj0_lock = arg0.map(|arg0| proxy::lock(arg0));
390        let obj0 = obj0_lock
391            .map(|obj0_lock| check_argument_proxy("parent", obj0_lock.wl_proxy()))
392            .unwrap_or(ptr::null_mut());
393        let mut args = [wl_argument { o: obj0 }];
394        // SAFETY: - self.proxy has the interface INTERFACE
395        //         - 1 < INTERFACE.method_count = 14
396        //         - the request signature is `?o`
397        unsafe {
398            self.proxy.send_request(1, &mut args);
399        }
400    }
401
402    /// set surface title
403    ///
404    /// Set a short title for the surface.
405    ///
406    /// This string may be used to identify the surface in a task bar,
407    /// window list, or other user interface elements provided by the
408    /// compositor.
409    ///
410    /// The string must be encoded in UTF-8.
411    ///
412    /// # Arguments
413    ///
414    /// - `title`:
415    #[inline]
416    pub fn set_title(&self, title: &str) {
417        let (arg0,) = (title,);
418        with_cstr_cache(|cache| {
419            let str0_offset = cache.len();
420            cache.extend_from_slice(arg0.as_bytes());
421            cache.push(0);
422            let str0 = cache[str0_offset..].as_ptr().cast();
423            let mut args = [wl_argument { s: str0 }];
424            // SAFETY: - self.proxy has the interface INTERFACE
425            //         - 2 < INTERFACE.method_count = 14
426            //         - the request signature is `s`
427            unsafe {
428                self.proxy.send_request(2, &mut args);
429            }
430        })
431    }
432
433    /// set application ID
434    ///
435    /// Set an application identifier for the surface.
436    ///
437    /// The app ID identifies the general class of applications to which
438    /// the surface belongs. The compositor can use this to group multiple
439    /// surfaces together, or to determine how to launch a new application.
440    ///
441    /// For D-Bus activatable applications, the app ID is used as the D-Bus
442    /// service name.
443    ///
444    /// The compositor shell will try to group application surfaces together
445    /// by their app ID. As a best practice, it is suggested to select app
446    /// ID's that match the basename of the application's .desktop file.
447    /// For example, "org.freedesktop.FooViewer" where the .desktop file is
448    /// "org.freedesktop.FooViewer.desktop".
449    ///
450    /// Like other properties, a set_app_id request can be sent after the
451    /// xdg_toplevel has been mapped to update the property.
452    ///
453    /// See the desktop-entry specification [0] for more details on
454    /// application identifiers and how they relate to well-known D-Bus
455    /// names and .desktop files.
456    ///
457    /// [0] https://standards.freedesktop.org/desktop-entry-spec/
458    ///
459    /// # Arguments
460    ///
461    /// - `app_id`:
462    #[inline]
463    pub fn set_app_id(&self, app_id: &str) {
464        let (arg0,) = (app_id,);
465        with_cstr_cache(|cache| {
466            let str0_offset = cache.len();
467            cache.extend_from_slice(arg0.as_bytes());
468            cache.push(0);
469            let str0 = cache[str0_offset..].as_ptr().cast();
470            let mut args = [wl_argument { s: str0 }];
471            // SAFETY: - self.proxy has the interface INTERFACE
472            //         - 3 < INTERFACE.method_count = 14
473            //         - the request signature is `s`
474            unsafe {
475                self.proxy.send_request(3, &mut args);
476            }
477        })
478    }
479
480    /// show the window menu
481    ///
482    /// Clients implementing client-side decorations might want to show
483    /// a context menu when right-clicking on the decorations, giving the
484    /// user a menu that they can use to maximize or minimize the window.
485    ///
486    /// This request asks the compositor to pop up such a window menu at
487    /// the given position, relative to the local surface coordinates of
488    /// the parent surface. There are no guarantees as to what menu items
489    /// the window menu contains, or even if a window menu will be drawn
490    /// at all.
491    ///
492    /// This request must be used in response to some sort of user action
493    /// like a button press, key press, or touch down event.
494    ///
495    /// # Arguments
496    ///
497    /// - `seat`: the wl_seat of the user event
498    /// - `serial`: the serial of the user event
499    /// - `x`: the x position to pop up the window menu at
500    /// - `y`: the y position to pop up the window menu at
501    #[inline]
502    pub fn show_window_menu(&self, seat: &WlSeatRef, serial: u32, x: i32, y: i32) {
503        let (arg0, arg1, arg2, arg3) = (seat, serial, x, y);
504        let obj0_lock = proxy::lock(arg0);
505        let obj0 = check_argument_proxy("seat", obj0_lock.wl_proxy());
506        let mut args = [
507            wl_argument { o: obj0 },
508            wl_argument { u: arg1 },
509            wl_argument { i: arg2 },
510            wl_argument { i: arg3 },
511        ];
512        // SAFETY: - self.proxy has the interface INTERFACE
513        //         - 4 < INTERFACE.method_count = 14
514        //         - the request signature is `ouii`
515        unsafe {
516            self.proxy.send_request(4, &mut args);
517        }
518    }
519
520    /// start an interactive move
521    ///
522    /// Start an interactive, user-driven move of the surface.
523    ///
524    /// This request must be used in response to some sort of user action
525    /// like a button press, key press, or touch down event. The passed
526    /// serial is used to determine the type of interactive move (touch,
527    /// pointer, etc).
528    ///
529    /// The server may ignore move requests depending on the state of
530    /// the surface (e.g. fullscreen or maximized), or if the passed serial
531    /// is no longer valid.
532    ///
533    /// If triggered, the surface will lose the focus of the device
534    /// (wl_pointer, wl_touch, etc) used for the move. It is up to the
535    /// compositor to visually indicate that the move is taking place, such as
536    /// updating a pointer cursor, during the move. There is no guarantee
537    /// that the device focus will return when the move is completed.
538    ///
539    /// # Arguments
540    ///
541    /// - `seat`: the wl_seat of the user event
542    /// - `serial`: the serial of the user event
543    #[inline]
544    pub fn r#move(&self, seat: &WlSeatRef, serial: u32) {
545        let (arg0, arg1) = (seat, serial);
546        let obj0_lock = proxy::lock(arg0);
547        let obj0 = check_argument_proxy("seat", obj0_lock.wl_proxy());
548        let mut args = [wl_argument { o: obj0 }, wl_argument { u: arg1 }];
549        // SAFETY: - self.proxy has the interface INTERFACE
550        //         - 5 < INTERFACE.method_count = 14
551        //         - the request signature is `ou`
552        unsafe {
553            self.proxy.send_request(5, &mut args);
554        }
555    }
556
557    /// start an interactive resize
558    ///
559    /// Start a user-driven, interactive resize of the surface.
560    ///
561    /// This request must be used in response to some sort of user action
562    /// like a button press, key press, or touch down event. The passed
563    /// serial is used to determine the type of interactive resize (touch,
564    /// pointer, etc).
565    ///
566    /// The server may ignore resize requests depending on the state of
567    /// the surface (e.g. fullscreen or maximized).
568    ///
569    /// If triggered, the client will receive configure events with the
570    /// "resize" state enum value and the expected sizes. See the "resize"
571    /// enum value for more details about what is required. The client
572    /// must also acknowledge configure events using "ack_configure". After
573    /// the resize is completed, the client will receive another "configure"
574    /// event without the resize state.
575    ///
576    /// If triggered, the surface also will lose the focus of the device
577    /// (wl_pointer, wl_touch, etc) used for the resize. It is up to the
578    /// compositor to visually indicate that the resize is taking place,
579    /// such as updating a pointer cursor, during the resize. There is no
580    /// guarantee that the device focus will return when the resize is
581    /// completed.
582    ///
583    /// The edges parameter specifies how the surface should be resized, and
584    /// is one of the values of the resize_edge enum. Values not matching
585    /// a variant of the enum will cause the invalid_resize_edge protocol error.
586    /// The compositor may use this information to update the surface position
587    /// for example when dragging the top left corner. The compositor may also
588    /// use this information to adapt its behavior, e.g. choose an appropriate
589    /// cursor image.
590    ///
591    /// # Arguments
592    ///
593    /// - `seat`: the wl_seat of the user event
594    /// - `serial`: the serial of the user event
595    /// - `edges`: which edge or corner is being dragged
596    #[inline]
597    pub fn resize(&self, seat: &WlSeatRef, serial: u32, edges: XdgToplevelResizeEdge) {
598        let (arg0, arg1, arg2) = (seat, serial, edges);
599        let obj0_lock = proxy::lock(arg0);
600        let obj0 = check_argument_proxy("seat", obj0_lock.wl_proxy());
601        let mut args = [
602            wl_argument { o: obj0 },
603            wl_argument { u: arg1 },
604            wl_argument { u: arg2.0 },
605        ];
606        // SAFETY: - self.proxy has the interface INTERFACE
607        //         - 6 < INTERFACE.method_count = 14
608        //         - the request signature is `ouu`
609        unsafe {
610            self.proxy.send_request(6, &mut args);
611        }
612    }
613
614    /// set the maximum size
615    ///
616    /// Set a maximum size for the window.
617    ///
618    /// The client can specify a maximum size so that the compositor does
619    /// not try to configure the window beyond this size.
620    ///
621    /// The width and height arguments are in window geometry coordinates.
622    /// See xdg_surface.set_window_geometry.
623    ///
624    /// Values set in this way are double-buffered, see wl_surface.commit.
625    ///
626    /// The compositor can use this information to allow or disallow
627    /// different states like maximize or fullscreen and draw accurate
628    /// animations.
629    ///
630    /// Similarly, a tiling window manager may use this information to
631    /// place and resize client windows in a more effective way.
632    ///
633    /// The client should not rely on the compositor to obey the maximum
634    /// size. The compositor may decide to ignore the values set by the
635    /// client and request a larger size.
636    ///
637    /// If never set, or a value of zero in the request, means that the
638    /// client has no expected maximum size in the given dimension.
639    /// As a result, a client wishing to reset the maximum size
640    /// to an unspecified state can use zero for width and height in the
641    /// request.
642    ///
643    /// Requesting a maximum size to be smaller than the minimum size of
644    /// a surface is illegal and will result in an invalid_size error.
645    ///
646    /// The width and height must be greater than or equal to zero. Using
647    /// strictly negative values for width or height will result in a
648    /// invalid_size error.
649    ///
650    /// # Arguments
651    ///
652    /// - `width`:
653    /// - `height`:
654    #[inline]
655    pub fn set_max_size(&self, width: i32, height: i32) {
656        let (arg0, arg1) = (width, height);
657        let mut args = [wl_argument { i: arg0 }, wl_argument { i: arg1 }];
658        // SAFETY: - self.proxy has the interface INTERFACE
659        //         - 7 < INTERFACE.method_count = 14
660        //         - the request signature is `ii`
661        unsafe {
662            self.proxy.send_request(7, &mut args);
663        }
664    }
665
666    /// set the minimum size
667    ///
668    /// Set a minimum size for the window.
669    ///
670    /// The client can specify a minimum size so that the compositor does
671    /// not try to configure the window below this size.
672    ///
673    /// The width and height arguments are in window geometry coordinates.
674    /// See xdg_surface.set_window_geometry.
675    ///
676    /// Values set in this way are double-buffered, see wl_surface.commit.
677    ///
678    /// The compositor can use this information to allow or disallow
679    /// different states like maximize or fullscreen and draw accurate
680    /// animations.
681    ///
682    /// Similarly, a tiling window manager may use this information to
683    /// place and resize client windows in a more effective way.
684    ///
685    /// The client should not rely on the compositor to obey the minimum
686    /// size. The compositor may decide to ignore the values set by the
687    /// client and request a smaller size.
688    ///
689    /// If never set, or a value of zero in the request, means that the
690    /// client has no expected minimum size in the given dimension.
691    /// As a result, a client wishing to reset the minimum size
692    /// to an unspecified state can use zero for width and height in the
693    /// request.
694    ///
695    /// Requesting a minimum size to be larger than the maximum size of
696    /// a surface is illegal and will result in an invalid_size error.
697    ///
698    /// The width and height must be greater than or equal to zero. Using
699    /// strictly negative values for width and height will result in a
700    /// invalid_size error.
701    ///
702    /// # Arguments
703    ///
704    /// - `width`:
705    /// - `height`:
706    #[inline]
707    pub fn set_min_size(&self, width: i32, height: i32) {
708        let (arg0, arg1) = (width, height);
709        let mut args = [wl_argument { i: arg0 }, wl_argument { i: arg1 }];
710        // SAFETY: - self.proxy has the interface INTERFACE
711        //         - 8 < INTERFACE.method_count = 14
712        //         - the request signature is `ii`
713        unsafe {
714            self.proxy.send_request(8, &mut args);
715        }
716    }
717
718    /// maximize the window
719    ///
720    /// Maximize the surface.
721    ///
722    /// After requesting that the surface should be maximized, the compositor
723    /// will respond by emitting a configure event. Whether this configure
724    /// actually sets the window maximized is subject to compositor policies.
725    /// The client must then update its content, drawing in the configured
726    /// state. The client must also acknowledge the configure when committing
727    /// the new content (see ack_configure).
728    ///
729    /// It is up to the compositor to decide how and where to maximize the
730    /// surface, for example which output and what region of the screen should
731    /// be used.
732    ///
733    /// If the surface was already maximized, the compositor will still emit
734    /// a configure event with the "maximized" state.
735    ///
736    /// If the surface is in a fullscreen state, this request has no direct
737    /// effect. It may alter the state the surface is returned to when
738    /// unmaximized unless overridden by the compositor.
739    #[inline]
740    pub fn set_maximized(&self) {
741        let mut args = [];
742        // SAFETY: - self.proxy has the interface INTERFACE
743        //         - 9 < INTERFACE.method_count = 14
744        //         - the request signature is ``
745        unsafe {
746            self.proxy.send_request(9, &mut args);
747        }
748    }
749
750    /// unmaximize the window
751    ///
752    /// Unmaximize the surface.
753    ///
754    /// After requesting that the surface should be unmaximized, the compositor
755    /// will respond by emitting a configure event. Whether this actually
756    /// un-maximizes the window is subject to compositor policies.
757    /// If available and applicable, the compositor will include the window
758    /// geometry dimensions the window had prior to being maximized in the
759    /// configure event. The client must then update its content, drawing it in
760    /// the configured state. The client must also acknowledge the configure
761    /// when committing the new content (see ack_configure).
762    ///
763    /// It is up to the compositor to position the surface after it was
764    /// unmaximized; usually the position the surface had before maximizing, if
765    /// applicable.
766    ///
767    /// If the surface was already not maximized, the compositor will still
768    /// emit a configure event without the "maximized" state.
769    ///
770    /// If the surface is in a fullscreen state, this request has no direct
771    /// effect. It may alter the state the surface is returned to when
772    /// unmaximized unless overridden by the compositor.
773    #[inline]
774    pub fn unset_maximized(&self) {
775        let mut args = [];
776        // SAFETY: - self.proxy has the interface INTERFACE
777        //         - 10 < INTERFACE.method_count = 14
778        //         - the request signature is ``
779        unsafe {
780            self.proxy.send_request(10, &mut args);
781        }
782    }
783
784    /// set the window as fullscreen on an output
785    ///
786    /// Make the surface fullscreen.
787    ///
788    /// After requesting that the surface should be fullscreened, the
789    /// compositor will respond by emitting a configure event. Whether the
790    /// client is actually put into a fullscreen state is subject to compositor
791    /// policies. The client must also acknowledge the configure when
792    /// committing the new content (see ack_configure).
793    ///
794    /// The output passed by the request indicates the client's preference as
795    /// to which display it should be set fullscreen on. If this value is NULL,
796    /// it's up to the compositor to choose which display will be used to map
797    /// this surface.
798    ///
799    /// If the surface doesn't cover the whole output, the compositor will
800    /// position the surface in the center of the output and compensate with
801    /// with border fill covering the rest of the output. The content of the
802    /// border fill is undefined, but should be assumed to be in some way that
803    /// attempts to blend into the surrounding area (e.g. solid black).
804    ///
805    /// If the fullscreened surface is not opaque, the compositor must make
806    /// sure that other screen content not part of the same surface tree (made
807    /// up of subsurfaces, popups or similarly coupled surfaces) are not
808    /// visible below the fullscreened surface.
809    ///
810    /// # Arguments
811    ///
812    /// - `output`:
813    #[inline]
814    pub fn set_fullscreen(&self, output: Option<&WlOutputRef>) {
815        let (arg0,) = (output,);
816        let obj0_lock = arg0.map(|arg0| proxy::lock(arg0));
817        let obj0 = obj0_lock
818            .map(|obj0_lock| check_argument_proxy("output", obj0_lock.wl_proxy()))
819            .unwrap_or(ptr::null_mut());
820        let mut args = [wl_argument { o: obj0 }];
821        // SAFETY: - self.proxy has the interface INTERFACE
822        //         - 11 < INTERFACE.method_count = 14
823        //         - the request signature is `?o`
824        unsafe {
825            self.proxy.send_request(11, &mut args);
826        }
827    }
828
829    /// unset the window as fullscreen
830    ///
831    /// Make the surface no longer fullscreen.
832    ///
833    /// After requesting that the surface should be unfullscreened, the
834    /// compositor will respond by emitting a configure event.
835    /// Whether this actually removes the fullscreen state of the client is
836    /// subject to compositor policies.
837    ///
838    /// Making a surface unfullscreen sets states for the surface based on the following:
839    /// * the state(s) it may have had before becoming fullscreen
840    /// * any state(s) decided by the compositor
841    /// * any state(s) requested by the client while the surface was fullscreen
842    ///
843    /// The compositor may include the previous window geometry dimensions in
844    /// the configure event, if applicable.
845    ///
846    /// The client must also acknowledge the configure when committing the new
847    /// content (see ack_configure).
848    #[inline]
849    pub fn unset_fullscreen(&self) {
850        let mut args = [];
851        // SAFETY: - self.proxy has the interface INTERFACE
852        //         - 12 < INTERFACE.method_count = 14
853        //         - the request signature is ``
854        unsafe {
855            self.proxy.send_request(12, &mut args);
856        }
857    }
858
859    /// set the window as minimized
860    ///
861    /// Request that the compositor minimize your surface. There is no
862    /// way to know if the surface is currently minimized, nor is there
863    /// any way to unset minimization on this surface.
864    ///
865    /// If you are looking to throttle redrawing when minimized, please
866    /// instead use the wl_surface.frame event for this, as this will
867    /// also work with live previews on windows in Alt-Tab, Expose or
868    /// similar compositor features.
869    #[inline]
870    pub fn set_minimized(&self) {
871        let mut args = [];
872        // SAFETY: - self.proxy has the interface INTERFACE
873        //         - 13 < INTERFACE.method_count = 14
874        //         - the request signature is ``
875        unsafe {
876            self.proxy.send_request(13, &mut args);
877        }
878    }
879}
880
881impl XdgToplevel {
882    /// Since when the configure event is available.
883    #[allow(dead_code)]
884    pub const EVT__CONFIGURE__SINCE: u32 = 1;
885
886    /// Since when the close event is available.
887    #[allow(dead_code)]
888    pub const EVT__CLOSE__SINCE: u32 = 1;
889
890    /// Since when the configure_bounds event is available.
891    #[allow(dead_code)]
892    pub const EVT__CONFIGURE_BOUNDS__SINCE: u32 = 4;
893
894    /// Since when the wm_capabilities event is available.
895    #[allow(dead_code)]
896    pub const EVT__WM_CAPABILITIES__SINCE: u32 = 5;
897}
898
899/// An event handler for [XdgToplevel] proxies.
900#[allow(dead_code)]
901pub trait XdgToplevelEventHandler {
902    type Data: 'static;
903
904    /// suggest a surface change
905    ///
906    /// This configure event asks the client to resize its toplevel surface or
907    /// to change its state. The configured state should not be applied
908    /// immediately. See xdg_surface.configure for details.
909    ///
910    /// The width and height arguments specify a hint to the window
911    /// about how its surface should be resized in window geometry
912    /// coordinates. See set_window_geometry.
913    ///
914    /// If the width or height arguments are zero, it means the client
915    /// should decide its own window dimension. This may happen when the
916    /// compositor needs to configure the state of the surface but doesn't
917    /// have any information about any previous or expected dimension.
918    ///
919    /// The states listed in the event specify how the width/height
920    /// arguments should be interpreted, and possibly how it should be
921    /// drawn.
922    ///
923    /// Clients must send an ack_configure in response to this event. See
924    /// xdg_surface.configure and xdg_surface.ack_configure for details.
925    ///
926    /// # Arguments
927    ///
928    /// - `width`:
929    /// - `height`:
930    /// - `states`:
931    #[inline]
932    fn configure(
933        &self,
934        _data: &mut Self::Data,
935        _slf: &XdgToplevelRef,
936        width: i32,
937        height: i32,
938        states: &[u8],
939    ) {
940        let _ = width;
941        let _ = height;
942        let _ = states;
943    }
944
945    /// surface wants to be closed
946    ///
947    /// The close event is sent by the compositor when the user
948    /// wants the surface to be closed. This should be equivalent to
949    /// the user clicking the close button in client-side decorations,
950    /// if your application has any.
951    ///
952    /// This is only a request that the user intends to close the
953    /// window. The client may choose to ignore this request, or show
954    /// a dialog to ask the user to save their data, etc.
955    #[inline]
956    fn close(&self, _data: &mut Self::Data, _slf: &XdgToplevelRef) {}
957
958    /// recommended window geometry bounds
959    ///
960    /// The configure_bounds event may be sent prior to a xdg_toplevel.configure
961    /// event to communicate the bounds a window geometry size is recommended
962    /// to constrain to.
963    ///
964    /// The passed width and height are in surface coordinate space. If width
965    /// and height are 0, it means bounds is unknown and equivalent to as if no
966    /// configure_bounds event was ever sent for this surface.
967    ///
968    /// The bounds can for example correspond to the size of a monitor excluding
969    /// any panels or other shell components, so that a surface isn't created in
970    /// a way that it cannot fit.
971    ///
972    /// The bounds may change at any point, and in such a case, a new
973    /// xdg_toplevel.configure_bounds will be sent, followed by
974    /// xdg_toplevel.configure and xdg_surface.configure.
975    ///
976    /// # Arguments
977    ///
978    /// - `width`:
979    /// - `height`:
980    #[inline]
981    fn configure_bounds(
982        &self,
983        _data: &mut Self::Data,
984        _slf: &XdgToplevelRef,
985        width: i32,
986        height: i32,
987    ) {
988        let _ = width;
989        let _ = height;
990    }
991
992    /// compositor capabilities
993    ///
994    /// This event advertises the capabilities supported by the compositor. If
995    /// a capability isn't supported, clients should hide or disable the UI
996    /// elements that expose this functionality. For instance, if the
997    /// compositor doesn't advertise support for minimized toplevels, a button
998    /// triggering the set_minimized request should not be displayed.
999    ///
1000    /// The compositor will ignore requests it doesn't support. For instance,
1001    /// a compositor which doesn't advertise support for minimized will ignore
1002    /// set_minimized requests.
1003    ///
1004    /// Compositors must send this event once before the first
1005    /// xdg_surface.configure event. When the capabilities change, compositors
1006    /// must send this event again and then send an xdg_surface.configure
1007    /// event.
1008    ///
1009    /// The configured state should not be applied immediately. See
1010    /// xdg_surface.configure for details.
1011    ///
1012    /// The capabilities are sent as an array of 32-bit unsigned integers in
1013    /// native endianness.
1014    ///
1015    /// # Arguments
1016    ///
1017    /// - `capabilities`: array of 32-bit capabilities
1018    #[inline]
1019    fn wm_capabilities(&self, _data: &mut Self::Data, _slf: &XdgToplevelRef, capabilities: &[u8]) {
1020        let _ = capabilities;
1021    }
1022}
1023
1024impl XdgToplevelEventHandler for private::NoOpEventHandler {
1025    type Data = ();
1026}
1027
1028// SAFETY: - INTERFACE is a valid wl_interface
1029//         - mutable_type always returns the same value
1030unsafe impl<H> EventHandler for private::EventHandler<H>
1031where
1032    H: XdgToplevelEventHandler,
1033{
1034    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
1035
1036    #[inline]
1037    fn mutable_type() -> Option<(TypeId, &'static str)> {
1038        let id = TypeId::of::<H::Data>();
1039        let name = std::any::type_name::<H::Data>();
1040        Some((id, name))
1041    }
1042
1043    #[allow(unused_variables)]
1044    unsafe fn handle_event(
1045        &self,
1046        queue: &Queue,
1047        data: *mut u8,
1048        slf: &UntypedBorrowedProxy,
1049        opcode: u32,
1050        args: *mut wl_argument,
1051    ) {
1052        // SAFETY: This function requires that slf has the interface INTERFACE
1053        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<XdgToplevelRef>(slf) };
1054        // SAFETY: This function requires that data is `&mut T` where `T`
1055        //         has the type id returned by `Self::mutable_type`, i.e.,
1056        //         `T = H::Data`.
1057        let data: &mut H::Data = unsafe { &mut *data.cast() };
1058        match opcode {
1059            0 => {
1060                // SAFETY: INTERFACE requires that there are 3 arguments
1061                let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
1062                // SAFETY: - INTERFACE requires that args[0] contains an int
1063                let arg0 = unsafe { args[0].i };
1064                // SAFETY: - INTERFACE requires that args[1] contains an int
1065                let arg1 = unsafe { args[1].i };
1066                // SAFETY: - INTERFACE requires that args[2] contains an array
1067                let arg2 = unsafe {
1068                    let a = &*args[2].a;
1069                    std::slice::from_raw_parts(a.data.cast(), a.size)
1070                };
1071                self.0.configure(data, slf, arg0, arg1, arg2);
1072            }
1073            1 => {
1074                self.0.close(data, slf);
1075            }
1076            2 => {
1077                // SAFETY: INTERFACE requires that there are 2 arguments
1078                let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
1079                // SAFETY: - INTERFACE requires that args[0] contains an int
1080                let arg0 = unsafe { args[0].i };
1081                // SAFETY: - INTERFACE requires that args[1] contains an int
1082                let arg1 = unsafe { args[1].i };
1083                self.0.configure_bounds(data, slf, arg0, arg1);
1084            }
1085            3 => {
1086                // SAFETY: INTERFACE requires that there are 1 arguments
1087                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
1088                // SAFETY: - INTERFACE requires that args[0] contains an array
1089                let arg0 = unsafe {
1090                    let a = &*args[0].a;
1091                    std::slice::from_raw_parts(a.data.cast(), a.size)
1092                };
1093                self.0.wm_capabilities(data, slf, arg0);
1094            }
1095            _ => {
1096                invalid_opcode("xdg_toplevel", opcode);
1097            }
1098        }
1099    }
1100}
1101
1102impl<H> CreateEventHandler<H> for private::ProxyApi
1103where
1104    H: XdgToplevelEventHandler,
1105{
1106    type EventHandler = private::EventHandler<H>;
1107
1108    #[inline]
1109    fn create_event_handler(handler: H) -> Self::EventHandler {
1110        private::EventHandler(handler)
1111    }
1112}
1113
1114impl XdgToplevel {
1115    /// Since when the error.invalid_resize_edge enum variant is available.
1116    #[allow(dead_code)]
1117    pub const ENM__ERROR_INVALID_RESIZE_EDGE__SINCE: u32 = 1;
1118    /// Since when the error.invalid_parent enum variant is available.
1119    #[allow(dead_code)]
1120    pub const ENM__ERROR_INVALID_PARENT__SINCE: u32 = 1;
1121    /// Since when the error.invalid_size enum variant is available.
1122    #[allow(dead_code)]
1123    pub const ENM__ERROR_INVALID_SIZE__SINCE: u32 = 1;
1124
1125    /// Since when the resize_edge.none enum variant is available.
1126    #[allow(dead_code)]
1127    pub const ENM__RESIZE_EDGE_NONE__SINCE: u32 = 1;
1128    /// Since when the resize_edge.top enum variant is available.
1129    #[allow(dead_code)]
1130    pub const ENM__RESIZE_EDGE_TOP__SINCE: u32 = 1;
1131    /// Since when the resize_edge.bottom enum variant is available.
1132    #[allow(dead_code)]
1133    pub const ENM__RESIZE_EDGE_BOTTOM__SINCE: u32 = 1;
1134    /// Since when the resize_edge.left enum variant is available.
1135    #[allow(dead_code)]
1136    pub const ENM__RESIZE_EDGE_LEFT__SINCE: u32 = 1;
1137    /// Since when the resize_edge.top_left enum variant is available.
1138    #[allow(dead_code)]
1139    pub const ENM__RESIZE_EDGE_TOP_LEFT__SINCE: u32 = 1;
1140    /// Since when the resize_edge.bottom_left enum variant is available.
1141    #[allow(dead_code)]
1142    pub const ENM__RESIZE_EDGE_BOTTOM_LEFT__SINCE: u32 = 1;
1143    /// Since when the resize_edge.right enum variant is available.
1144    #[allow(dead_code)]
1145    pub const ENM__RESIZE_EDGE_RIGHT__SINCE: u32 = 1;
1146    /// Since when the resize_edge.top_right enum variant is available.
1147    #[allow(dead_code)]
1148    pub const ENM__RESIZE_EDGE_TOP_RIGHT__SINCE: u32 = 1;
1149    /// Since when the resize_edge.bottom_right enum variant is available.
1150    #[allow(dead_code)]
1151    pub const ENM__RESIZE_EDGE_BOTTOM_RIGHT__SINCE: u32 = 1;
1152
1153    /// Since when the state.maximized enum variant is available.
1154    #[allow(dead_code)]
1155    pub const ENM__STATE_MAXIMIZED__SINCE: u32 = 1;
1156    /// Since when the state.fullscreen enum variant is available.
1157    #[allow(dead_code)]
1158    pub const ENM__STATE_FULLSCREEN__SINCE: u32 = 1;
1159    /// Since when the state.resizing enum variant is available.
1160    #[allow(dead_code)]
1161    pub const ENM__STATE_RESIZING__SINCE: u32 = 1;
1162    /// Since when the state.activated enum variant is available.
1163    #[allow(dead_code)]
1164    pub const ENM__STATE_ACTIVATED__SINCE: u32 = 1;
1165    /// Since when the state.tiled_left enum variant is available.
1166    #[allow(dead_code)]
1167    pub const ENM__STATE_TILED_LEFT__SINCE: u32 = 2;
1168    /// Since when the state.tiled_right enum variant is available.
1169    #[allow(dead_code)]
1170    pub const ENM__STATE_TILED_RIGHT__SINCE: u32 = 2;
1171    /// Since when the state.tiled_top enum variant is available.
1172    #[allow(dead_code)]
1173    pub const ENM__STATE_TILED_TOP__SINCE: u32 = 2;
1174    /// Since when the state.tiled_bottom enum variant is available.
1175    #[allow(dead_code)]
1176    pub const ENM__STATE_TILED_BOTTOM__SINCE: u32 = 2;
1177    /// Since when the state.suspended enum variant is available.
1178    #[allow(dead_code)]
1179    pub const ENM__STATE_SUSPENDED__SINCE: u32 = 6;
1180
1181    /// Since when the wm_capabilities.window_menu enum variant is available.
1182    #[allow(dead_code)]
1183    pub const ENM__WM_CAPABILITIES_WINDOW_MENU__SINCE: u32 = 1;
1184    /// Since when the wm_capabilities.maximize enum variant is available.
1185    #[allow(dead_code)]
1186    pub const ENM__WM_CAPABILITIES_MAXIMIZE__SINCE: u32 = 1;
1187    /// Since when the wm_capabilities.fullscreen enum variant is available.
1188    #[allow(dead_code)]
1189    pub const ENM__WM_CAPABILITIES_FULLSCREEN__SINCE: u32 = 1;
1190    /// Since when the wm_capabilities.minimize enum variant is available.
1191    #[allow(dead_code)]
1192    pub const ENM__WM_CAPABILITIES_MINIMIZE__SINCE: u32 = 1;
1193}
1194
1195#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1196#[allow(dead_code)]
1197pub struct XdgToplevelError(pub u32);
1198
1199impl XdgToplevelError {
1200    /// provided value is         not a valid variant of the resize_edge enum
1201    #[allow(dead_code)]
1202    pub const INVALID_RESIZE_EDGE: Self = Self(0);
1203
1204    /// invalid parent toplevel
1205    #[allow(dead_code)]
1206    pub const INVALID_PARENT: Self = Self(1);
1207
1208    /// client provided an invalid min or max size
1209    #[allow(dead_code)]
1210    pub const INVALID_SIZE: Self = Self(2);
1211}
1212
1213impl Debug for XdgToplevelError {
1214    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1215        let name = match *self {
1216            Self::INVALID_RESIZE_EDGE => "INVALID_RESIZE_EDGE",
1217            Self::INVALID_PARENT => "INVALID_PARENT",
1218            Self::INVALID_SIZE => "INVALID_SIZE",
1219            _ => return Debug::fmt(&self.0, f),
1220        };
1221        f.write_str(name)
1222    }
1223}
1224
1225/// edge values for resizing
1226///
1227/// These values are used to indicate which edge of a surface
1228/// is being dragged in a resize operation.
1229#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1230#[allow(dead_code)]
1231pub struct XdgToplevelResizeEdge(pub u32);
1232
1233impl XdgToplevelResizeEdge {
1234    #[allow(dead_code)]
1235    pub const NONE: Self = Self(0);
1236
1237    #[allow(dead_code)]
1238    pub const TOP: Self = Self(1);
1239
1240    #[allow(dead_code)]
1241    pub const BOTTOM: Self = Self(2);
1242
1243    #[allow(dead_code)]
1244    pub const LEFT: Self = Self(4);
1245
1246    #[allow(dead_code)]
1247    pub const TOP_LEFT: Self = Self(5);
1248
1249    #[allow(dead_code)]
1250    pub const BOTTOM_LEFT: Self = Self(6);
1251
1252    #[allow(dead_code)]
1253    pub const RIGHT: Self = Self(8);
1254
1255    #[allow(dead_code)]
1256    pub const TOP_RIGHT: Self = Self(9);
1257
1258    #[allow(dead_code)]
1259    pub const BOTTOM_RIGHT: Self = Self(10);
1260}
1261
1262impl Debug for XdgToplevelResizeEdge {
1263    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1264        let name = match *self {
1265            Self::NONE => "NONE",
1266            Self::TOP => "TOP",
1267            Self::BOTTOM => "BOTTOM",
1268            Self::LEFT => "LEFT",
1269            Self::TOP_LEFT => "TOP_LEFT",
1270            Self::BOTTOM_LEFT => "BOTTOM_LEFT",
1271            Self::RIGHT => "RIGHT",
1272            Self::TOP_RIGHT => "TOP_RIGHT",
1273            Self::BOTTOM_RIGHT => "BOTTOM_RIGHT",
1274            _ => return Debug::fmt(&self.0, f),
1275        };
1276        f.write_str(name)
1277    }
1278}
1279
1280/// types of state on the surface
1281///
1282/// The different state values used on the surface. This is designed for
1283/// state values like maximized, fullscreen. It is paired with the
1284/// configure event to ensure that both the client and the compositor
1285/// setting the state can be synchronized.
1286///
1287/// States set in this way are double-buffered, see wl_surface.commit.
1288#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1289#[allow(dead_code)]
1290pub struct XdgToplevelState(pub u32);
1291
1292impl XdgToplevelState {
1293    /// the surface is maximized
1294    ///
1295    /// the surface is maximized
1296    ///
1297    /// The surface is maximized. The window geometry specified in the configure
1298    /// event must be obeyed by the client, or the xdg_wm_base.invalid_surface_state
1299    /// error is raised.
1300    ///
1301    /// The client should draw without shadow or other
1302    /// decoration outside of the window geometry.
1303    #[allow(dead_code)]
1304    pub const MAXIMIZED: Self = Self(1);
1305
1306    /// the surface is fullscreen
1307    ///
1308    /// the surface is fullscreen
1309    ///
1310    /// The surface is fullscreen. The window geometry specified in the
1311    /// configure event is a maximum; the client cannot resize beyond it. For
1312    /// a surface to cover the whole fullscreened area, the geometry
1313    /// dimensions must be obeyed by the client. For more details, see
1314    /// xdg_toplevel.set_fullscreen.
1315    #[allow(dead_code)]
1316    pub const FULLSCREEN: Self = Self(2);
1317
1318    /// the surface is being resized
1319    ///
1320    /// the surface is being resized
1321    ///
1322    /// The surface is being resized. The window geometry specified in the
1323    /// configure event is a maximum; the client cannot resize beyond it.
1324    /// Clients that have aspect ratio or cell sizing configuration can use
1325    /// a smaller size, however.
1326    #[allow(dead_code)]
1327    pub const RESIZING: Self = Self(3);
1328
1329    /// the surface is now activated
1330    ///
1331    /// the surface is now activated
1332    ///
1333    /// Client window decorations should be painted as if the window is
1334    /// active. Do not assume this means that the window actually has
1335    /// keyboard or pointer focus.
1336    #[allow(dead_code)]
1337    pub const ACTIVATED: Self = Self(4);
1338
1339    /// the surface’s left edge is tiled
1340    ///
1341    /// The window is currently in a tiled layout and the left edge is
1342    /// considered to be adjacent to another part of the tiling grid.
1343    ///
1344    /// The client should draw without shadow or other decoration outside of
1345    /// the window geometry on the left edge.
1346    #[allow(dead_code)]
1347    pub const TILED_LEFT: Self = Self(5);
1348
1349    /// the surface’s right edge is tiled
1350    ///
1351    /// The window is currently in a tiled layout and the right edge is
1352    /// considered to be adjacent to another part of the tiling grid.
1353    ///
1354    /// The client should draw without shadow or other decoration outside of
1355    /// the window geometry on the right edge.
1356    #[allow(dead_code)]
1357    pub const TILED_RIGHT: Self = Self(6);
1358
1359    /// the surface’s top edge is tiled
1360    ///
1361    /// The window is currently in a tiled layout and the top edge is
1362    /// considered to be adjacent to another part of the tiling grid.
1363    ///
1364    /// The client should draw without shadow or other decoration outside of
1365    /// the window geometry on the top edge.
1366    #[allow(dead_code)]
1367    pub const TILED_TOP: Self = Self(7);
1368
1369    /// the surface’s bottom edge is tiled
1370    ///
1371    /// The window is currently in a tiled layout and the bottom edge is
1372    /// considered to be adjacent to another part of the tiling grid.
1373    ///
1374    /// The client should draw without shadow or other decoration outside of
1375    /// the window geometry on the bottom edge.
1376    #[allow(dead_code)]
1377    pub const TILED_BOTTOM: Self = Self(8);
1378
1379    /// surface repaint is suspended
1380    ///
1381    /// The surface is currently not ordinarily being repainted; for
1382    /// example because its content is occluded by another window, or its
1383    /// outputs are switched off due to screen locking.
1384    #[allow(dead_code)]
1385    pub const SUSPENDED: Self = Self(9);
1386}
1387
1388impl Debug for XdgToplevelState {
1389    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1390        let name = match *self {
1391            Self::MAXIMIZED => "MAXIMIZED",
1392            Self::FULLSCREEN => "FULLSCREEN",
1393            Self::RESIZING => "RESIZING",
1394            Self::ACTIVATED => "ACTIVATED",
1395            Self::TILED_LEFT => "TILED_LEFT",
1396            Self::TILED_RIGHT => "TILED_RIGHT",
1397            Self::TILED_TOP => "TILED_TOP",
1398            Self::TILED_BOTTOM => "TILED_BOTTOM",
1399            Self::SUSPENDED => "SUSPENDED",
1400            _ => return Debug::fmt(&self.0, f),
1401        };
1402        f.write_str(name)
1403    }
1404}
1405
1406#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1407#[allow(dead_code)]
1408pub struct XdgToplevelWmCapabilities(pub u32);
1409
1410impl XdgToplevelWmCapabilities {
1411    /// show_window_menu is available
1412    #[allow(dead_code)]
1413    pub const WINDOW_MENU: Self = Self(1);
1414
1415    /// set_maximized and unset_maximized are available
1416    #[allow(dead_code)]
1417    pub const MAXIMIZE: Self = Self(2);
1418
1419    /// set_fullscreen and unset_fullscreen are available
1420    #[allow(dead_code)]
1421    pub const FULLSCREEN: Self = Self(3);
1422
1423    /// set_minimized is available
1424    #[allow(dead_code)]
1425    pub const MINIMIZE: Self = Self(4);
1426}
1427
1428impl Debug for XdgToplevelWmCapabilities {
1429    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1430        let name = match *self {
1431            Self::WINDOW_MENU => "WINDOW_MENU",
1432            Self::MAXIMIZE => "MAXIMIZE",
1433            Self::FULLSCREEN => "FULLSCREEN",
1434            Self::MINIMIZE => "MINIMIZE",
1435            _ => return Debug::fmt(&self.0, f),
1436        };
1437        f.write_str(name)
1438    }
1439}
1440
1441/// Functional event handlers.
1442pub mod event_handlers {
1443    use super::*;
1444
1445    /// Event handler for configure events.
1446    pub struct Configure<T, F>(F, PhantomData<fn(&mut T)>);
1447    impl<T, F> XdgToplevelEventHandler for Configure<T, F>
1448    where
1449        T: 'static,
1450        F: Fn(&mut T, &XdgToplevelRef, i32, i32, &[u8]),
1451    {
1452        type Data = T;
1453
1454        #[inline]
1455        fn configure(
1456            &self,
1457            _data: &mut T,
1458            _slf: &XdgToplevelRef,
1459            width: i32,
1460            height: i32,
1461            states: &[u8],
1462        ) {
1463            self.0(_data, _slf, width, height, states)
1464        }
1465    }
1466
1467    /// Event handler for close events.
1468    pub struct Close<T, F>(F, PhantomData<fn(&mut T)>);
1469    impl<T, F> XdgToplevelEventHandler for Close<T, F>
1470    where
1471        T: 'static,
1472        F: Fn(&mut T, &XdgToplevelRef),
1473    {
1474        type Data = T;
1475
1476        #[inline]
1477        fn close(&self, _data: &mut T, _slf: &XdgToplevelRef) {
1478            self.0(_data, _slf)
1479        }
1480    }
1481
1482    /// Event handler for configure_bounds events.
1483    pub struct ConfigureBounds<T, F>(F, PhantomData<fn(&mut T)>);
1484    impl<T, F> XdgToplevelEventHandler for ConfigureBounds<T, F>
1485    where
1486        T: 'static,
1487        F: Fn(&mut T, &XdgToplevelRef, i32, i32),
1488    {
1489        type Data = T;
1490
1491        #[inline]
1492        fn configure_bounds(&self, _data: &mut T, _slf: &XdgToplevelRef, width: i32, height: i32) {
1493            self.0(_data, _slf, width, height)
1494        }
1495    }
1496
1497    /// Event handler for wm_capabilities events.
1498    pub struct WmCapabilities<T, F>(F, PhantomData<fn(&mut T)>);
1499    impl<T, F> XdgToplevelEventHandler for WmCapabilities<T, F>
1500    where
1501        T: 'static,
1502        F: Fn(&mut T, &XdgToplevelRef, &[u8]),
1503    {
1504        type Data = T;
1505
1506        #[inline]
1507        fn wm_capabilities(&self, _data: &mut T, _slf: &XdgToplevelRef, capabilities: &[u8]) {
1508            self.0(_data, _slf, capabilities)
1509        }
1510    }
1511
1512    impl XdgToplevel {
1513        /// Creates an event handler for configure events.
1514        ///
1515        /// The event handler ignores all other events.
1516        #[allow(dead_code)]
1517        pub fn on_configure<T, F>(f: F) -> Configure<T, F>
1518        where
1519            T: 'static,
1520            F: Fn(&mut T, &XdgToplevelRef, i32, i32, &[u8]),
1521        {
1522            Configure(f, PhantomData)
1523        }
1524
1525        /// Creates an event handler for close events.
1526        ///
1527        /// The event handler ignores all other events.
1528        #[allow(dead_code)]
1529        pub fn on_close<T, F>(f: F) -> Close<T, F>
1530        where
1531            T: 'static,
1532            F: Fn(&mut T, &XdgToplevelRef),
1533        {
1534            Close(f, PhantomData)
1535        }
1536
1537        /// Creates an event handler for configure_bounds events.
1538        ///
1539        /// The event handler ignores all other events.
1540        #[allow(dead_code)]
1541        pub fn on_configure_bounds<T, F>(f: F) -> ConfigureBounds<T, F>
1542        where
1543            T: 'static,
1544            F: Fn(&mut T, &XdgToplevelRef, i32, i32),
1545        {
1546            ConfigureBounds(f, PhantomData)
1547        }
1548
1549        /// Creates an event handler for wm_capabilities events.
1550        ///
1551        /// The event handler ignores all other events.
1552        #[allow(dead_code)]
1553        pub fn on_wm_capabilities<T, F>(f: F) -> WmCapabilities<T, F>
1554        where
1555            T: 'static,
1556            F: Fn(&mut T, &XdgToplevelRef, &[u8]),
1557        {
1558            WmCapabilities(f, PhantomData)
1559        }
1560    }
1561}