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”:
requested_modeandrequested_constraintsare what we asked for. They are always known, because we said them.configurationis what the window system did. It isNoneuntil the first configure arrives, and itsmodecan disagree with the requested one forever.
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: DisplayModeThe mode most recently asked for through
Shell::set_mode or
WindowDesc::mode.
requested_constraints: SizeConstraintsThe constraints most recently asked for. Hints; see
SizeConstraints.
focused: boolWhether this window has keyboard focus.
visible: boolWhether the window is mapped and not minimized.
pointer_mode: PointerModeCurrent pointer mode; see PointerMode.
close_pending: boolWhether a CloseRequested is
awaiting a reply_close_request.
Implementations§
Source§impl WindowState
impl WindowState
Sourcepub fn size(&self) -> Option<PhysicalSize>
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.
Sourcepub fn scale_factor(&self) -> Option<f64>
pub fn scale_factor(&self) -> Option<f64>
Device pixels per logical unit, or None while the window is
unconfigured.
Sourcepub fn effective_mode(&self) -> Option<DisplayMode>
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.
Sourcepub const fn is_configured(&self) -> bool
pub const fn is_configured(&self) -> bool
Whether the window system has reported a size yet.
Sourcepub fn mode_request_honoured(&self) -> bool
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.