@@ -5,10 +5,11 @@ use std::{io, iter, mem, ptr};
55
66use windows_sys:: Win32 :: Foundation :: { BOOL , HWND , LPARAM , POINT , RECT } ;
77use windows_sys:: Win32 :: Graphics :: Gdi :: {
8- EnumDisplayMonitors , EnumDisplaySettingsExW , GetMonitorInfoW , MonitorFromPoint ,
9- MonitorFromWindow , DEVMODEW , DM_BITSPERPEL , DM_DISPLAYFREQUENCY , DM_PELSHEIGHT , DM_PELSWIDTH ,
10- ENUM_CURRENT_SETTINGS , HDC , HMONITOR , MONITORINFO , MONITORINFOEXW , MONITOR_DEFAULTTONEAREST ,
11- MONITOR_DEFAULTTOPRIMARY ,
8+ CreateDCW , DeleteDC , EnumDisplayMonitors , EnumDisplaySettingsExW , GetDeviceCaps ,
9+ GetMonitorInfoW , MonitorFromPoint , MonitorFromWindow , DEVMODEW , DM_BITSPERPEL ,
10+ DM_DISPLAYFREQUENCY , DM_PELSHEIGHT , DM_PELSWIDTH , ENUM_CURRENT_SETTINGS , HDC , HMONITOR ,
11+ HORZSIZE , MONITORINFO , MONITORINFOEXW , MONITOR_DEFAULTTONEAREST , MONITOR_DEFAULTTOPRIMARY ,
12+ VERTSIZE ,
1213} ;
1314
1415use super :: util:: decode_wide;
@@ -185,6 +186,32 @@ impl MonitorHandleProvider for MonitorHandle {
185186 . ok ( )
186187 }
187188
189+ fn physical_size ( & self ) -> Option < PhysicalSize < u32 > > {
190+ let monitor_info_ex_w = get_monitor_info ( self . 0 ) . ok ( ) ?;
191+
192+ let hdc = unsafe {
193+ CreateDCW (
194+ monitor_info_ex_w. szDevice . as_ptr ( ) ,
195+ monitor_info_ex_w. szDevice . as_ptr ( ) ,
196+ std:: ptr:: null ( ) ,
197+ std:: ptr:: null ( ) ,
198+ )
199+ } ;
200+
201+ let width: u32 =
202+ unsafe { GetDeviceCaps ( hdc, HORZSIZE . try_into ( ) . ok ( ) ?) } . try_into ( ) . ok ( ) ?;
203+ let height: u32 =
204+ unsafe { GetDeviceCaps ( hdc, VERTSIZE . try_into ( ) . ok ( ) ?) } . try_into ( ) . ok ( ) ?;
205+
206+ unsafe {
207+ if DeleteDC ( hdc) == 0 {
208+ tracing:: error!( "DeleteDC {:?} failed" , hdc)
209+ }
210+ }
211+
212+ ( width > 0 && height > 0 ) . then_some ( PhysicalSize { width, height } )
213+ }
214+
188215 fn scale_factor ( & self ) -> f64 {
189216 dpi_to_scale_factor ( get_monitor_dpi ( self . 0 ) . unwrap_or ( 96 ) )
190217 }
0 commit comments