pub struct MonitorInfo {
pub id: MonitorId,
pub name: String,
pub connector: Option<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.
connector: Option<String>The connector the window system reported for this monitor, e.g.
"DP-2" or "HDMI-A-1" — the name to match against another protocol’s
view of the same output, such as wlr-output-management’s head.name.
Some only when the platform reported one: on Wayland the
wl_output.name event (wl_output version 4 and later), else
zxdg_output_v1.name; on X11 the RandR output’s name. A reported name
is passed through as is, so it can coincide with a placeholder’s
spelling (Xvfb’s one RandR output is named screen) or be one no other
protocol uses (RandR 1.0 emulation’s default). On Wayland the name can
arrive after the output first appears; the monitor list is republished
with it, under a MonitorsChanged,
when it does.
None whenever name is a placeholder the backend made
up (wl-output-N on Wayland; output-N, CRTC-N, and screen without
RandR, on X11),
and always on Win32, AppKit, the web and the headless shell, which have
no connector name to report.
Like name, it is not guaranteed unique and is not a substitute for
id within this shell.
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.