display.rs

 1use anyhow::{anyhow, Result};
 2use uuid::Uuid;
 3use windows::{
 4    core::PCSTR,
 5    Win32::Graphics::Gdi::{EnumDisplaySettingsA, DEVMODEA, ENUM_CURRENT_SETTINGS},
 6};
 7
 8use crate::{Bounds, DisplayId, GlobalPixels, PlatformDisplay, Point, Size};
 9
10#[derive(Debug)]
11pub(crate) struct WindowsDisplay;
12
13impl WindowsDisplay {
14    pub(crate) fn new() -> Self {
15        Self
16    }
17}
18
19impl PlatformDisplay for WindowsDisplay {
20    // todo(windows)
21    fn id(&self) -> DisplayId {
22        DisplayId(1)
23    }
24
25    // todo(windows)
26    fn uuid(&self) -> Result<Uuid> {
27        Err(anyhow!("not implemented yet."))
28    }
29
30    fn bounds(&self) -> Bounds<GlobalPixels> {
31        let mut dev = DEVMODEA {
32            dmSize: std::mem::size_of::<DEVMODEA>() as _,
33            ..unsafe { std::mem::zeroed() }
34        };
35        unsafe { EnumDisplaySettingsA(PCSTR::null(), ENUM_CURRENT_SETTINGS, &mut dev) };
36        let w = dev.dmPelsWidth;
37        let h = dev.dmPelsHeight;
38
39        log::debug!("Screen size: {w} {h}");
40        Bounds::new(
41            Point::new(0.0.into(), 0.0.into()),
42            Size {
43                width: GlobalPixels(w as f32),
44                height: GlobalPixels(h as f32),
45            },
46        )
47    }
48}