11use super :: { Display , Target } ;
2+ use windows:: Win32 :: Graphics :: Dwm :: { DwmGetWindowAttribute , DWMWA_EXTENDED_FRAME_BOUNDS } ;
23use windows:: Win32 :: UI :: HiDpi :: { GetDpiForMonitor , GetDpiForWindow , MDT_EFFECTIVE_DPI } ;
4+ use windows:: Win32 :: UI :: WindowsAndMessaging :: GetWindowRect ;
35use windows:: Win32 :: {
46 Foundation :: { HWND , RECT } ,
57 Graphics :: Gdi :: HMONITOR ,
@@ -84,10 +86,21 @@ pub fn get_target_dimensions(target: &Target) -> (u64, u64) {
8486 match target {
8587 Target :: Window ( window) => unsafe {
8688 let hwnd = window. raw_handle ;
87-
88- // get width and height of the window
8989 let mut rect = RECT :: default ( ) ;
90- let _ = windows:: Win32 :: UI :: WindowsAndMessaging :: GetWindowRect ( hwnd, & mut rect) ;
90+
91+ // Try DwmGetWindowAttribute first for accurate bounds without shadows
92+ let result = DwmGetWindowAttribute (
93+ hwnd,
94+ DWMWA_EXTENDED_FRAME_BOUNDS ,
95+ & mut rect as * mut RECT as * mut _ ,
96+ std:: mem:: size_of :: < RECT > ( ) as u32 ,
97+ ) ;
98+
99+ // Fall back to GetWindowRect if DwmGetWindowAttribute fails
100+ if result. is_err ( ) {
101+ let _ = GetWindowRect ( hwnd, & mut rect) ;
102+ }
103+
91104 let width = rect. right - rect. left ;
92105 let height = rect. bottom - rect. top ;
93106
@@ -97,8 +110,8 @@ pub fn get_target_dimensions(target: &Target) -> (u64, u64) {
97110 let monitor = Monitor :: from_raw_hmonitor ( display. raw_handle . 0 ) ;
98111
99112 (
100- monitor. width ( ) . unwrap ( ) as u64 ,
101- monitor. height ( ) . unwrap ( ) as u64 ,
113+ monitor. width ( ) . unwrap_or_default ( ) as u64 ,
114+ monitor. height ( ) . unwrap_or_default ( ) as u64 ,
102115 )
103116 }
104117 }
0 commit comments