Struct MonitorHandle

Source
pub struct MonitorHandle { /* private fields */ }
Expand description

Handle to a monitor.

Allows you to retrieve information about a given monitor and can be used in Window creation.

Implementations§

Source§

impl MonitorHandle

Source

pub fn name(&self) -> Option<String>

Returns a human-readable name of the monitor.

Returns None if the monitor doesn’t exist anymore.

Examples found in repository?
examples/window.rs (line 249)
239    fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
240        info!("Monitors information");
241        let primary_monitor = event_loop.primary_monitor();
242        for monitor in event_loop.available_monitors() {
243            let intro = if primary_monitor.as_ref() == Some(&monitor) {
244                "Primary monitor"
245            } else {
246                "Monitor"
247            };
248
249            if let Some(name) = monitor.name() {
250                info!("{intro}: {name}");
251            } else {
252                info!("{intro}: [no name]");
253            }
254
255            let PhysicalSize { width, height } = monitor.size();
256            info!(
257                "  Current mode: {width}x{height}{}",
258                if let Some(m_hz) = monitor.refresh_rate_millihertz() {
259                    format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
260                } else {
261                    String::new()
262                }
263            );
264
265            let PhysicalPosition { x, y } = monitor.position();
266            info!("  Position: {x},{y}");
267
268            info!("  Scale factor: {}", monitor.scale_factor());
269
270            info!("  Available modes (width x height x bit-depth):");
271            for mode in monitor.video_modes() {
272                let PhysicalSize { width, height } = mode.size();
273                let bits = mode.bit_depth();
274                let m_hz = mode.refresh_rate_millihertz();
275                info!(
276                    "    {width}x{height}x{bits} @ {}.{} Hz",
277                    m_hz / 1000,
278                    m_hz % 1000
279                );
280            }
281        }
282    }
Source

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

Returns the monitor’s resolution.

Examples found in repository?
examples/window.rs (line 255)
239    fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
240        info!("Monitors information");
241        let primary_monitor = event_loop.primary_monitor();
242        for monitor in event_loop.available_monitors() {
243            let intro = if primary_monitor.as_ref() == Some(&monitor) {
244                "Primary monitor"
245            } else {
246                "Monitor"
247            };
248
249            if let Some(name) = monitor.name() {
250                info!("{intro}: {name}");
251            } else {
252                info!("{intro}: [no name]");
253            }
254
255            let PhysicalSize { width, height } = monitor.size();
256            info!(
257                "  Current mode: {width}x{height}{}",
258                if let Some(m_hz) = monitor.refresh_rate_millihertz() {
259                    format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
260                } else {
261                    String::new()
262                }
263            );
264
265            let PhysicalPosition { x, y } = monitor.position();
266            info!("  Position: {x},{y}");
267
268            info!("  Scale factor: {}", monitor.scale_factor());
269
270            info!("  Available modes (width x height x bit-depth):");
271            for mode in monitor.video_modes() {
272                let PhysicalSize { width, height } = mode.size();
273                let bits = mode.bit_depth();
274                let m_hz = mode.refresh_rate_millihertz();
275                info!(
276                    "    {width}x{height}x{bits} @ {}.{} Hz",
277                    m_hz / 1000,
278                    m_hz % 1000
279                );
280            }
281        }
282    }
Source

pub fn position(&self) -> PhysicalPosition<i32>

Returns the top-left corner position of the monitor relative to the larger full screen area.

Examples found in repository?
examples/window.rs (line 265)
239    fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
240        info!("Monitors information");
241        let primary_monitor = event_loop.primary_monitor();
242        for monitor in event_loop.available_monitors() {
243            let intro = if primary_monitor.as_ref() == Some(&monitor) {
244                "Primary monitor"
245            } else {
246                "Monitor"
247            };
248
249            if let Some(name) = monitor.name() {
250                info!("{intro}: {name}");
251            } else {
252                info!("{intro}: [no name]");
253            }
254
255            let PhysicalSize { width, height } = monitor.size();
256            info!(
257                "  Current mode: {width}x{height}{}",
258                if let Some(m_hz) = monitor.refresh_rate_millihertz() {
259                    format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
260                } else {
261                    String::new()
262                }
263            );
264
265            let PhysicalPosition { x, y } = monitor.position();
266            info!("  Position: {x},{y}");
267
268            info!("  Scale factor: {}", monitor.scale_factor());
269
270            info!("  Available modes (width x height x bit-depth):");
271            for mode in monitor.video_modes() {
272                let PhysicalSize { width, height } = mode.size();
273                let bits = mode.bit_depth();
274                let m_hz = mode.refresh_rate_millihertz();
275                info!(
276                    "    {width}x{height}x{bits} @ {}.{} Hz",
277                    m_hz / 1000,
278                    m_hz % 1000
279                );
280            }
281        }
282    }
Source

pub fn refresh_rate_millihertz(&self) -> Option<u32>

The monitor refresh rate used by the system.

Return Some if succeed, or None if failed, which usually happens when the monitor the window is on is removed.

When using exclusive fullscreen, the refresh rate of the VideoModeHandle that was used to enter fullscreen should be used instead.

Examples found in repository?
examples/window.rs (line 258)
239    fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
240        info!("Monitors information");
241        let primary_monitor = event_loop.primary_monitor();
242        for monitor in event_loop.available_monitors() {
243            let intro = if primary_monitor.as_ref() == Some(&monitor) {
244                "Primary monitor"
245            } else {
246                "Monitor"
247            };
248
249            if let Some(name) = monitor.name() {
250                info!("{intro}: {name}");
251            } else {
252                info!("{intro}: [no name]");
253            }
254
255            let PhysicalSize { width, height } = monitor.size();
256            info!(
257                "  Current mode: {width}x{height}{}",
258                if let Some(m_hz) = monitor.refresh_rate_millihertz() {
259                    format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
260                } else {
261                    String::new()
262                }
263            );
264
265            let PhysicalPosition { x, y } = monitor.position();
266            info!("  Position: {x},{y}");
267
268            info!("  Scale factor: {}", monitor.scale_factor());
269
270            info!("  Available modes (width x height x bit-depth):");
271            for mode in monitor.video_modes() {
272                let PhysicalSize { width, height } = mode.size();
273                let bits = mode.bit_depth();
274                let m_hz = mode.refresh_rate_millihertz();
275                info!(
276                    "    {width}x{height}x{bits} @ {}.{} Hz",
277                    m_hz / 1000,
278                    m_hz % 1000
279                );
280            }
281        }
282    }
Source

pub fn scale_factor(&self) -> f64

Returns the scale factor of the underlying monitor. To map logical pixels to physical pixels and vice versa, use Window::scale_factor.

See the dpi module for more information.

§Platform-specific
  • X11: Can be overridden using the WINIT_X11_SCALE_FACTOR environment variable.
  • Wayland: May differ from Window::scale_factor.
  • Android: Always returns 1.0.
Examples found in repository?
examples/window.rs (line 268)
239    fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
240        info!("Monitors information");
241        let primary_monitor = event_loop.primary_monitor();
242        for monitor in event_loop.available_monitors() {
243            let intro = if primary_monitor.as_ref() == Some(&monitor) {
244                "Primary monitor"
245            } else {
246                "Monitor"
247            };
248
249            if let Some(name) = monitor.name() {
250                info!("{intro}: {name}");
251            } else {
252                info!("{intro}: [no name]");
253            }
254
255            let PhysicalSize { width, height } = monitor.size();
256            info!(
257                "  Current mode: {width}x{height}{}",
258                if let Some(m_hz) = monitor.refresh_rate_millihertz() {
259                    format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
260                } else {
261                    String::new()
262                }
263            );
264
265            let PhysicalPosition { x, y } = monitor.position();
266            info!("  Position: {x},{y}");
267
268            info!("  Scale factor: {}", monitor.scale_factor());
269
270            info!("  Available modes (width x height x bit-depth):");
271            for mode in monitor.video_modes() {
272                let PhysicalSize { width, height } = mode.size();
273                let bits = mode.bit_depth();
274                let m_hz = mode.refresh_rate_millihertz();
275                info!(
276                    "    {width}x{height}x{bits} @ {}.{} Hz",
277                    m_hz / 1000,
278                    m_hz % 1000
279                );
280            }
281        }
282    }
Source

pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle>

Returns all fullscreen video modes supported by this monitor.

§Platform-specific
  • Web: Always returns an empty iterator
Examples found in repository?
examples/window.rs (line 271)
239    fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
240        info!("Monitors information");
241        let primary_monitor = event_loop.primary_monitor();
242        for monitor in event_loop.available_monitors() {
243            let intro = if primary_monitor.as_ref() == Some(&monitor) {
244                "Primary monitor"
245            } else {
246                "Monitor"
247            };
248
249            if let Some(name) = monitor.name() {
250                info!("{intro}: {name}");
251            } else {
252                info!("{intro}: [no name]");
253            }
254
255            let PhysicalSize { width, height } = monitor.size();
256            info!(
257                "  Current mode: {width}x{height}{}",
258                if let Some(m_hz) = monitor.refresh_rate_millihertz() {
259                    format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
260                } else {
261                    String::new()
262                }
263            );
264
265            let PhysicalPosition { x, y } = monitor.position();
266            info!("  Position: {x},{y}");
267
268            info!("  Scale factor: {}", monitor.scale_factor());
269
270            info!("  Available modes (width x height x bit-depth):");
271            for mode in monitor.video_modes() {
272                let PhysicalSize { width, height } = mode.size();
273                let bits = mode.bit_depth();
274                let m_hz = mode.refresh_rate_millihertz();
275                info!(
276                    "    {width}x{height}x{bits} @ {}.{} Hz",
277                    m_hz / 1000,
278                    m_hz % 1000
279                );
280            }
281        }
282    }

Trait Implementations§

Source§

impl Clone for MonitorHandle

Source§

fn clone(&self) -> MonitorHandle

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MonitorHandle

Source§

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

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

impl MonitorHandleExtMacOS for MonitorHandle

Source§

fn native_id(&self) -> u32

Returns the identifier of the monitor for Cocoa.
Source§

fn ns_screen(&self) -> Option<*mut c_void>

Returns a pointer to the NSScreen representing this monitor.
Source§

impl MonitorHandleExtWayland for MonitorHandle

Source§

fn native_id(&self) -> u32

Returns the inner identifier of the monitor.
Source§

impl MonitorHandleExtWindows for MonitorHandle

Source§

fn native_id(&self) -> String

Returns the name of the monitor adapter specific to the Win32 API.
Source§

fn hmonitor(&self) -> HMONITOR

Returns the handle of the monitor - HMONITOR.
Source§

impl MonitorHandleExtX11 for MonitorHandle

Source§

fn native_id(&self) -> u32

Returns the inner identifier of the monitor.
Source§

impl Ord for MonitorHandle

Source§

fn cmp(&self, other: &MonitorHandle) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for MonitorHandle

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for MonitorHandle

Source§

fn partial_cmp(&self, other: &MonitorHandle) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for MonitorHandle

Source§

impl StructuralPartialEq for MonitorHandle

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, dst: *mut u8)

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

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more