Skip to main content

MonitorInfo

Struct MonitorInfo 

Source
pub struct MonitorInfo {
    pub id: MonitorId,
    pub name: String,
    pub bounds: PhysicalRect,
    pub work_area: PhysicalRect,
    pub scale_factor: f64,
    pub refresh_millihertz: u32,
    pub is_primary: bool,
}
Expand description

What the shell knows about one monitor.

Owned rather than borrowed: enumeration happens at startup and on hotplug, so the String is not worth avoiding, and borrowing from the shell would infect every consumer with a lifetime — the same argument crcbl-hal’s AdapterInfo makes.

Not Eq: scale_factor is an f64. A settings screen diffing two of these gets PartialEq, which is the correct relation for a struct holding a float.

Fields§

§id: MonitorId

Stable id for this monitor within the session.

§name: String

Human-readable name, e.g. "DP-2" or "Dell U2723QE".

For settings UI and logs only. Never key behaviour off it: it is not unique (two identical monitors report identical names on some drivers) and it is not stable across drivers.

§bounds: PhysicalRect

Position and size in the desktop’s device-pixel coordinate space.

The origin is wherever the window system puts it, and coordinates are signed because a monitor placed left of or above the primary one has negative ones.

On Wayland this comes from xdg_output logical geometry scaled back to pixels by that output’s own scale; a compositor without xdg_output falls back to wl_output.geometry, whose position is logical while its size is physical, so the two only agree at scale 1.

There is a limit to how meaningful this can be, and it is worth knowing before building a layout on it: on a desktop whose outputs run at different scales there is no single device-pixel coordinate space at all, and these rectangles will not tile — a 1× monitor beside a 2× one has two device-pixel spaces, and only the compositor’s logical space is globally coherent. This type cannot express that, so it reports each monitor in its own pixels. Use it to name a monitor and to tell a settings screen which one is on the left; do not use it as a desktop layout. ShellCaps::WINDOW_POSITION is the bit that says a window can be placed, and Wayland never sets it.

§work_area: PhysicalRect

The part of bounds not covered by panels, docks or taskbars.

What a windowed window should be placed within. Equal to bounds when the backend cannot find out — Wayland has no protocol for it, so the Wayland backend will report the full area and nothing may assume otherwise.

§scale_factor: f64

Device pixels per logical unit, e.g. 1.0, 1.5, 2.0.

Fractional values only appear when ShellCaps::FRACTIONAL_SCALE is set. Note that a window’s scale factor is not necessarily any monitor’s: a window straddling two outputs gets one of them, chosen by the compositor, and it can change while the window is dragged — which is what ShellEvent::ScaleFactorChanged is for.

§refresh_millihertz: u32

Refresh rate in millihertz — 60_000 for 60 Hz, 59_940 for 59.94 Hz.

Zero when the backend cannot determine it (a virtual output, a browser canvas). See the module docs for the unit choice.

§is_primary: bool

Whether the window system calls this the primary monitor.

Wayland has no such concept, so a Wayland backend marks the first output it sees. Use it as a default, never as a guarantee.

Implementations§

Source§

impl MonitorInfo

Source

pub fn refresh_hz(&self) -> f64

Refresh rate in hertz, for display and frame pacing.

Source

pub fn frame_period(&self) -> Option<Duration>

The frame period implied by refresh_hz, or None if the rate is unknown.

Source

pub const fn size(&self) -> PhysicalSize

The monitor’s resolution in device pixels.

Trait Implementations§

Source§

impl Clone for MonitorInfo

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 Debug for MonitorInfo

Source§

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

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

impl PartialEq for MonitorInfo

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 MonitorInfo

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.