Skip to main content

winit_core/window/
positioner.rs

1//! Anchor-based window placement: the types describing a placement request.
2//!
3//! The `xdg_positioner`-style algorithm that resolves these into a concrete position and size
4//! lives in `winit-common`, since it's only needed by backends without a native equivalent of
5//! Wayland's `xdg_positioner` (such as Win32 and AppKit) and isn't part of winit's public API.
6
7/// Anchor rect within the parent surface
8/// See: https://wayland.app/protocols/xdg-shell#xdg_positioner:request:set_anchor_rect
9#[derive(Debug, Clone, Copy, Default, PartialEq)]
10#[non_exhaustive]
11pub enum WindowAnchor {
12    #[default]
13    Center,
14    Top,
15    Bottom,
16    Left,
17    Right,
18    TopLeft,
19    BottomLeft,
20    TopRight,
21    BottomRight,
22}
23
24/// Defines in what direction a surface should be positioned
25/// See: https://wayland.app/protocols/xdg-shell#xdg_positioner:request:set_gravity
26#[derive(Debug, Clone, Copy, Default, PartialEq)]
27#[non_exhaustive]
28pub enum WindowGravity {
29    #[default]
30    Center,
31    Top,
32    Bottom,
33    Left,
34    Right,
35    TopLeft,
36    BottomLeft,
37    TopRight,
38    BottomRight,
39}
40
41bitflags::bitflags! {
42    /// Specify how the window should be positioned if the originally intended position caused the
43    /// surface to be constrained See: https://wayland.app/protocols/xdg-shell#xdg_positioner:request:set_constraint_adjustment
44    /// For all other platforms than wayland the behaviour is simulated on the winit side
45    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
46    pub struct WindowConstraintAdjustment: u32 {
47        const SLIDE_X = 1 << 0;
48        const SLIDE_Y = 1 << 1;
49        const FLIP_X = 1 << 2;
50        const FLIP_Y = 1 << 3;
51        const RESIZE_X = 1 << 4;
52        const RESIZE_Y = 1 << 5;
53    }
54}