@@ -533,6 +533,19 @@ impl TryFrom<Icon> for WryIcon {
533533
534534struct WindowEventWrapper ( Option < WindowEvent > ) ;
535535
536+ impl WindowEventWrapper {
537+ fn parse ( webview : & WindowHandle , event : & WryWindowEvent ) -> Self {
538+ match event {
539+ // resized event from tao doesn't include a reliable size on macOS
540+ // because wry replaces the NSView
541+ WryWindowEvent :: Resized ( _) => Self ( Some ( WindowEvent :: Resized (
542+ PhysicalSizeWrapper ( webview. inner_size ( ) ) . into ( ) ,
543+ ) ) ) ,
544+ e => e. into ( ) ,
545+ }
546+ }
547+ }
548+
536549impl < ' a > From < & WryWindowEvent < ' a > > for WindowEventWrapper {
537550 fn from ( event : & WryWindowEvent < ' a > ) -> Self {
538551 let event = match event {
@@ -1424,6 +1437,13 @@ impl WindowHandle {
14241437 Self :: Window ( w) => w,
14251438 }
14261439 }
1440+
1441+ fn inner_size ( & self ) -> WryPhysicalSize < u32 > {
1442+ match self {
1443+ WindowHandle :: Window ( w) => w. inner_size ( ) ,
1444+ WindowHandle :: Webview ( w) => w. inner_size ( ) ,
1445+ }
1446+ }
14271447}
14281448
14291449#[ derive( Debug ) ]
@@ -1899,7 +1919,7 @@ fn handle_user_message(
18991919 )
19001920 . unwrap ( ) ,
19011921 WindowMessage :: InnerSize ( tx) => tx
1902- . send ( PhysicalSizeWrapper ( window . inner_size ( ) ) . into ( ) )
1922+ . send ( PhysicalSizeWrapper ( webview . inner . inner_size ( ) ) . into ( ) )
19031923 . unwrap ( ) ,
19041924 WindowMessage :: OuterSize ( tx) => tx
19051925 . send ( PhysicalSizeWrapper ( window. outer_size ( ) ) . into ( ) )
@@ -1929,7 +1949,8 @@ fn handle_user_message(
19291949 WindowMessage :: GtkWindow ( tx) => tx. send ( GtkWindow ( window. gtk_window ( ) . clone ( ) ) ) . unwrap ( ) ,
19301950 // Setters
19311951 WindowMessage :: Center ( tx) => {
1932- tx. send ( center_window ( window) ) . unwrap ( ) ;
1952+ tx. send ( center_window ( window, webview. inner . inner_size ( ) ) )
1953+ . unwrap ( ) ;
19331954 }
19341955 WindowMessage :: RequestUserAttention ( request_type) => {
19351956 window. request_user_attention ( request_type. map ( |r| r. 0 ) ) ;
@@ -2272,19 +2293,26 @@ fn handle_event_loop(
22722293 }
22732294 }
22742295
2275- if let Some ( event) = WindowEventWrapper :: from ( & event) . 0 {
2276- for handler in window_event_listeners
2277- . lock ( )
2278- . unwrap ( )
2279- . get ( & window_id)
2280- . unwrap ( )
2281- . lock ( )
2282- . unwrap ( )
2283- . values ( )
2284- {
2285- handler ( & event) ;
2296+ {
2297+ let windows_lock = windows. lock ( ) . expect ( "poisoned webview collection" ) ;
2298+ if let Some ( window_handle) = windows_lock. get ( & window_id) . map ( |w| & w. inner ) {
2299+ if let Some ( event) = WindowEventWrapper :: parse ( window_handle, & event) . 0 {
2300+ drop ( windows_lock) ;
2301+ for handler in window_event_listeners
2302+ . lock ( )
2303+ . unwrap ( )
2304+ . get ( & window_id)
2305+ . unwrap ( )
2306+ . lock ( )
2307+ . unwrap ( )
2308+ . values ( )
2309+ {
2310+ handler ( & event) ;
2311+ }
2312+ }
22862313 }
22872314 }
2315+
22882316 match event {
22892317 WryWindowEvent :: CloseRequested => {
22902318 let ( tx, rx) = channel ( ) ;
@@ -2409,10 +2437,9 @@ fn on_window_close<'a>(
24092437 }
24102438}
24112439
2412- fn center_window ( window : & Window ) -> Result < ( ) > {
2440+ fn center_window ( window : & Window , window_size : WryPhysicalSize < u32 > ) -> Result < ( ) > {
24132441 if let Some ( monitor) = window. current_monitor ( ) {
24142442 let screen_size = monitor. size ( ) ;
2415- let window_size = window. inner_size ( ) ;
24162443 let x = ( screen_size. width - window_size. width ) / 2 ;
24172444 let y = ( screen_size. height - window_size. height ) / 2 ;
24182445 window. set_outer_position ( WryPhysicalPosition :: new ( x, y) ) ;
@@ -2527,7 +2554,7 @@ fn create_webview(
25272554 . insert ( window. id ( ) , WindowMenuEventListeners :: default ( ) ) ;
25282555
25292556 if window_builder. center {
2530- let _ = center_window ( & window) ;
2557+ let _ = center_window ( & window, window . inner_size ( ) ) ;
25312558 }
25322559 let mut webview_builder = WebViewBuilder :: new ( window)
25332560 . map_err ( |e| Error :: CreateWebview ( Box :: new ( e) ) ) ?
0 commit comments