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?
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 }
Sourcepub fn size(&self) -> PhysicalSize<u32>
pub fn size(&self) -> PhysicalSize<u32>
Returns the monitor’s resolution.
Examples found in repository?
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 }
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?
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 }
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?
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 }
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_FACTOR
environment variable. - Wayland: May differ from
Window::scale_factor
. - Android: Always returns 1.0.
Examples found in repository?
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 }
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?
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
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 more