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
impl MonitorHandle
Sourcepub fn name(&self) -> Option<String>
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?
226 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
227 info!("Monitors information");
228 let primary_monitor = event_loop.primary_monitor();
229 for monitor in event_loop.available_monitors() {
230 let intro = if primary_monitor.as_ref() == Some(&monitor) {
231 "Primary monitor"
232 } else {
233 "Monitor"
234 };
235
236 if let Some(name) = monitor.name() {
237 info!("{intro}: {name}");
238 } else {
239 info!("{intro}: [no name]");
240 }
241
242 let PhysicalSize { width, height } = monitor.size();
243 info!(
244 " Current mode: {width}x{height}{}",
245 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
246 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
247 } else {
248 String::new()
249 }
250 );
251
252 let PhysicalPosition { x, y } = monitor.position();
253 info!(" Position: {x},{y}");
254
255 info!(" Scale factor: {}", monitor.scale_factor());
256
257 info!(" Available modes (width x height x bit-depth):");
258 for mode in monitor.video_modes() {
259 let PhysicalSize { width, height } = mode.size();
260 let bits = mode.bit_depth();
261 let m_hz = mode.refresh_rate_millihertz();
262 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
263 }
264 }
265 }Sourcepub fn size(&self) -> PhysicalSize<u32>
pub fn size(&self) -> PhysicalSize<u32>
Returns the monitor’s resolution.
Examples found in repository?
226 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
227 info!("Monitors information");
228 let primary_monitor = event_loop.primary_monitor();
229 for monitor in event_loop.available_monitors() {
230 let intro = if primary_monitor.as_ref() == Some(&monitor) {
231 "Primary monitor"
232 } else {
233 "Monitor"
234 };
235
236 if let Some(name) = monitor.name() {
237 info!("{intro}: {name}");
238 } else {
239 info!("{intro}: [no name]");
240 }
241
242 let PhysicalSize { width, height } = monitor.size();
243 info!(
244 " Current mode: {width}x{height}{}",
245 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
246 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
247 } else {
248 String::new()
249 }
250 );
251
252 let PhysicalPosition { x, y } = monitor.position();
253 info!(" Position: {x},{y}");
254
255 info!(" Scale factor: {}", monitor.scale_factor());
256
257 info!(" Available modes (width x height x bit-depth):");
258 for mode in monitor.video_modes() {
259 let PhysicalSize { width, height } = mode.size();
260 let bits = mode.bit_depth();
261 let m_hz = mode.refresh_rate_millihertz();
262 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
263 }
264 }
265 }Sourcepub fn position(&self) -> PhysicalPosition<i32>
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?
226 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
227 info!("Monitors information");
228 let primary_monitor = event_loop.primary_monitor();
229 for monitor in event_loop.available_monitors() {
230 let intro = if primary_monitor.as_ref() == Some(&monitor) {
231 "Primary monitor"
232 } else {
233 "Monitor"
234 };
235
236 if let Some(name) = monitor.name() {
237 info!("{intro}: {name}");
238 } else {
239 info!("{intro}: [no name]");
240 }
241
242 let PhysicalSize { width, height } = monitor.size();
243 info!(
244 " Current mode: {width}x{height}{}",
245 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
246 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
247 } else {
248 String::new()
249 }
250 );
251
252 let PhysicalPosition { x, y } = monitor.position();
253 info!(" Position: {x},{y}");
254
255 info!(" Scale factor: {}", monitor.scale_factor());
256
257 info!(" Available modes (width x height x bit-depth):");
258 for mode in monitor.video_modes() {
259 let PhysicalSize { width, height } = mode.size();
260 let bits = mode.bit_depth();
261 let m_hz = mode.refresh_rate_millihertz();
262 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
263 }
264 }
265 }Sourcepub fn refresh_rate_millihertz(&self) -> Option<u32>
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?
226 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
227 info!("Monitors information");
228 let primary_monitor = event_loop.primary_monitor();
229 for monitor in event_loop.available_monitors() {
230 let intro = if primary_monitor.as_ref() == Some(&monitor) {
231 "Primary monitor"
232 } else {
233 "Monitor"
234 };
235
236 if let Some(name) = monitor.name() {
237 info!("{intro}: {name}");
238 } else {
239 info!("{intro}: [no name]");
240 }
241
242 let PhysicalSize { width, height } = monitor.size();
243 info!(
244 " Current mode: {width}x{height}{}",
245 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
246 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
247 } else {
248 String::new()
249 }
250 );
251
252 let PhysicalPosition { x, y } = monitor.position();
253 info!(" Position: {x},{y}");
254
255 info!(" Scale factor: {}", monitor.scale_factor());
256
257 info!(" Available modes (width x height x bit-depth):");
258 for mode in monitor.video_modes() {
259 let PhysicalSize { width, height } = mode.size();
260 let bits = mode.bit_depth();
261 let m_hz = mode.refresh_rate_millihertz();
262 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
263 }
264 }
265 }Sourcepub fn scale_factor(&self) -> f64
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_FACTORenvironment variable. - Wayland: May differ from
Window::scale_factor. - Android: Always returns 1.0.
Examples found in repository?
226 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
227 info!("Monitors information");
228 let primary_monitor = event_loop.primary_monitor();
229 for monitor in event_loop.available_monitors() {
230 let intro = if primary_monitor.as_ref() == Some(&monitor) {
231 "Primary monitor"
232 } else {
233 "Monitor"
234 };
235
236 if let Some(name) = monitor.name() {
237 info!("{intro}: {name}");
238 } else {
239 info!("{intro}: [no name]");
240 }
241
242 let PhysicalSize { width, height } = monitor.size();
243 info!(
244 " Current mode: {width}x{height}{}",
245 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
246 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
247 } else {
248 String::new()
249 }
250 );
251
252 let PhysicalPosition { x, y } = monitor.position();
253 info!(" Position: {x},{y}");
254
255 info!(" Scale factor: {}", monitor.scale_factor());
256
257 info!(" Available modes (width x height x bit-depth):");
258 for mode in monitor.video_modes() {
259 let PhysicalSize { width, height } = mode.size();
260 let bits = mode.bit_depth();
261 let m_hz = mode.refresh_rate_millihertz();
262 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
263 }
264 }
265 }Sourcepub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle>
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?
226 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
227 info!("Monitors information");
228 let primary_monitor = event_loop.primary_monitor();
229 for monitor in event_loop.available_monitors() {
230 let intro = if primary_monitor.as_ref() == Some(&monitor) {
231 "Primary monitor"
232 } else {
233 "Monitor"
234 };
235
236 if let Some(name) = monitor.name() {
237 info!("{intro}: {name}");
238 } else {
239 info!("{intro}: [no name]");
240 }
241
242 let PhysicalSize { width, height } = monitor.size();
243 info!(
244 " Current mode: {width}x{height}{}",
245 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
246 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
247 } else {
248 String::new()
249 }
250 );
251
252 let PhysicalPosition { x, y } = monitor.position();
253 info!(" Position: {x},{y}");
254
255 info!(" Scale factor: {}", monitor.scale_factor());
256
257 info!(" Available modes (width x height x bit-depth):");
258 for mode in monitor.video_modes() {
259 let PhysicalSize { width, height } = mode.size();
260 let bits = mode.bit_depth();
261 let m_hz = mode.refresh_rate_millihertz();
262 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
263 }
264 }
265 }Trait Implementations§
Source§impl Clone for MonitorHandle
impl Clone for MonitorHandle
Source§fn clone(&self) -> MonitorHandle
fn clone(&self) -> MonitorHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MonitorHandle
impl Debug for MonitorHandle
Source§impl MonitorHandleExtIOS for MonitorHandle
Available on ios_platform only.
impl MonitorHandleExtIOS for MonitorHandle
ios_platform only.Source§fn ui_screen(&self) -> *mut c_void
fn ui_screen(&self) -> *mut c_void
UIScreen that is used by this monitor.Source§fn preferred_video_mode(&self) -> VideoModeHandle
fn preferred_video_mode(&self) -> VideoModeHandle
VideoModeHandle for this monitor. Read moreSource§impl MonitorHandleExtMacOS for MonitorHandle
Available on macos_platform only.
impl MonitorHandleExtMacOS for MonitorHandle
macos_platform only.Source§impl MonitorHandleExtWayland for MonitorHandle
Available on wayland_platform only.
impl MonitorHandleExtWayland for MonitorHandle
wayland_platform only.Source§impl MonitorHandleExtWindows for MonitorHandle
Available on windows_platform only.
impl MonitorHandleExtWindows for MonitorHandle
windows_platform only.Source§impl MonitorHandleExtX11 for MonitorHandle
Available on x11_platform only.
impl MonitorHandleExtX11 for MonitorHandle
x11_platform only.