Skip to main content

get_registry/common/protocols_data/xdg_shell/
xdg_positioner.rs

1//! child surface positioner
2//!
3//! The xdg_positioner provides a collection of rules for the placement of a
4//! child surface relative to a parent surface. Rules can be defined to ensure
5//! the child surface remains within the visible area's borders, and to
6//! specify how the child surface changes its position, such as sliding along
7//! an axis, or flipping around a rectangle. These positioner-created rules are
8//! constrained by the requirement that a child surface must intersect with or
9//! be at least partially adjacent to its parent surface.
10//!
11//! See the various requests for details about possible rules.
12//!
13//! At the time of the request, the compositor makes a copy of the rules
14//! specified by the xdg_positioner. Thus, after the request is complete the
15//! xdg_positioner object can be destroyed or reused; further changes to the
16//! object will have no effect on previous usages.
17//!
18//! For an xdg_positioner object to be considered complete, it must have a
19//! non-zero size set by set_size, and a non-zero anchor rectangle set by
20//! set_anchor_rect. Passing an incomplete xdg_positioner object when
21//! positioning a surface raises an invalid_positioner error.
22
23use super::super::all_types::*;
24use ::wl_client::builder::prelude::*;
25
26static INTERFACE: wl_interface = wl_interface {
27    name: c"xdg_positioner".as_ptr(),
28    version: 6,
29    method_count: 10,
30    methods: {
31        static MESSAGES: [wl_message; 10] = [
32            wl_message {
33                name: c"destroy".as_ptr(),
34                signature: c"".as_ptr(),
35                types: {
36                    static TYPES: [Option<&'static wl_interface>; 0] = [];
37                    TYPES.as_ptr().cast()
38                },
39            },
40            wl_message {
41                name: c"set_size".as_ptr(),
42                signature: c"ii".as_ptr(),
43                types: {
44                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
45                    TYPES.as_ptr().cast()
46                },
47            },
48            wl_message {
49                name: c"set_anchor_rect".as_ptr(),
50                signature: c"iiii".as_ptr(),
51                types: {
52                    static TYPES: [Option<&'static wl_interface>; 4] = [None, None, None, None];
53                    TYPES.as_ptr().cast()
54                },
55            },
56            wl_message {
57                name: c"set_anchor".as_ptr(),
58                signature: c"u".as_ptr(),
59                types: {
60                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
61                    TYPES.as_ptr().cast()
62                },
63            },
64            wl_message {
65                name: c"set_gravity".as_ptr(),
66                signature: c"u".as_ptr(),
67                types: {
68                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
69                    TYPES.as_ptr().cast()
70                },
71            },
72            wl_message {
73                name: c"set_constraint_adjustment".as_ptr(),
74                signature: c"u".as_ptr(),
75                types: {
76                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
77                    TYPES.as_ptr().cast()
78                },
79            },
80            wl_message {
81                name: c"set_offset".as_ptr(),
82                signature: c"ii".as_ptr(),
83                types: {
84                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
85                    TYPES.as_ptr().cast()
86                },
87            },
88            wl_message {
89                name: c"set_reactive".as_ptr(),
90                signature: c"".as_ptr(),
91                types: {
92                    static TYPES: [Option<&'static wl_interface>; 0] = [];
93                    TYPES.as_ptr().cast()
94                },
95            },
96            wl_message {
97                name: c"set_parent_size".as_ptr(),
98                signature: c"ii".as_ptr(),
99                types: {
100                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
101                    TYPES.as_ptr().cast()
102                },
103            },
104            wl_message {
105                name: c"set_parent_configure".as_ptr(),
106                signature: c"u".as_ptr(),
107                types: {
108                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
109                    TYPES.as_ptr().cast()
110                },
111            },
112        ];
113        MESSAGES.as_ptr()
114    },
115    event_count: 0,
116    events: ptr::null(),
117};
118
119/// An owned xdg_positioner proxy.
120///
121/// See the documentation of [the module][self] for the interface description.
122#[derive(Clone, Eq, PartialEq)]
123#[repr(transparent)]
124pub struct XdgPositioner {
125    /// This proxy has the interface INTERFACE.
126    proxy: UntypedOwnedProxy,
127}
128
129/// A borrowed xdg_positioner proxy.
130///
131/// See the documentation of [the module][self] for the interface description.
132#[derive(Eq, PartialEq)]
133#[repr(transparent)]
134pub struct XdgPositionerRef {
135    /// This proxy has the interface INTERFACE.
136    proxy: UntypedBorrowedProxy,
137}
138
139// SAFETY: XdgPositioner is a transparent wrapper around UntypedOwnedProxy
140unsafe impl UntypedOwnedProxyWrapper for XdgPositioner {}
141
142// SAFETY: - INTERFACE is a valid wl_interface
143//         - The only invariant is that self.proxy has a compatible interface
144unsafe impl OwnedProxy for XdgPositioner {
145    const INTERFACE: &'static str = "xdg_positioner";
146    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
147    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
148        private::EventHandler(private::NoOpEventHandler);
149    const MAX_VERSION: u32 = 6;
150
151    type Borrowed = XdgPositionerRef;
152    type Api = private::ProxyApi;
153    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
154}
155
156// SAFETY: XdgPositionerRef is a transparent wrapper around UntypedBorrowedProxy
157unsafe impl UntypedBorrowedProxyWrapper for XdgPositionerRef {}
158
159// SAFETY: - The only invariant is that self.proxy has a compatible interface
160unsafe impl BorrowedProxy for XdgPositionerRef {
161    type Owned = XdgPositioner;
162}
163
164impl Deref for XdgPositioner {
165    type Target = XdgPositionerRef;
166
167    fn deref(&self) -> &Self::Target {
168        proxy::low_level::deref(self)
169    }
170}
171
172mod private {
173    pub struct ProxyApi;
174
175    #[allow(dead_code)]
176    pub struct EventHandler<H>(pub(super) H);
177
178    #[allow(dead_code)]
179    pub struct NoOpEventHandler;
180}
181
182impl Debug for XdgPositioner {
183    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
184        write!(f, "xdg_positioner#{}", self.proxy.id())
185    }
186}
187
188impl Debug for XdgPositionerRef {
189    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
190        write!(f, "xdg_positioner#{}", self.proxy.id())
191    }
192}
193
194impl PartialEq<XdgPositionerRef> for XdgPositioner {
195    fn eq(&self, other: &XdgPositionerRef) -> bool {
196        self.proxy == other.proxy
197    }
198}
199
200impl PartialEq<XdgPositioner> for XdgPositionerRef {
201    fn eq(&self, other: &XdgPositioner) -> bool {
202        self.proxy == other.proxy
203    }
204}
205
206#[allow(dead_code)]
207impl XdgPositioner {
208    /// Since when the destroy request is available.
209    #[allow(dead_code)]
210    pub const REQ__DESTROY__SINCE: u32 = 1;
211
212    /// Since when the set_size request is available.
213    #[allow(dead_code)]
214    pub const REQ__SET_SIZE__SINCE: u32 = 1;
215
216    /// Since when the set_anchor_rect request is available.
217    #[allow(dead_code)]
218    pub const REQ__SET_ANCHOR_RECT__SINCE: u32 = 1;
219
220    /// Since when the set_anchor request is available.
221    #[allow(dead_code)]
222    pub const REQ__SET_ANCHOR__SINCE: u32 = 1;
223
224    /// Since when the set_gravity request is available.
225    #[allow(dead_code)]
226    pub const REQ__SET_GRAVITY__SINCE: u32 = 1;
227
228    /// Since when the set_constraint_adjustment request is available.
229    #[allow(dead_code)]
230    pub const REQ__SET_CONSTRAINT_ADJUSTMENT__SINCE: u32 = 1;
231
232    /// Since when the set_offset request is available.
233    #[allow(dead_code)]
234    pub const REQ__SET_OFFSET__SINCE: u32 = 1;
235
236    /// Since when the set_reactive request is available.
237    #[allow(dead_code)]
238    pub const REQ__SET_REACTIVE__SINCE: u32 = 3;
239
240    /// Since when the set_parent_size request is available.
241    #[allow(dead_code)]
242    pub const REQ__SET_PARENT_SIZE__SINCE: u32 = 3;
243
244    /// Since when the set_parent_configure request is available.
245    #[allow(dead_code)]
246    pub const REQ__SET_PARENT_CONFIGURE__SINCE: u32 = 3;
247}
248
249#[allow(dead_code)]
250impl XdgPositioner {
251    /// destroy the xdg_positioner object
252    ///
253    /// Notify the compositor that the xdg_positioner will no longer be used.
254    #[inline]
255    pub fn destroy(&self) {
256        let mut args = [];
257        // SAFETY: - self.proxy has the interface INTERFACE
258        //         - 0 < INTERFACE.method_count = 10
259        //         - the request signature is ``
260        unsafe {
261            self.proxy.send_destructor(0, &mut args);
262        }
263    }
264}
265
266#[allow(dead_code)]
267impl XdgPositionerRef {
268    /// set the size of the to-be positioned rectangle
269    ///
270    /// Set the size of the surface that is to be positioned with the positioner
271    /// object. The size is in surface-local coordinates and corresponds to the
272    /// window geometry. See xdg_surface.set_window_geometry.
273    ///
274    /// If a zero or negative size is set the invalid_input error is raised.
275    ///
276    /// # Arguments
277    ///
278    /// - `width`: width of positioned rectangle
279    /// - `height`: height of positioned rectangle
280    #[inline]
281    pub fn set_size(&self, width: i32, height: i32) {
282        let (arg0, arg1) = (width, height);
283        let mut args = [wl_argument { i: arg0 }, wl_argument { i: arg1 }];
284        // SAFETY: - self.proxy has the interface INTERFACE
285        //         - 1 < INTERFACE.method_count = 10
286        //         - the request signature is `ii`
287        unsafe {
288            self.proxy.send_request(1, &mut args);
289        }
290    }
291
292    /// set the anchor rectangle within the parent surface
293    ///
294    /// Specify the anchor rectangle within the parent surface that the child
295    /// surface will be placed relative to. The rectangle is relative to the
296    /// window geometry as defined by xdg_surface.set_window_geometry of the
297    /// parent surface.
298    ///
299    /// When the xdg_positioner object is used to position a child surface, the
300    /// anchor rectangle may not extend outside the window geometry of the
301    /// positioned child's parent surface.
302    ///
303    /// If a negative size is set the invalid_input error is raised.
304    ///
305    /// # Arguments
306    ///
307    /// - `x`: x position of anchor rectangle
308    /// - `y`: y position of anchor rectangle
309    /// - `width`: width of anchor rectangle
310    /// - `height`: height of anchor rectangle
311    #[inline]
312    pub fn set_anchor_rect(&self, x: i32, y: i32, width: i32, height: i32) {
313        let (arg0, arg1, arg2, arg3) = (x, y, width, height);
314        let mut args = [
315            wl_argument { i: arg0 },
316            wl_argument { i: arg1 },
317            wl_argument { i: arg2 },
318            wl_argument { i: arg3 },
319        ];
320        // SAFETY: - self.proxy has the interface INTERFACE
321        //         - 2 < INTERFACE.method_count = 10
322        //         - the request signature is `iiii`
323        unsafe {
324            self.proxy.send_request(2, &mut args);
325        }
326    }
327
328    /// set anchor rectangle anchor
329    ///
330    /// Defines the anchor point for the anchor rectangle. The specified anchor
331    /// is used derive an anchor point that the child surface will be
332    /// positioned relative to. If a corner anchor is set (e.g. 'top_left' or
333    /// 'bottom_right'), the anchor point will be at the specified corner;
334    /// otherwise, the derived anchor point will be centered on the specified
335    /// edge, or in the center of the anchor rectangle if no edge is specified.
336    ///
337    /// # Arguments
338    ///
339    /// - `anchor`: anchor
340    #[inline]
341    pub fn set_anchor(&self, anchor: XdgPositionerAnchor) {
342        let (arg0,) = (anchor,);
343        let mut args = [wl_argument { u: arg0.0 }];
344        // SAFETY: - self.proxy has the interface INTERFACE
345        //         - 3 < INTERFACE.method_count = 10
346        //         - the request signature is `u`
347        unsafe {
348            self.proxy.send_request(3, &mut args);
349        }
350    }
351
352    /// set child surface gravity
353    ///
354    /// Defines in what direction a surface should be positioned, relative to
355    /// the anchor point of the parent surface. If a corner gravity is
356    /// specified (e.g. 'bottom_right' or 'top_left'), then the child surface
357    /// will be placed towards the specified gravity; otherwise, the child
358    /// surface will be centered over the anchor point on any axis that had no
359    /// gravity specified. If the gravity is not in the ‘gravity’ enum, an
360    /// invalid_input error is raised.
361    ///
362    /// # Arguments
363    ///
364    /// - `gravity`: gravity direction
365    #[inline]
366    pub fn set_gravity(&self, gravity: XdgPositionerGravity) {
367        let (arg0,) = (gravity,);
368        let mut args = [wl_argument { u: arg0.0 }];
369        // SAFETY: - self.proxy has the interface INTERFACE
370        //         - 4 < INTERFACE.method_count = 10
371        //         - the request signature is `u`
372        unsafe {
373            self.proxy.send_request(4, &mut args);
374        }
375    }
376
377    /// set the adjustment to be done when constrained
378    ///
379    /// Specify how the window should be positioned if the originally intended
380    /// position caused the surface to be constrained, meaning at least
381    /// partially outside positioning boundaries set by the compositor. The
382    /// adjustment is set by constructing a bitmask describing the adjustment to
383    /// be made when the surface is constrained on that axis.
384    ///
385    /// If no bit for one axis is set, the compositor will assume that the child
386    /// surface should not change its position on that axis when constrained.
387    ///
388    /// If more than one bit for one axis is set, the order of how adjustments
389    /// are applied is specified in the corresponding adjustment descriptions.
390    ///
391    /// The default adjustment is none.
392    ///
393    /// # Arguments
394    ///
395    /// - `constraint_adjustment`: bit mask of constraint adjustments
396    #[inline]
397    pub fn set_constraint_adjustment(
398        &self,
399        constraint_adjustment: XdgPositionerConstraintAdjustment,
400    ) {
401        let (arg0,) = (constraint_adjustment,);
402        let mut args = [wl_argument { u: arg0.0 }];
403        // SAFETY: - self.proxy has the interface INTERFACE
404        //         - 5 < INTERFACE.method_count = 10
405        //         - the request signature is `u`
406        unsafe {
407            self.proxy.send_request(5, &mut args);
408        }
409    }
410
411    /// set surface position offset
412    ///
413    /// Specify the surface position offset relative to the position of the
414    /// anchor on the anchor rectangle and the anchor on the surface. For
415    /// example if the anchor of the anchor rectangle is at (x, y), the surface
416    /// has the gravity bottom|right, and the offset is (ox, oy), the calculated
417    /// surface position will be (x + ox, y + oy). The offset position of the
418    /// surface is the one used for constraint testing. See
419    /// set_constraint_adjustment.
420    ///
421    /// An example use case is placing a popup menu on top of a user interface
422    /// element, while aligning the user interface element of the parent surface
423    /// with some user interface element placed somewhere in the popup surface.
424    ///
425    /// # Arguments
426    ///
427    /// - `x`: surface position x offset
428    /// - `y`: surface position y offset
429    #[inline]
430    pub fn set_offset(&self, x: i32, y: i32) {
431        let (arg0, arg1) = (x, y);
432        let mut args = [wl_argument { i: arg0 }, wl_argument { i: arg1 }];
433        // SAFETY: - self.proxy has the interface INTERFACE
434        //         - 6 < INTERFACE.method_count = 10
435        //         - the request signature is `ii`
436        unsafe {
437            self.proxy.send_request(6, &mut args);
438        }
439    }
440
441    /// continuously reconstrain the surface
442    ///
443    /// When set reactive, the surface is reconstrained if the conditions used
444    /// for constraining changed, e.g. the parent window moved.
445    ///
446    /// If the conditions changed and the popup was reconstrained, an
447    /// xdg_popup.configure event is sent with updated geometry, followed by an
448    /// xdg_surface.configure event.
449    #[inline]
450    pub fn set_reactive(&self) {
451        let mut args = [];
452        // SAFETY: - self.proxy has the interface INTERFACE
453        //         - 7 < INTERFACE.method_count = 10
454        //         - the request signature is ``
455        unsafe {
456            self.proxy.send_request(7, &mut args);
457        }
458    }
459
460    ///
461    /// Set the parent window geometry the compositor should use when
462    /// positioning the popup. The compositor may use this information to
463    /// determine the future state the popup should be constrained using. If
464    /// this doesn't match the dimension of the parent the popup is eventually
465    /// positioned against, the behavior is undefined.
466    ///
467    /// The arguments are given in the surface-local coordinate space.
468    ///
469    /// # Arguments
470    ///
471    /// - `parent_width`: future window geometry width of parent
472    /// - `parent_height`: future window geometry height of parent
473    #[inline]
474    pub fn set_parent_size(&self, parent_width: i32, parent_height: i32) {
475        let (arg0, arg1) = (parent_width, parent_height);
476        let mut args = [wl_argument { i: arg0 }, wl_argument { i: arg1 }];
477        // SAFETY: - self.proxy has the interface INTERFACE
478        //         - 8 < INTERFACE.method_count = 10
479        //         - the request signature is `ii`
480        unsafe {
481            self.proxy.send_request(8, &mut args);
482        }
483    }
484
485    /// set parent configure this is a response to
486    ///
487    /// Set the serial of an xdg_surface.configure event this positioner will be
488    /// used in response to. The compositor may use this information together
489    /// with set_parent_size to determine what future state the popup should be
490    /// constrained using.
491    ///
492    /// # Arguments
493    ///
494    /// - `serial`: serial of parent configure event
495    #[inline]
496    pub fn set_parent_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        //         - 9 < INTERFACE.method_count = 10
501        //         - the request signature is `u`
502        unsafe {
503            self.proxy.send_request(9, &mut args);
504        }
505    }
506}
507
508/// An event handler for [XdgPositioner] proxies.
509#[allow(dead_code)]
510pub trait XdgPositionerEventHandler {
511    type Data: 'static;
512}
513
514impl XdgPositionerEventHandler for private::NoOpEventHandler {
515    type Data = ();
516}
517
518// SAFETY: - INTERFACE is a valid wl_interface
519//         - mutable_type always returns the same value
520unsafe impl<H> EventHandler for private::EventHandler<H>
521where
522    H: XdgPositionerEventHandler,
523{
524    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
525
526    #[inline]
527    fn mutable_type() -> Option<(TypeId, &'static str)> {
528        let id = TypeId::of::<H::Data>();
529        let name = std::any::type_name::<H::Data>();
530        Some((id, name))
531    }
532
533    #[allow(unused_variables)]
534    unsafe fn handle_event(
535        &self,
536        queue: &Queue,
537        data: *mut u8,
538        slf: &UntypedBorrowedProxy,
539        opcode: u32,
540        args: *mut wl_argument,
541    ) {
542        invalid_opcode("xdg_positioner", opcode);
543    }
544}
545
546impl<H> CreateEventHandler<H> for private::ProxyApi
547where
548    H: XdgPositionerEventHandler,
549{
550    type EventHandler = private::EventHandler<H>;
551
552    #[inline]
553    fn create_event_handler(handler: H) -> Self::EventHandler {
554        private::EventHandler(handler)
555    }
556}
557
558impl XdgPositioner {
559    /// Since when the error.invalid_input enum variant is available.
560    #[allow(dead_code)]
561    pub const ENM__ERROR_INVALID_INPUT__SINCE: u32 = 1;
562
563    /// Since when the anchor.none enum variant is available.
564    #[allow(dead_code)]
565    pub const ENM__ANCHOR_NONE__SINCE: u32 = 1;
566    /// Since when the anchor.top enum variant is available.
567    #[allow(dead_code)]
568    pub const ENM__ANCHOR_TOP__SINCE: u32 = 1;
569    /// Since when the anchor.bottom enum variant is available.
570    #[allow(dead_code)]
571    pub const ENM__ANCHOR_BOTTOM__SINCE: u32 = 1;
572    /// Since when the anchor.left enum variant is available.
573    #[allow(dead_code)]
574    pub const ENM__ANCHOR_LEFT__SINCE: u32 = 1;
575    /// Since when the anchor.right enum variant is available.
576    #[allow(dead_code)]
577    pub const ENM__ANCHOR_RIGHT__SINCE: u32 = 1;
578    /// Since when the anchor.top_left enum variant is available.
579    #[allow(dead_code)]
580    pub const ENM__ANCHOR_TOP_LEFT__SINCE: u32 = 1;
581    /// Since when the anchor.bottom_left enum variant is available.
582    #[allow(dead_code)]
583    pub const ENM__ANCHOR_BOTTOM_LEFT__SINCE: u32 = 1;
584    /// Since when the anchor.top_right enum variant is available.
585    #[allow(dead_code)]
586    pub const ENM__ANCHOR_TOP_RIGHT__SINCE: u32 = 1;
587    /// Since when the anchor.bottom_right enum variant is available.
588    #[allow(dead_code)]
589    pub const ENM__ANCHOR_BOTTOM_RIGHT__SINCE: u32 = 1;
590
591    /// Since when the gravity.none enum variant is available.
592    #[allow(dead_code)]
593    pub const ENM__GRAVITY_NONE__SINCE: u32 = 1;
594    /// Since when the gravity.top enum variant is available.
595    #[allow(dead_code)]
596    pub const ENM__GRAVITY_TOP__SINCE: u32 = 1;
597    /// Since when the gravity.bottom enum variant is available.
598    #[allow(dead_code)]
599    pub const ENM__GRAVITY_BOTTOM__SINCE: u32 = 1;
600    /// Since when the gravity.left enum variant is available.
601    #[allow(dead_code)]
602    pub const ENM__GRAVITY_LEFT__SINCE: u32 = 1;
603    /// Since when the gravity.right enum variant is available.
604    #[allow(dead_code)]
605    pub const ENM__GRAVITY_RIGHT__SINCE: u32 = 1;
606    /// Since when the gravity.top_left enum variant is available.
607    #[allow(dead_code)]
608    pub const ENM__GRAVITY_TOP_LEFT__SINCE: u32 = 1;
609    /// Since when the gravity.bottom_left enum variant is available.
610    #[allow(dead_code)]
611    pub const ENM__GRAVITY_BOTTOM_LEFT__SINCE: u32 = 1;
612    /// Since when the gravity.top_right enum variant is available.
613    #[allow(dead_code)]
614    pub const ENM__GRAVITY_TOP_RIGHT__SINCE: u32 = 1;
615    /// Since when the gravity.bottom_right enum variant is available.
616    #[allow(dead_code)]
617    pub const ENM__GRAVITY_BOTTOM_RIGHT__SINCE: u32 = 1;
618
619    /// Since when the constraint_adjustment.none enum variant is available.
620    #[allow(dead_code)]
621    pub const ENM__CONSTRAINT_ADJUSTMENT_NONE__SINCE: u32 = 1;
622    /// Since when the constraint_adjustment.slide_x enum variant is available.
623    #[allow(dead_code)]
624    pub const ENM__CONSTRAINT_ADJUSTMENT_SLIDE_X__SINCE: u32 = 1;
625    /// Since when the constraint_adjustment.slide_y enum variant is available.
626    #[allow(dead_code)]
627    pub const ENM__CONSTRAINT_ADJUSTMENT_SLIDE_Y__SINCE: u32 = 1;
628    /// Since when the constraint_adjustment.flip_x enum variant is available.
629    #[allow(dead_code)]
630    pub const ENM__CONSTRAINT_ADJUSTMENT_FLIP_X__SINCE: u32 = 1;
631    /// Since when the constraint_adjustment.flip_y enum variant is available.
632    #[allow(dead_code)]
633    pub const ENM__CONSTRAINT_ADJUSTMENT_FLIP_Y__SINCE: u32 = 1;
634    /// Since when the constraint_adjustment.resize_x enum variant is available.
635    #[allow(dead_code)]
636    pub const ENM__CONSTRAINT_ADJUSTMENT_RESIZE_X__SINCE: u32 = 1;
637    /// Since when the constraint_adjustment.resize_y enum variant is available.
638    #[allow(dead_code)]
639    pub const ENM__CONSTRAINT_ADJUSTMENT_RESIZE_Y__SINCE: u32 = 1;
640}
641
642#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
643#[allow(dead_code)]
644pub struct XdgPositionerError(pub u32);
645
646impl XdgPositionerError {
647    /// invalid input provided
648    #[allow(dead_code)]
649    pub const INVALID_INPUT: Self = Self(0);
650}
651
652impl Debug for XdgPositionerError {
653    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
654        let name = match *self {
655            Self::INVALID_INPUT => "INVALID_INPUT",
656            _ => return Debug::fmt(&self.0, f),
657        };
658        f.write_str(name)
659    }
660}
661
662#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
663#[allow(dead_code)]
664pub struct XdgPositionerAnchor(pub u32);
665
666impl XdgPositionerAnchor {
667    #[allow(dead_code)]
668    pub const NONE: Self = Self(0);
669
670    #[allow(dead_code)]
671    pub const TOP: Self = Self(1);
672
673    #[allow(dead_code)]
674    pub const BOTTOM: Self = Self(2);
675
676    #[allow(dead_code)]
677    pub const LEFT: Self = Self(3);
678
679    #[allow(dead_code)]
680    pub const RIGHT: Self = Self(4);
681
682    #[allow(dead_code)]
683    pub const TOP_LEFT: Self = Self(5);
684
685    #[allow(dead_code)]
686    pub const BOTTOM_LEFT: Self = Self(6);
687
688    #[allow(dead_code)]
689    pub const TOP_RIGHT: Self = Self(7);
690
691    #[allow(dead_code)]
692    pub const BOTTOM_RIGHT: Self = Self(8);
693}
694
695impl Debug for XdgPositionerAnchor {
696    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
697        let name = match *self {
698            Self::NONE => "NONE",
699            Self::TOP => "TOP",
700            Self::BOTTOM => "BOTTOM",
701            Self::LEFT => "LEFT",
702            Self::RIGHT => "RIGHT",
703            Self::TOP_LEFT => "TOP_LEFT",
704            Self::BOTTOM_LEFT => "BOTTOM_LEFT",
705            Self::TOP_RIGHT => "TOP_RIGHT",
706            Self::BOTTOM_RIGHT => "BOTTOM_RIGHT",
707            _ => return Debug::fmt(&self.0, f),
708        };
709        f.write_str(name)
710    }
711}
712
713#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
714#[allow(dead_code)]
715pub struct XdgPositionerGravity(pub u32);
716
717impl XdgPositionerGravity {
718    #[allow(dead_code)]
719    pub const NONE: Self = Self(0);
720
721    #[allow(dead_code)]
722    pub const TOP: Self = Self(1);
723
724    #[allow(dead_code)]
725    pub const BOTTOM: Self = Self(2);
726
727    #[allow(dead_code)]
728    pub const LEFT: Self = Self(3);
729
730    #[allow(dead_code)]
731    pub const RIGHT: Self = Self(4);
732
733    #[allow(dead_code)]
734    pub const TOP_LEFT: Self = Self(5);
735
736    #[allow(dead_code)]
737    pub const BOTTOM_LEFT: Self = Self(6);
738
739    #[allow(dead_code)]
740    pub const TOP_RIGHT: Self = Self(7);
741
742    #[allow(dead_code)]
743    pub const BOTTOM_RIGHT: Self = Self(8);
744}
745
746impl Debug for XdgPositionerGravity {
747    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
748        let name = match *self {
749            Self::NONE => "NONE",
750            Self::TOP => "TOP",
751            Self::BOTTOM => "BOTTOM",
752            Self::LEFT => "LEFT",
753            Self::RIGHT => "RIGHT",
754            Self::TOP_LEFT => "TOP_LEFT",
755            Self::BOTTOM_LEFT => "BOTTOM_LEFT",
756            Self::TOP_RIGHT => "TOP_RIGHT",
757            Self::BOTTOM_RIGHT => "BOTTOM_RIGHT",
758            _ => return Debug::fmt(&self.0, f),
759        };
760        f.write_str(name)
761    }
762}
763
764/// constraint adjustments
765///
766/// The constraint adjustment value define ways the compositor will adjust
767/// the position of the surface, if the unadjusted position would result
768/// in the surface being partly constrained.
769///
770/// Whether a surface is considered 'constrained' is left to the compositor
771/// to determine. For example, the surface may be partly outside the
772/// compositor's defined 'work area', thus necessitating the child surface's
773/// position be adjusted until it is entirely inside the work area.
774///
775/// The adjustments can be combined, according to a defined precedence: 1)
776/// Flip, 2) Slide, 3) Resize.
777#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
778#[allow(dead_code)]
779pub struct XdgPositionerConstraintAdjustment(pub u32);
780
781/// An iterator over the set bits in a [XdgPositionerConstraintAdjustment].
782///
783/// You can construct this with the `IntoIterator` implementation of `XdgPositionerConstraintAdjustment`.
784#[derive(Clone, Debug)]
785#[allow(dead_code)]
786pub struct XdgPositionerConstraintAdjustmentIter(pub u32);
787
788impl XdgPositionerConstraintAdjustment {
789    /// don't move the child surface when constrained
790    ///
791    /// Don't alter the surface position even if it is constrained on some
792    /// axis, for example partially outside the edge of an output.
793    #[allow(dead_code)]
794    pub const NONE: Self = Self(0);
795
796    /// move along the x axis until unconstrained
797    ///
798    /// Slide the surface along the x axis until it is no longer constrained.
799    ///
800    /// First try to slide towards the direction of the gravity on the x axis
801    /// until either the edge in the opposite direction of the gravity is
802    /// unconstrained or the edge in the direction of the gravity is
803    /// constrained.
804    ///
805    /// Then try to slide towards the opposite direction of the gravity on the
806    /// x axis until either the edge in the direction of the gravity is
807    /// unconstrained or the edge in the opposite direction of the gravity is
808    /// constrained.
809    #[allow(dead_code)]
810    pub const SLIDE_X: Self = Self(1);
811
812    /// move along the y axis until unconstrained
813    ///
814    /// Slide the surface along the y axis until it is no longer constrained.
815    ///
816    /// First try to slide towards the direction of the gravity on the y axis
817    /// until either the edge in the opposite direction of the gravity is
818    /// unconstrained or the edge in the direction of the gravity is
819    /// constrained.
820    ///
821    /// Then try to slide towards the opposite direction of the gravity on the
822    /// y axis until either the edge in the direction of the gravity is
823    /// unconstrained or the edge in the opposite direction of the gravity is
824    /// constrained.
825    #[allow(dead_code)]
826    pub const SLIDE_Y: Self = Self(2);
827
828    /// invert the anchor and gravity on the x axis
829    ///
830    /// Invert the anchor and gravity on the x axis if the surface is
831    /// constrained on the x axis. For example, if the left edge of the
832    /// surface is constrained, the gravity is 'left' and the anchor is
833    /// 'left', change the gravity to 'right' and the anchor to 'right'.
834    ///
835    /// If the adjusted position also ends up being constrained, the resulting
836    /// position of the flip_x adjustment will be the one before the
837    /// adjustment.
838    #[allow(dead_code)]
839    pub const FLIP_X: Self = Self(4);
840
841    /// invert the anchor and gravity on the y axis
842    ///
843    /// Invert the anchor and gravity on the y axis if the surface is
844    /// constrained on the y axis. For example, if the bottom edge of the
845    /// surface is constrained, the gravity is 'bottom' and the anchor is
846    /// 'bottom', change the gravity to 'top' and the anchor to 'top'.
847    ///
848    /// The adjusted position is calculated given the original anchor
849    /// rectangle and offset, but with the new flipped anchor and gravity
850    /// values.
851    ///
852    /// If the adjusted position also ends up being constrained, the resulting
853    /// position of the flip_y adjustment will be the one before the
854    /// adjustment.
855    #[allow(dead_code)]
856    pub const FLIP_Y: Self = Self(8);
857
858    /// horizontally resize the surface
859    ///
860    /// Resize the surface horizontally so that it is completely
861    /// unconstrained.
862    #[allow(dead_code)]
863    pub const RESIZE_X: Self = Self(16);
864
865    /// vertically resize the surface
866    ///
867    /// Resize the surface vertically so that it is completely unconstrained.
868    #[allow(dead_code)]
869    pub const RESIZE_Y: Self = Self(32);
870}
871
872#[allow(dead_code)]
873impl XdgPositionerConstraintAdjustment {
874    #[inline]
875    pub const fn empty() -> Self {
876        Self(0)
877    }
878
879    #[inline]
880    #[must_use]
881    pub const fn is_empty(self) -> bool {
882        self.0 == 0
883    }
884
885    #[inline]
886    #[must_use]
887    pub const fn contains(self, other: Self) -> bool {
888        self.0 & other.0 == other.0
889    }
890
891    #[inline]
892    #[must_use]
893    pub const fn intersects(self, other: Self) -> bool {
894        self.0 & other.0 != 0
895    }
896
897    #[inline]
898    pub const fn insert(&mut self, other: Self) {
899        *self = self.union(other);
900    }
901
902    #[inline]
903    pub const fn remove(&mut self, other: Self) {
904        *self = self.difference(other);
905    }
906
907    #[inline]
908    pub const fn toggle(&mut self, other: Self) {
909        *self = self.symmetric_difference(other);
910    }
911
912    #[inline]
913    pub const fn set(&mut self, other: Self, value: bool) {
914        if value {
915            self.insert(other);
916        } else {
917            self.remove(other);
918        }
919    }
920
921    #[inline]
922    #[must_use]
923    pub const fn intersection(self, other: Self) -> Self {
924        Self(self.0 & other.0)
925    }
926
927    #[inline]
928    #[must_use]
929    pub const fn union(self, other: Self) -> Self {
930        Self(self.0 | other.0)
931    }
932
933    #[inline]
934    #[must_use]
935    pub const fn difference(self, other: Self) -> Self {
936        Self(self.0 & !other.0)
937    }
938
939    #[inline]
940    #[must_use]
941    pub const fn complement(self) -> Self {
942        Self(!self.0)
943    }
944
945    #[inline]
946    #[must_use]
947    pub const fn symmetric_difference(self, other: Self) -> Self {
948        Self(self.0 ^ other.0)
949    }
950
951    #[inline]
952    pub const fn all_known() -> Self {
953        #[allow(clippy::eq_op, clippy::identity_op)]
954        Self(0 | 0 | 1 | 2 | 4 | 8 | 16 | 32)
955    }
956}
957
958impl Iterator for XdgPositionerConstraintAdjustmentIter {
959    type Item = XdgPositionerConstraintAdjustment;
960
961    fn next(&mut self) -> Option<Self::Item> {
962        if self.0 == 0 {
963            return None;
964        }
965        let bit = 1 << self.0.trailing_zeros();
966        self.0 &= !bit;
967        Some(XdgPositionerConstraintAdjustment(bit))
968    }
969}
970
971impl IntoIterator for XdgPositionerConstraintAdjustment {
972    type Item = XdgPositionerConstraintAdjustment;
973    type IntoIter = XdgPositionerConstraintAdjustmentIter;
974
975    fn into_iter(self) -> Self::IntoIter {
976        XdgPositionerConstraintAdjustmentIter(self.0)
977    }
978}
979
980impl BitAnd for XdgPositionerConstraintAdjustment {
981    type Output = Self;
982
983    fn bitand(self, rhs: Self) -> Self::Output {
984        self.intersection(rhs)
985    }
986}
987
988impl BitAndAssign for XdgPositionerConstraintAdjustment {
989    fn bitand_assign(&mut self, rhs: Self) {
990        *self = self.intersection(rhs);
991    }
992}
993
994impl BitOr for XdgPositionerConstraintAdjustment {
995    type Output = Self;
996
997    fn bitor(self, rhs: Self) -> Self::Output {
998        self.union(rhs)
999    }
1000}
1001
1002impl BitOrAssign for XdgPositionerConstraintAdjustment {
1003    fn bitor_assign(&mut self, rhs: Self) {
1004        *self = self.union(rhs);
1005    }
1006}
1007
1008impl BitXor for XdgPositionerConstraintAdjustment {
1009    type Output = Self;
1010
1011    fn bitxor(self, rhs: Self) -> Self::Output {
1012        self.symmetric_difference(rhs)
1013    }
1014}
1015
1016impl BitXorAssign for XdgPositionerConstraintAdjustment {
1017    fn bitxor_assign(&mut self, rhs: Self) {
1018        *self = self.symmetric_difference(rhs);
1019    }
1020}
1021
1022impl Sub for XdgPositionerConstraintAdjustment {
1023    type Output = Self;
1024
1025    fn sub(self, rhs: Self) -> Self::Output {
1026        self.difference(rhs)
1027    }
1028}
1029
1030impl SubAssign for XdgPositionerConstraintAdjustment {
1031    fn sub_assign(&mut self, rhs: Self) {
1032        *self = self.difference(rhs);
1033    }
1034}
1035
1036impl Not for XdgPositionerConstraintAdjustment {
1037    type Output = Self;
1038
1039    fn not(self) -> Self::Output {
1040        self.complement()
1041    }
1042}
1043
1044impl Debug for XdgPositionerConstraintAdjustment {
1045    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1046        let mut v = self.0;
1047        let mut first = true;
1048        if v & 1 == 1 {
1049            v &= !1;
1050            if first {
1051                first = false;
1052            } else {
1053                f.write_str(" | ")?;
1054            }
1055            f.write_str("SLIDE_X")?;
1056        }
1057        if v & 2 == 2 {
1058            v &= !2;
1059            if first {
1060                first = false;
1061            } else {
1062                f.write_str(" | ")?;
1063            }
1064            f.write_str("SLIDE_Y")?;
1065        }
1066        if v & 4 == 4 {
1067            v &= !4;
1068            if first {
1069                first = false;
1070            } else {
1071                f.write_str(" | ")?;
1072            }
1073            f.write_str("FLIP_X")?;
1074        }
1075        if v & 8 == 8 {
1076            v &= !8;
1077            if first {
1078                first = false;
1079            } else {
1080                f.write_str(" | ")?;
1081            }
1082            f.write_str("FLIP_Y")?;
1083        }
1084        if v & 16 == 16 {
1085            v &= !16;
1086            if first {
1087                first = false;
1088            } else {
1089                f.write_str(" | ")?;
1090            }
1091            f.write_str("RESIZE_X")?;
1092        }
1093        if v & 32 == 32 {
1094            v &= !32;
1095            if first {
1096                first = false;
1097            } else {
1098                f.write_str(" | ")?;
1099            }
1100            f.write_str("RESIZE_Y")?;
1101        }
1102        if v != 0 {
1103            if first {
1104                first = false;
1105            } else {
1106                f.write_str(" | ")?;
1107            }
1108            write!(f, "0x{v:032x}")?;
1109        }
1110        if first {
1111            f.write_str("NONE")?;
1112        }
1113        Ok(())
1114    }
1115}
1116
1117/// Functional event handlers.
1118pub mod event_handlers {
1119    use super::*;
1120
1121    impl XdgPositioner {}
1122}