use windows_sys::Win32::Graphics::Gdi::{
CreateDCW, DeleteDC, GetDeviceCaps, HORZRES, HORZSIZE, VERTRES, VERTSIZE,
};
#[allow(
clippy::cast_possible_wrap,
reason = "GDI capability indices are fixed constants that fit in i32"
)]
pub(super) fn physical_size_mm() -> Option<(u32, u32)> {
let bounds = crate::input::windows::virtual_bounds().ok()?;
let driver: Vec<u16> = "DISPLAY\0".encode_utf16().collect();
let dc = unsafe {
CreateDCW(
driver.as_ptr(),
std::ptr::null(),
std::ptr::null(),
std::ptr::null(),
)
};
if dc.is_null() {
return None;
}
let (mm, pixels) = unsafe {
(
(
f64::from(GetDeviceCaps(dc, HORZSIZE as i32)),
f64::from(GetDeviceCaps(dc, VERTSIZE as i32)),
),
(
f64::from(GetDeviceCaps(dc, HORZRES as i32)),
f64::from(GetDeviceCaps(dc, VERTRES as i32)),
),
)
};
unsafe { DeleteDC(dc) };
super::scale_desktop_mm(
mm,
pixels,
(f64::from(bounds.width), f64::from(bounds.height)),
)
}