@@ -9,13 +9,12 @@ use dpi::{PhysicalSize, Size};
99use raw_window_handle:: { DisplayHandle , Win32WindowHandle } ;
1010use std:: cell:: { Cell , OnceCell , Ref , RefCell } ;
1111use std:: num:: NonZeroIsize ;
12- use windows_sys:: Win32 :: Foundation :: HWND ;
1312use windows_sys:: Win32 :: UI :: WindowsAndMessaging :: PostMessageW ;
1413
1514/// All data associated with the window.
1615pub ( crate ) struct WindowState {
1716 /// The HWND belonging to this window.
18- pub hwnd : HWND ,
17+ pub hwnd : HWnd ,
1918 pub current_size : Cell < PhysicalSize < u32 > > ,
2019 pub current_dpi : Cell < Dpi > , // None if in non-system scale policy
2120 pub keyboard_state : RefCell < KeyboardState > ,
@@ -34,7 +33,7 @@ pub(crate) struct WindowState {
3433
3534impl WindowState {
3635 pub fn new (
37- hwnd : HWND , current_size : PhysicalSize < u32 > , scale_policy : WindowScalePolicy ,
36+ hwnd : HWnd , current_size : PhysicalSize < u32 > , scale_policy : WindowScalePolicy ,
3837 user32 : ExtendedUser32 ,
3938 ) -> Self {
4039 Self {
@@ -92,21 +91,21 @@ impl WindowState {
9291
9392 pub fn request_close ( & self ) {
9493 unsafe {
95- PostMessageW ( self . hwnd , crate :: platform:: win:: window:: BV_WINDOW_MUST_CLOSE , 0 , 0 ) ;
94+ PostMessageW (
95+ self . hwnd . as_raw ( ) ,
96+ crate :: platform:: win:: window:: BV_WINDOW_MUST_CLOSE ,
97+ 0 ,
98+ 0 ,
99+ ) ;
96100 }
97101 }
98102
99103 pub fn has_focus ( & self ) -> bool {
100- HWnd :: get_focused_window ( ) == self . hwnd
104+ HWnd :: get_focused_window ( ) == self . hwnd . as_raw ( )
101105 }
102106
103107 pub fn focus ( & self ) {
104- self . hwnd ( ) . set_focus ( ) . unwrap ( )
105- }
106-
107- fn hwnd ( & self ) -> HWnd {
108- // SAFETY: this handle should be safe to use
109- unsafe { HWnd :: from_raw ( self . hwnd ) }
108+ self . hwnd . set_focus ( ) . unwrap ( )
110109 }
111110
112111 pub fn resize ( & self , size : Size ) {
@@ -115,7 +114,7 @@ impl WindowState {
115114 let dpi = self . current_dpi . get ( ) ;
116115 let new_size = size. to_physical ( dpi. scale_factor ( ) ) ;
117116
118- self . hwnd ( ) . resize_and_activate ( new_size, dpi, & self . user32 ) . unwrap ( ) ;
117+ self . hwnd . resize_and_activate ( new_size, dpi, & self . user32 ) . unwrap ( ) ;
119118 }
120119
121120 pub fn set_mouse_cursor ( & self , mouse_cursor : MouseCursor ) {
@@ -132,7 +131,7 @@ impl WindowState {
132131 }
133132
134133 pub fn window_handle ( & self ) -> Option < raw_window_handle:: WindowHandle < ' _ > > {
135- let Some ( hwnd) = NonZeroIsize :: new ( self . hwnd as _ ) else { unreachable ! ( ) } ;
134+ let Some ( hwnd) = NonZeroIsize :: new ( self . hwnd . as_raw ( ) as _ ) else { unreachable ! ( ) } ;
136135 let mut handle = Win32WindowHandle :: new ( hwnd) ;
137136 handle. hinstance = Some ( HInstance :: get_from_dll ( ) . addr ( ) ) ;
138137
@@ -144,7 +143,7 @@ impl WindowState {
144143 }
145144
146145 pub fn platform_handle ( & self ) -> PlatformHandle {
147- let Some ( hwnd) = NonZeroIsize :: new ( self . hwnd as _ ) else { unreachable ! ( ) } ;
146+ let Some ( hwnd) = NonZeroIsize :: new ( self . hwnd . as_raw ( ) as _ ) else { unreachable ! ( ) } ;
148147 PlatformHandle { hwnd }
149148 }
150149}
0 commit comments