11use std:: { ffi:: OsString , mem, os:: windows:: ffi:: OsStringExt , path:: PathBuf , str:: FromStr } ;
22use tracing:: error;
33use windows:: {
4+ core:: { BOOL , PCWSTR , PWSTR } ,
45 Graphics :: Capture :: GraphicsCaptureItem ,
56 Win32 :: {
67 Foundation :: { CloseHandle , HWND , LPARAM , POINT , RECT , TRUE , WPARAM } ,
78 Graphics :: {
8- Dwm :: { DWMWA_CLOAKED , DWMWA_EXTENDED_FRAME_BOUNDS , DwmGetWindowAttribute } ,
9+ Dwm :: { DwmGetWindowAttribute , DWMWA_CLOAKED , DWMWA_EXTENDED_FRAME_BOUNDS } ,
910 Gdi :: {
10- BI_RGB , BITMAP , BITMAPINFO , BITMAPINFOHEADER , CreateCompatibleBitmap ,
11- CreateCompatibleDC , CreateSolidBrush , DEVMODEW , DIB_RGB_COLORS ,
12- DISPLAY_DEVICE_STATE_FLAGS , DISPLAY_DEVICEW , DeleteDC , DeleteObject ,
13- ENUM_CURRENT_SETTINGS , EnumDisplayDevicesW , EnumDisplayMonitors ,
14- EnumDisplaySettingsW , FillRect , GetDC , GetDIBits , GetMonitorInfoW , GetObjectA ,
15- HBRUSH , HDC , HGDIOBJ , HMONITOR , MONITOR_DEFAULTTONEAREST , MONITOR_DEFAULTTONULL ,
16- MONITORINFOEXW , MonitorFromPoint , MonitorFromWindow , ReleaseDC , SelectObject ,
11+ CreateCompatibleBitmap , CreateCompatibleDC , CreateSolidBrush , DeleteDC ,
12+ DeleteObject , EnumDisplayDevicesW , EnumDisplayMonitors , EnumDisplaySettingsW ,
13+ FillRect , GetDC , GetDIBits , GetMonitorInfoW , GetObjectA , MonitorFromPoint ,
14+ MonitorFromWindow , ReleaseDC , SelectObject , BITMAP , BITMAPINFO , BITMAPINFOHEADER ,
15+ BI_RGB , DEVMODEW , DIB_RGB_COLORS , DISPLAY_DEVICEW , DISPLAY_DEVICE_STATE_FLAGS ,
16+ ENUM_CURRENT_SETTINGS , HBRUSH , HDC , HGDIOBJ , HMONITOR , MONITORINFOEXW ,
17+ MONITOR_DEFAULTTONEAREST , MONITOR_DEFAULTTONULL ,
1718 } ,
1819 } ,
1920 Storage :: FileSystem :: {
20- FILE_FLAGS_AND_ATTRIBUTES , GetFileVersionInfoSizeW , GetFileVersionInfoW , VerQueryValueW ,
21+ GetFileVersionInfoSizeW , GetFileVersionInfoW , VerQueryValueW , FILE_FLAGS_AND_ATTRIBUTES ,
2122 } ,
2223 System :: {
2324 Threading :: {
24- GetCurrentProcessId , OpenProcess , PROCESS_NAME_FORMAT ,
25- PROCESS_QUERY_LIMITED_INFORMATION , QueryFullProcessImageNameW ,
25+ GetCurrentProcessId , OpenProcess , QueryFullProcessImageNameW , PROCESS_NAME_FORMAT ,
26+ PROCESS_QUERY_LIMITED_INFORMATION ,
2627 } ,
2728 WinRT :: Graphics :: Capture :: IGraphicsCaptureItemInterop ,
2829 } ,
@@ -32,25 +33,26 @@ use windows::{
3233 PROCESS_PER_MONITOR_DPI_AWARE ,
3334 } ,
3435 Shell :: {
35- ExtractIconExW , SHFILEINFOW , SHGFI_ICON , SHGFI_LARGEICON , SHGFI_SMALLICON ,
36- SHGetFileInfoW ,
36+ ExtractIconExW , SHGetFileInfoW , SHFILEINFOW , SHGFI_ICON , SHGFI_LARGEICON ,
37+ SHGFI_SMALLICON ,
3738 } ,
3839 WindowsAndMessaging :: {
39- DI_FLAGS , DestroyIcon , DrawIconEx , EnumChildWindows , EnumWindows , GCLP_HICON ,
40- GW_HWNDNEXT , GWL_EXSTYLE , GWL_STYLE , GetClassLongPtrW , GetClassNameW ,
41- GetClientRect , GetCursorPos , GetDesktopWindow , GetIconInfo ,
40+ DestroyIcon , DrawIconEx , EnumChildWindows , EnumWindows , GetClassLongPtrW ,
41+ GetClassNameW , GetClientRect , GetCursorPos , GetDesktopWindow , GetIconInfo ,
4242 GetLayeredWindowAttributes , GetWindow , GetWindowLongPtrW , GetWindowLongW ,
4343 GetWindowRect , GetWindowTextLengthW , GetWindowTextW , GetWindowThreadProcessId ,
44- HICON , ICONINFO , IsIconic , IsWindowVisible , PrivateExtractIconsW , SendMessageW ,
44+ IsIconic , IsWindowVisible , PrivateExtractIconsW , SendMessageW , WindowFromPoint ,
45+ DI_FLAGS , GCLP_HICON , GWL_EXSTYLE , GWL_STYLE , GW_HWNDNEXT , HICON , ICONINFO ,
4546 WM_GETICON , WS_CHILD , WS_EX_LAYERED , WS_EX_TOOLWINDOW , WS_EX_TOPMOST ,
46- WS_EX_TRANSPARENT , WindowFromPoint ,
47+ WS_EX_TRANSPARENT ,
4748 } ,
4849 } ,
4950 } ,
50- core:: { BOOL , PCWSTR , PWSTR } ,
5151} ;
5252
53- use crate :: bounds:: { LogicalSize , PhysicalBounds , PhysicalPosition , PhysicalSize } ;
53+ use crate :: bounds:: {
54+ LogicalBounds , LogicalPosition , LogicalSize , PhysicalBounds , PhysicalPosition , PhysicalSize ,
55+ } ;
5456
5557// All of this assumes PROCESS_PER_MONITOR_DPI_AWARE
5658//
@@ -124,7 +126,7 @@ impl DisplayImpl {
124126 }
125127
126128 pub fn raw_id ( & self ) -> DisplayIdImpl {
127- DisplayIdImpl ( self . 0 . 0 as u64 )
129+ DisplayIdImpl ( self . 0 . 0 as u64 )
128130 }
129131
130132 pub fn from_id ( id : String ) -> Option < Self > {
@@ -149,6 +151,29 @@ impl DisplayImpl {
149151 ) )
150152 }
151153
154+ pub fn logical_bounds ( & self ) -> Option < LogicalBounds > {
155+ let physical_bounds = self . physical_bounds ( ) ?;
156+
157+ let dpi = unsafe {
158+ let mut dpi_x = 0 ;
159+ GetDpiForMonitor ( self . 0 , MDT_EFFECTIVE_DPI , & mut dpi_x, & mut 0 ) . ok ( ) ?;
160+ dpi_x
161+ } ;
162+
163+ let scale = dpi as f64 / 96.0 ;
164+
165+ Some ( LogicalBounds :: new (
166+ LogicalPosition :: new (
167+ physical_bounds. position ( ) . x ( ) / scale,
168+ physical_bounds. position ( ) . y ( ) / scale,
169+ ) ,
170+ LogicalSize :: new (
171+ physical_bounds. size ( ) . width ( ) / scale,
172+ physical_bounds. size ( ) . height ( ) / scale,
173+ ) ,
174+ ) )
175+ }
176+
152177 pub fn get_containing_cursor ( ) -> Option < Self > {
153178 let cursor = get_cursor_position ( ) ?;
154179 let point = POINT {
@@ -424,7 +449,7 @@ impl WindowImpl {
424449 }
425450
426451 pub fn id ( & self ) -> WindowIdImpl {
427- WindowIdImpl ( self . 0 . 0 as u64 )
452+ WindowIdImpl ( self . 0 . 0 as u64 )
428453 }
429454
430455 pub fn level ( & self ) -> Option < i32 > {
0 commit comments