Skip to main content

optic_window/
screen.rs

1use optic_core::{Coord2D, Size2D};
2
3/// Information about a connected monitor/screen.
4#[derive(Debug, Clone)]
5pub struct ScreenInfo {
6    pub name: String,
7    pub size: Size2D,
8    pub refresh_rate: u32,
9    pub scale_factor: f64,
10    pub position: Coord2D,
11}
12
13impl ScreenInfo {
14    /// Construct from a winit [`MonitorHandle`](winit::monitor::MonitorHandle).
15    pub fn from_handle(handle: &winit::monitor::MonitorHandle) -> Self {
16        let sz = handle.size();
17        let pos = handle.position();
18        Self {
19            name: handle.name().unwrap_or_default(),
20            size: Size2D::from(sz.width, sz.height),
21            refresh_rate: handle.refresh_rate_millihertz().unwrap_or(0) / 1000,
22            scale_factor: handle.scale_factor(),
23            position: Coord2D::from(pos.x as f64, pos.y as f64),
24        }
25    }
26}