Skip to main content

get_registry/common/protocols/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
512impl XdgPositionerEventHandler for private::NoOpEventHandler {}
513
514// SAFETY: - INTERFACE is a valid wl_interface
515unsafe impl<H> EventHandler for private::EventHandler<H>
516where
517    H: XdgPositionerEventHandler,
518{
519    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
520
521    #[allow(unused_variables)]
522    unsafe fn handle_event(
523        &self,
524        queue: &Queue,
525        data: *mut u8,
526        slf: &UntypedBorrowedProxy,
527        opcode: u32,
528        args: *mut wl_argument,
529    ) {
530        invalid_opcode("xdg_positioner", opcode);
531    }
532}
533
534impl<H> CreateEventHandler<H> for private::ProxyApi
535where
536    H: XdgPositionerEventHandler,
537{
538    type EventHandler = private::EventHandler<H>;
539
540    #[inline]
541    fn create_event_handler(handler: H) -> Self::EventHandler {
542        private::EventHandler(handler)
543    }
544}
545
546impl XdgPositioner {
547    /// Since when the error.invalid_input enum variant is available.
548    #[allow(dead_code)]
549    pub const ENM__ERROR_INVALID_INPUT__SINCE: u32 = 1;
550
551    /// Since when the anchor.none enum variant is available.
552    #[allow(dead_code)]
553    pub const ENM__ANCHOR_NONE__SINCE: u32 = 1;
554    /// Since when the anchor.top enum variant is available.
555    #[allow(dead_code)]
556    pub const ENM__ANCHOR_TOP__SINCE: u32 = 1;
557    /// Since when the anchor.bottom enum variant is available.
558    #[allow(dead_code)]
559    pub const ENM__ANCHOR_BOTTOM__SINCE: u32 = 1;
560    /// Since when the anchor.left enum variant is available.
561    #[allow(dead_code)]
562    pub const ENM__ANCHOR_LEFT__SINCE: u32 = 1;
563    /// Since when the anchor.right enum variant is available.
564    #[allow(dead_code)]
565    pub const ENM__ANCHOR_RIGHT__SINCE: u32 = 1;
566    /// Since when the anchor.top_left enum variant is available.
567    #[allow(dead_code)]
568    pub const ENM__ANCHOR_TOP_LEFT__SINCE: u32 = 1;
569    /// Since when the anchor.bottom_left enum variant is available.
570    #[allow(dead_code)]
571    pub const ENM__ANCHOR_BOTTOM_LEFT__SINCE: u32 = 1;
572    /// Since when the anchor.top_right enum variant is available.
573    #[allow(dead_code)]
574    pub const ENM__ANCHOR_TOP_RIGHT__SINCE: u32 = 1;
575    /// Since when the anchor.bottom_right enum variant is available.
576    #[allow(dead_code)]
577    pub const ENM__ANCHOR_BOTTOM_RIGHT__SINCE: u32 = 1;
578
579    /// Since when the gravity.none enum variant is available.
580    #[allow(dead_code)]
581    pub const ENM__GRAVITY_NONE__SINCE: u32 = 1;
582    /// Since when the gravity.top enum variant is available.
583    #[allow(dead_code)]
584    pub const ENM__GRAVITY_TOP__SINCE: u32 = 1;
585    /// Since when the gravity.bottom enum variant is available.
586    #[allow(dead_code)]
587    pub const ENM__GRAVITY_BOTTOM__SINCE: u32 = 1;
588    /// Since when the gravity.left enum variant is available.
589    #[allow(dead_code)]
590    pub const ENM__GRAVITY_LEFT__SINCE: u32 = 1;
591    /// Since when the gravity.right enum variant is available.
592    #[allow(dead_code)]
593    pub const ENM__GRAVITY_RIGHT__SINCE: u32 = 1;
594    /// Since when the gravity.top_left enum variant is available.
595    #[allow(dead_code)]
596    pub const ENM__GRAVITY_TOP_LEFT__SINCE: u32 = 1;
597    /// Since when the gravity.bottom_left enum variant is available.
598    #[allow(dead_code)]
599    pub const ENM__GRAVITY_BOTTOM_LEFT__SINCE: u32 = 1;
600    /// Since when the gravity.top_right enum variant is available.
601    #[allow(dead_code)]
602    pub const ENM__GRAVITY_TOP_RIGHT__SINCE: u32 = 1;
603    /// Since when the gravity.bottom_right enum variant is available.
604    #[allow(dead_code)]
605    pub const ENM__GRAVITY_BOTTOM_RIGHT__SINCE: u32 = 1;
606
607    /// Since when the constraint_adjustment.none enum variant is available.
608    #[allow(dead_code)]
609    pub const ENM__CONSTRAINT_ADJUSTMENT_NONE__SINCE: u32 = 1;
610    /// Since when the constraint_adjustment.slide_x enum variant is available.
611    #[allow(dead_code)]
612    pub const ENM__CONSTRAINT_ADJUSTMENT_SLIDE_X__SINCE: u32 = 1;
613    /// Since when the constraint_adjustment.slide_y enum variant is available.
614    #[allow(dead_code)]
615    pub const ENM__CONSTRAINT_ADJUSTMENT_SLIDE_Y__SINCE: u32 = 1;
616    /// Since when the constraint_adjustment.flip_x enum variant is available.
617    #[allow(dead_code)]
618    pub const ENM__CONSTRAINT_ADJUSTMENT_FLIP_X__SINCE: u32 = 1;
619    /// Since when the constraint_adjustment.flip_y enum variant is available.
620    #[allow(dead_code)]
621    pub const ENM__CONSTRAINT_ADJUSTMENT_FLIP_Y__SINCE: u32 = 1;
622    /// Since when the constraint_adjustment.resize_x enum variant is available.
623    #[allow(dead_code)]
624    pub const ENM__CONSTRAINT_ADJUSTMENT_RESIZE_X__SINCE: u32 = 1;
625    /// Since when the constraint_adjustment.resize_y enum variant is available.
626    #[allow(dead_code)]
627    pub const ENM__CONSTRAINT_ADJUSTMENT_RESIZE_Y__SINCE: u32 = 1;
628}
629
630#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
631#[allow(dead_code)]
632pub struct XdgPositionerError(pub u32);
633
634impl XdgPositionerError {
635    /// invalid input provided
636    #[allow(dead_code)]
637    pub const INVALID_INPUT: Self = Self(0);
638}
639
640impl Debug for XdgPositionerError {
641    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
642        let name = match *self {
643            Self::INVALID_INPUT => "INVALID_INPUT",
644            _ => return Debug::fmt(&self.0, f),
645        };
646        f.write_str(name)
647    }
648}
649
650#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
651#[allow(dead_code)]
652pub struct XdgPositionerAnchor(pub u32);
653
654impl XdgPositionerAnchor {
655    #[allow(dead_code)]
656    pub const NONE: Self = Self(0);
657
658    #[allow(dead_code)]
659    pub const TOP: Self = Self(1);
660
661    #[allow(dead_code)]
662    pub const BOTTOM: Self = Self(2);
663
664    #[allow(dead_code)]
665    pub const LEFT: Self = Self(3);
666
667    #[allow(dead_code)]
668    pub const RIGHT: Self = Self(4);
669
670    #[allow(dead_code)]
671    pub const TOP_LEFT: Self = Self(5);
672
673    #[allow(dead_code)]
674    pub const BOTTOM_LEFT: Self = Self(6);
675
676    #[allow(dead_code)]
677    pub const TOP_RIGHT: Self = Self(7);
678
679    #[allow(dead_code)]
680    pub const BOTTOM_RIGHT: Self = Self(8);
681}
682
683impl Debug for XdgPositionerAnchor {
684    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
685        let name = match *self {
686            Self::NONE => "NONE",
687            Self::TOP => "TOP",
688            Self::BOTTOM => "BOTTOM",
689            Self::LEFT => "LEFT",
690            Self::RIGHT => "RIGHT",
691            Self::TOP_LEFT => "TOP_LEFT",
692            Self::BOTTOM_LEFT => "BOTTOM_LEFT",
693            Self::TOP_RIGHT => "TOP_RIGHT",
694            Self::BOTTOM_RIGHT => "BOTTOM_RIGHT",
695            _ => return Debug::fmt(&self.0, f),
696        };
697        f.write_str(name)
698    }
699}
700
701#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
702#[allow(dead_code)]
703pub struct XdgPositionerGravity(pub u32);
704
705impl XdgPositionerGravity {
706    #[allow(dead_code)]
707    pub const NONE: Self = Self(0);
708
709    #[allow(dead_code)]
710    pub const TOP: Self = Self(1);
711
712    #[allow(dead_code)]
713    pub const BOTTOM: Self = Self(2);
714
715    #[allow(dead_code)]
716    pub const LEFT: Self = Self(3);
717
718    #[allow(dead_code)]
719    pub const RIGHT: Self = Self(4);
720
721    #[allow(dead_code)]
722    pub const TOP_LEFT: Self = Self(5);
723
724    #[allow(dead_code)]
725    pub const BOTTOM_LEFT: Self = Self(6);
726
727    #[allow(dead_code)]
728    pub const TOP_RIGHT: Self = Self(7);
729
730    #[allow(dead_code)]
731    pub const BOTTOM_RIGHT: Self = Self(8);
732}
733
734impl Debug for XdgPositionerGravity {
735    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
736        let name = match *self {
737            Self::NONE => "NONE",
738            Self::TOP => "TOP",
739            Self::BOTTOM => "BOTTOM",
740            Self::LEFT => "LEFT",
741            Self::RIGHT => "RIGHT",
742            Self::TOP_LEFT => "TOP_LEFT",
743            Self::BOTTOM_LEFT => "BOTTOM_LEFT",
744            Self::TOP_RIGHT => "TOP_RIGHT",
745            Self::BOTTOM_RIGHT => "BOTTOM_RIGHT",
746            _ => return Debug::fmt(&self.0, f),
747        };
748        f.write_str(name)
749    }
750}
751
752/// constraint adjustments
753///
754/// The constraint adjustment value define ways the compositor will adjust
755/// the position of the surface, if the unadjusted position would result
756/// in the surface being partly constrained.
757///
758/// Whether a surface is considered 'constrained' is left to the compositor
759/// to determine. For example, the surface may be partly outside the
760/// compositor's defined 'work area', thus necessitating the child surface's
761/// position be adjusted until it is entirely inside the work area.
762///
763/// The adjustments can be combined, according to a defined precedence: 1)
764/// Flip, 2) Slide, 3) Resize.
765#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
766#[allow(dead_code)]
767pub struct XdgPositionerConstraintAdjustment(pub u32);
768
769/// An iterator over the set bits in a [XdgPositionerConstraintAdjustment].
770///
771/// You can construct this with the `IntoIterator` implementation of `XdgPositionerConstraintAdjustment`.
772#[derive(Clone, Debug)]
773#[allow(dead_code)]
774pub struct XdgPositionerConstraintAdjustmentIter(pub u32);
775
776impl XdgPositionerConstraintAdjustment {
777    /// don't move the child surface when constrained
778    ///
779    /// Don't alter the surface position even if it is constrained on some
780    /// axis, for example partially outside the edge of an output.
781    #[allow(dead_code)]
782    pub const NONE: Self = Self(0);
783
784    /// move along the x axis until unconstrained
785    ///
786    /// Slide the surface along the x axis until it is no longer constrained.
787    ///
788    /// First try to slide towards the direction of the gravity on the x axis
789    /// until either the edge in the opposite direction of the gravity is
790    /// unconstrained or the edge in the direction of the gravity is
791    /// constrained.
792    ///
793    /// Then try to slide towards the opposite direction of the gravity on the
794    /// x axis until either the edge in the direction of the gravity is
795    /// unconstrained or the edge in the opposite direction of the gravity is
796    /// constrained.
797    #[allow(dead_code)]
798    pub const SLIDE_X: Self = Self(1);
799
800    /// move along the y axis until unconstrained
801    ///
802    /// Slide the surface along the y axis until it is no longer constrained.
803    ///
804    /// First try to slide towards the direction of the gravity on the y axis
805    /// until either the edge in the opposite direction of the gravity is
806    /// unconstrained or the edge in the direction of the gravity is
807    /// constrained.
808    ///
809    /// Then try to slide towards the opposite direction of the gravity on the
810    /// y axis until either the edge in the direction of the gravity is
811    /// unconstrained or the edge in the opposite direction of the gravity is
812    /// constrained.
813    #[allow(dead_code)]
814    pub const SLIDE_Y: Self = Self(2);
815
816    /// invert the anchor and gravity on the x axis
817    ///
818    /// Invert the anchor and gravity on the x axis if the surface is
819    /// constrained on the x axis. For example, if the left edge of the
820    /// surface is constrained, the gravity is 'left' and the anchor is
821    /// 'left', change the gravity to 'right' and the anchor to 'right'.
822    ///
823    /// If the adjusted position also ends up being constrained, the resulting
824    /// position of the flip_x adjustment will be the one before the
825    /// adjustment.
826    #[allow(dead_code)]
827    pub const FLIP_X: Self = Self(4);
828
829    /// invert the anchor and gravity on the y axis
830    ///
831    /// Invert the anchor and gravity on the y axis if the surface is
832    /// constrained on the y axis. For example, if the bottom edge of the
833    /// surface is constrained, the gravity is 'bottom' and the anchor is
834    /// 'bottom', change the gravity to 'top' and the anchor to 'top'.
835    ///
836    /// The adjusted position is calculated given the original anchor
837    /// rectangle and offset, but with the new flipped anchor and gravity
838    /// values.
839    ///
840    /// If the adjusted position also ends up being constrained, the resulting
841    /// position of the flip_y adjustment will be the one before the
842    /// adjustment.
843    #[allow(dead_code)]
844    pub const FLIP_Y: Self = Self(8);
845
846    /// horizontally resize the surface
847    ///
848    /// Resize the surface horizontally so that it is completely
849    /// unconstrained.
850    #[allow(dead_code)]
851    pub const RESIZE_X: Self = Self(16);
852
853    /// vertically resize the surface
854    ///
855    /// Resize the surface vertically so that it is completely unconstrained.
856    #[allow(dead_code)]
857    pub const RESIZE_Y: Self = Self(32);
858}
859
860#[allow(dead_code)]
861impl XdgPositionerConstraintAdjustment {
862    #[inline]
863    pub const fn empty() -> Self {
864        Self(0)
865    }
866
867    #[inline]
868    #[must_use]
869    pub const fn is_empty(self) -> bool {
870        self.0 == 0
871    }
872
873    #[inline]
874    #[must_use]
875    pub const fn contains(self, other: Self) -> bool {
876        self.0 & other.0 == other.0
877    }
878
879    #[inline]
880    #[must_use]
881    pub const fn intersects(self, other: Self) -> bool {
882        self.0 & other.0 != 0
883    }
884
885    #[inline]
886    pub const fn insert(&mut self, other: Self) {
887        *self = self.union(other);
888    }
889
890    #[inline]
891    pub const fn remove(&mut self, other: Self) {
892        *self = self.difference(other);
893    }
894
895    #[inline]
896    pub const fn toggle(&mut self, other: Self) {
897        *self = self.symmetric_difference(other);
898    }
899
900    #[inline]
901    pub const fn set(&mut self, other: Self, value: bool) {
902        if value {
903            self.insert(other);
904        } else {
905            self.remove(other);
906        }
907    }
908
909    #[inline]
910    #[must_use]
911    pub const fn intersection(self, other: Self) -> Self {
912        Self(self.0 & other.0)
913    }
914
915    #[inline]
916    #[must_use]
917    pub const fn union(self, other: Self) -> Self {
918        Self(self.0 | other.0)
919    }
920
921    #[inline]
922    #[must_use]
923    pub const fn difference(self, other: Self) -> Self {
924        Self(self.0 & !other.0)
925    }
926
927    #[inline]
928    #[must_use]
929    pub const fn complement(self) -> Self {
930        Self(!self.0)
931    }
932
933    #[inline]
934    #[must_use]
935    pub const fn symmetric_difference(self, other: Self) -> Self {
936        Self(self.0 ^ other.0)
937    }
938
939    #[inline]
940    pub const fn all_known() -> Self {
941        #[allow(clippy::eq_op, clippy::identity_op)]
942        Self(0 | 0 | 1 | 2 | 4 | 8 | 16 | 32)
943    }
944}
945
946impl Iterator for XdgPositionerConstraintAdjustmentIter {
947    type Item = XdgPositionerConstraintAdjustment;
948
949    fn next(&mut self) -> Option<Self::Item> {
950        if self.0 == 0 {
951            return None;
952        }
953        let bit = 1 << self.0.trailing_zeros();
954        self.0 &= !bit;
955        Some(XdgPositionerConstraintAdjustment(bit))
956    }
957}
958
959impl IntoIterator for XdgPositionerConstraintAdjustment {
960    type Item = XdgPositionerConstraintAdjustment;
961    type IntoIter = XdgPositionerConstraintAdjustmentIter;
962
963    fn into_iter(self) -> Self::IntoIter {
964        XdgPositionerConstraintAdjustmentIter(self.0)
965    }
966}
967
968impl BitAnd for XdgPositionerConstraintAdjustment {
969    type Output = Self;
970
971    fn bitand(self, rhs: Self) -> Self::Output {
972        self.intersection(rhs)
973    }
974}
975
976impl BitAndAssign for XdgPositionerConstraintAdjustment {
977    fn bitand_assign(&mut self, rhs: Self) {
978        *self = self.intersection(rhs);
979    }
980}
981
982impl BitOr for XdgPositionerConstraintAdjustment {
983    type Output = Self;
984
985    fn bitor(self, rhs: Self) -> Self::Output {
986        self.union(rhs)
987    }
988}
989
990impl BitOrAssign for XdgPositionerConstraintAdjustment {
991    fn bitor_assign(&mut self, rhs: Self) {
992        *self = self.union(rhs);
993    }
994}
995
996impl BitXor for XdgPositionerConstraintAdjustment {
997    type Output = Self;
998
999    fn bitxor(self, rhs: Self) -> Self::Output {
1000        self.symmetric_difference(rhs)
1001    }
1002}
1003
1004impl BitXorAssign for XdgPositionerConstraintAdjustment {
1005    fn bitxor_assign(&mut self, rhs: Self) {
1006        *self = self.symmetric_difference(rhs);
1007    }
1008}
1009
1010impl Sub for XdgPositionerConstraintAdjustment {
1011    type Output = Self;
1012
1013    fn sub(self, rhs: Self) -> Self::Output {
1014        self.difference(rhs)
1015    }
1016}
1017
1018impl SubAssign for XdgPositionerConstraintAdjustment {
1019    fn sub_assign(&mut self, rhs: Self) {
1020        *self = self.difference(rhs);
1021    }
1022}
1023
1024impl Not for XdgPositionerConstraintAdjustment {
1025    type Output = Self;
1026
1027    fn not(self) -> Self::Output {
1028        self.complement()
1029    }
1030}
1031
1032impl Debug for XdgPositionerConstraintAdjustment {
1033    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1034        let mut v = self.0;
1035        let mut first = true;
1036        if v & 1 == 1 {
1037            v &= !1;
1038            if first {
1039                first = false;
1040            } else {
1041                f.write_str(" | ")?;
1042            }
1043            f.write_str("SLIDE_X")?;
1044        }
1045        if v & 2 == 2 {
1046            v &= !2;
1047            if first {
1048                first = false;
1049            } else {
1050                f.write_str(" | ")?;
1051            }
1052            f.write_str("SLIDE_Y")?;
1053        }
1054        if v & 4 == 4 {
1055            v &= !4;
1056            if first {
1057                first = false;
1058            } else {
1059                f.write_str(" | ")?;
1060            }
1061            f.write_str("FLIP_X")?;
1062        }
1063        if v & 8 == 8 {
1064            v &= !8;
1065            if first {
1066                first = false;
1067            } else {
1068                f.write_str(" | ")?;
1069            }
1070            f.write_str("FLIP_Y")?;
1071        }
1072        if v & 16 == 16 {
1073            v &= !16;
1074            if first {
1075                first = false;
1076            } else {
1077                f.write_str(" | ")?;
1078            }
1079            f.write_str("RESIZE_X")?;
1080        }
1081        if v & 32 == 32 {
1082            v &= !32;
1083            if first {
1084                first = false;
1085            } else {
1086                f.write_str(" | ")?;
1087            }
1088            f.write_str("RESIZE_Y")?;
1089        }
1090        if v != 0 {
1091            if first {
1092                first = false;
1093            } else {
1094                f.write_str(" | ")?;
1095            }
1096            write!(f, "0x{v:032x}")?;
1097        }
1098        if first {
1099            f.write_str("NONE")?;
1100        }
1101        Ok(())
1102    }
1103}
1104
1105/// Functional event handlers.
1106pub mod event_handlers {
1107    use super::*;
1108
1109    impl XdgPositioner {}
1110}