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: MonitorIdStable id for this monitor within the session.
name: StringHuman-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: PhysicalRectPosition 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: PhysicalRectThe 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: f64Device 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: u32Refresh 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: boolWhether 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
impl MonitorInfo
Sourcepub fn refresh_hz(&self) -> f64
pub fn refresh_hz(&self) -> f64
Refresh rate in hertz, for display and frame pacing.
Sourcepub fn frame_period(&self) -> Option<Duration>
pub fn frame_period(&self) -> Option<Duration>
The frame period implied by refresh_hz, or None
if the rate is unknown.
Sourcepub const fn size(&self) -> PhysicalSize
pub const fn size(&self) -> PhysicalSize
The monitor’s resolution in device pixels.