Skip to main content

WindowState

Struct WindowState 

Source
pub struct WindowState {
    pub configuration: Option<WindowConfiguration>,
    pub requested_mode: DisplayMode,
    pub requested_constraints: SizeConstraints,
    pub focused: bool,
    pub visible: bool,
    pub pointer_mode: PointerMode,
    pub close_pending: bool,
}
Expand description

A window’s current, observable state.

Returned by Shell::window_state as a snapshot by value. It exists so a consumer that missed an event — a system that started late, an editor panel that was just opened — can ask, instead of having to have watched the whole event stream from the beginning.

It is not a substitute for the events: a renderer that polls this every frame instead of handling ShellEvent::Resized will recreate its swapchain a frame late.

§Requested versus effective

The split down the middle of this struct is the seam’s answer to “a window request is not a window command”:

Nothing here reports “effective constraints”, because no platform has such a concept: min/max/aspect are hints whose only observable effect is the size in configuration.

Fields§

§configuration: Option<WindowConfiguration>

What the window system has told us, or None if it has not yet.

See WindowState::size for the ordering constraint this creates.

§requested_mode: DisplayMode

The mode most recently asked for through Shell::set_mode or WindowDesc::mode.

§requested_constraints: SizeConstraints

The constraints most recently asked for. Hints; see SizeConstraints.

§focused: bool

Whether this window has keyboard focus.

§visible: bool

Whether the window is mapped and not minimized.

§pointer_mode: PointerMode

Current pointer mode; see PointerMode.

§close_pending: bool

Whether a CloseRequested is awaiting a reply_close_request.

Implementations§

Source§

impl WindowState

Source

pub fn size(&self) -> Option<PhysicalSize>

The client area in device pixels, or None while the window is unconfigured.

§This is the swapchain ordering constraint

A freshly created window has no size. On Wayland an xdg_surface is not sized — and must not be given a buffer — until the compositor answers with a configure, which is a round trip away. A swapchain needs an extent, so the mandatory sequence is:

let window = shell.create_window(&desc)?;
loop {
    shell.pump(&mut |event| { … });          // ← the first Resized
    if let Some(size) = shell.window_state(window)?.size() {
        create_swapchain(size);              // only now
        break;
    }
}

HeadlessShell deliberately defers the first configure by at least one pump so that this sequence is exercised rather than merely documented — a test double that succeeds immediately proves nothing about the code path that matters.

Source

pub fn scale_factor(&self) -> Option<f64>

Device pixels per logical unit, or None while the window is unconfigured.

Source

pub fn effective_mode(&self) -> Option<DisplayMode>

The mode actually in effect, or None while the window is unconfigured.

Compare requested_mode — they can differ.

Source

pub const fn is_configured(&self) -> bool

Whether the window system has reported a size yet.

Source

pub fn mode_request_honoured(&self) -> bool

Whether the window system honoured the last mode request.

false while unconfigured (nothing has been honoured yet) and false when a compositor refused. A UI showing a fullscreen toggle reads this, not requested_mode, or the checkbox lies.

The comparison is DisplayMode::satisfied_by rather than ==; see there for why a request naming no monitor is answered by one that does.

Trait Implementations§

Source§

impl Clone for WindowState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for WindowState

Source§

impl Debug for WindowState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for WindowState

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for WindowState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.