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?
256 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
257 info!("Monitors information");
258 let primary_monitor = event_loop.primary_monitor();
259 for monitor in event_loop.available_monitors() {
260 let intro = if primary_monitor.as_ref() == Some(&monitor) {
261 "Primary monitor"
262 } else {
263 "Monitor"
264 };
265
266 if let Some(name) = monitor.name() {
267 info!("{intro}: {name}");
268 } else {
269 info!("{intro}: [no name]");
270 }
271
272 let PhysicalSize { width, height } = monitor.size();
273 info!(
274 " Current mode: {width}x{height}{}",
275 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
276 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
277 } else {
278 String::new()
279 }
280 );
281
282 let PhysicalPosition { x, y } = monitor.position();
283 info!(" Position: {x},{y}");
284
285 info!(" Scale factor: {}", monitor.scale_factor());
286
287 info!(" Available modes (width x height x bit-depth):");
288 for mode in monitor.video_modes() {
289 let PhysicalSize { width, height } = mode.size();
290 let bits = mode.bit_depth();
291 let m_hz = mode.refresh_rate_millihertz();
292 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
293 }
294 }
295 }Sourcepub fn size(&self) -> PhysicalSize<u32>
pub fn size(&self) -> PhysicalSize<u32>
Returns the monitor’s resolution.
Examples found in repository?
256 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
257 info!("Monitors information");
258 let primary_monitor = event_loop.primary_monitor();
259 for monitor in event_loop.available_monitors() {
260 let intro = if primary_monitor.as_ref() == Some(&monitor) {
261 "Primary monitor"
262 } else {
263 "Monitor"
264 };
265
266 if let Some(name) = monitor.name() {
267 info!("{intro}: {name}");
268 } else {
269 info!("{intro}: [no name]");
270 }
271
272 let PhysicalSize { width, height } = monitor.size();
273 info!(
274 " Current mode: {width}x{height}{}",
275 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
276 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
277 } else {
278 String::new()
279 }
280 );
281
282 let PhysicalPosition { x, y } = monitor.position();
283 info!(" Position: {x},{y}");
284
285 info!(" Scale factor: {}", monitor.scale_factor());
286
287 info!(" Available modes (width x height x bit-depth):");
288 for mode in monitor.video_modes() {
289 let PhysicalSize { width, height } = mode.size();
290 let bits = mode.bit_depth();
291 let m_hz = mode.refresh_rate_millihertz();
292 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
293 }
294 }
295 }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?
256 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
257 info!("Monitors information");
258 let primary_monitor = event_loop.primary_monitor();
259 for monitor in event_loop.available_monitors() {
260 let intro = if primary_monitor.as_ref() == Some(&monitor) {
261 "Primary monitor"
262 } else {
263 "Monitor"
264 };
265
266 if let Some(name) = monitor.name() {
267 info!("{intro}: {name}");
268 } else {
269 info!("{intro}: [no name]");
270 }
271
272 let PhysicalSize { width, height } = monitor.size();
273 info!(
274 " Current mode: {width}x{height}{}",
275 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
276 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
277 } else {
278 String::new()
279 }
280 );
281
282 let PhysicalPosition { x, y } = monitor.position();
283 info!(" Position: {x},{y}");
284
285 info!(" Scale factor: {}", monitor.scale_factor());
286
287 info!(" Available modes (width x height x bit-depth):");
288 for mode in monitor.video_modes() {
289 let PhysicalSize { width, height } = mode.size();
290 let bits = mode.bit_depth();
291 let m_hz = mode.refresh_rate_millihertz();
292 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
293 }
294 }
295 }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?
256 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
257 info!("Monitors information");
258 let primary_monitor = event_loop.primary_monitor();
259 for monitor in event_loop.available_monitors() {
260 let intro = if primary_monitor.as_ref() == Some(&monitor) {
261 "Primary monitor"
262 } else {
263 "Monitor"
264 };
265
266 if let Some(name) = monitor.name() {
267 info!("{intro}: {name}");
268 } else {
269 info!("{intro}: [no name]");
270 }
271
272 let PhysicalSize { width, height } = monitor.size();
273 info!(
274 " Current mode: {width}x{height}{}",
275 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
276 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
277 } else {
278 String::new()
279 }
280 );
281
282 let PhysicalPosition { x, y } = monitor.position();
283 info!(" Position: {x},{y}");
284
285 info!(" Scale factor: {}", monitor.scale_factor());
286
287 info!(" Available modes (width x height x bit-depth):");
288 for mode in monitor.video_modes() {
289 let PhysicalSize { width, height } = mode.size();
290 let bits = mode.bit_depth();
291 let m_hz = mode.refresh_rate_millihertz();
292 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
293 }
294 }
295 }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?
256 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
257 info!("Monitors information");
258 let primary_monitor = event_loop.primary_monitor();
259 for monitor in event_loop.available_monitors() {
260 let intro = if primary_monitor.as_ref() == Some(&monitor) {
261 "Primary monitor"
262 } else {
263 "Monitor"
264 };
265
266 if let Some(name) = monitor.name() {
267 info!("{intro}: {name}");
268 } else {
269 info!("{intro}: [no name]");
270 }
271
272 let PhysicalSize { width, height } = monitor.size();
273 info!(
274 " Current mode: {width}x{height}{}",
275 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
276 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
277 } else {
278 String::new()
279 }
280 );
281
282 let PhysicalPosition { x, y } = monitor.position();
283 info!(" Position: {x},{y}");
284
285 info!(" Scale factor: {}", monitor.scale_factor());
286
287 info!(" Available modes (width x height x bit-depth):");
288 for mode in monitor.video_modes() {
289 let PhysicalSize { width, height } = mode.size();
290 let bits = mode.bit_depth();
291 let m_hz = mode.refresh_rate_millihertz();
292 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
293 }
294 }
295 }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?
256 fn dump_monitors(&self, event_loop: &ActiveEventLoop) {
257 info!("Monitors information");
258 let primary_monitor = event_loop.primary_monitor();
259 for monitor in event_loop.available_monitors() {
260 let intro = if primary_monitor.as_ref() == Some(&monitor) {
261 "Primary monitor"
262 } else {
263 "Monitor"
264 };
265
266 if let Some(name) = monitor.name() {
267 info!("{intro}: {name}");
268 } else {
269 info!("{intro}: [no name]");
270 }
271
272 let PhysicalSize { width, height } = monitor.size();
273 info!(
274 " Current mode: {width}x{height}{}",
275 if let Some(m_hz) = monitor.refresh_rate_millihertz() {
276 format!(" @ {}.{} Hz", m_hz / 1000, m_hz % 1000)
277 } else {
278 String::new()
279 }
280 );
281
282 let PhysicalPosition { x, y } = monitor.position();
283 info!(" Position: {x},{y}");
284
285 info!(" Scale factor: {}", monitor.scale_factor());
286
287 info!(" Available modes (width x height x bit-depth):");
288 for mode in monitor.video_modes() {
289 let PhysicalSize { width, height } = mode.size();
290 let bits = mode.bit_depth();
291 let m_hz = mode.refresh_rate_millihertz();
292 info!(" {width}x{height}x{bits} @ {}.{} Hz", m_hz / 1000, m_hz % 1000);
293 }
294 }
295 }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.