@@ -127,9 +127,11 @@ type IpcHandler = dyn Fn(Request<String>) + 'static;
127127 target_os = "openbsd"
128128) ) ]
129129mod undecorated_resizing;
130-
131130mod webview;
131+ mod window;
132+
132133pub use webview:: Webview ;
134+ use window:: WindowExt as _;
133135
134136#[ derive( Debug ) ]
135137pub struct WebContext {
@@ -1166,9 +1168,11 @@ pub enum WindowMessage {
11661168 GtkBox ( Sender < GtkBox > ) ,
11671169 RawWindowHandle ( Sender < std:: result:: Result < SendRawWindowHandle , raw_window_handle:: HandleError > > ) ,
11681170 Theme ( Sender < Theme > ) ,
1171+ IsEnabled ( Sender < bool > ) ,
11691172 // Setters
11701173 Center ,
11711174 RequestUserAttention ( Option < UserAttentionTypeWrapper > ) ,
1175+ SetEnabled ( bool ) ,
11721176 SetResizable ( bool ) ,
11731177 SetMaximizable ( bool ) ,
11741178 SetMinimizable ( bool ) ,
@@ -1700,6 +1704,10 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
17001704 window_getter ! ( self , WindowMessage :: Theme )
17011705 }
17021706
1707+ fn is_enabled ( & self ) -> Result < bool > {
1708+ window_getter ! ( self , WindowMessage :: IsEnabled )
1709+ }
1710+
17031711 #[ cfg( any(
17041712 target_os = "linux" ,
17051713 target_os = "dragonfly" ,
@@ -1775,6 +1783,13 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
17751783 )
17761784 }
17771785
1786+ fn set_enabled ( & self , enabled : bool ) -> Result < ( ) > {
1787+ send_user_message (
1788+ & self . context ,
1789+ Message :: Window ( self . window_id , WindowMessage :: SetEnabled ( enabled) ) ,
1790+ )
1791+ }
1792+
17781793 fn set_maximizable ( & self , maximizable : bool ) -> Result < ( ) > {
17791794 send_user_message (
17801795 & self . context ,
@@ -2865,40 +2880,10 @@ fn handle_user_message<T: UserEvent>(
28652880 WindowMessage :: Theme ( tx) => {
28662881 tx. send ( map_theme ( & window. theme ( ) ) ) . unwrap ( ) ;
28672882 }
2868- // Setters
2869- WindowMessage :: Center => {
2870- #[ cfg( not( target_os = "macos" ) ) ]
2871- if let Some ( monitor) = window. current_monitor ( ) {
2872- #[ allow( unused_mut) ]
2873- let mut window_size = window. outer_size ( ) ;
2874- #[ cfg( windows) ]
2875- if window. is_decorated ( ) {
2876- use windows:: Win32 :: Foundation :: RECT ;
2877- use windows:: Win32 :: Graphics :: Dwm :: {
2878- DwmGetWindowAttribute , DWMWA_EXTENDED_FRAME_BOUNDS ,
2879- } ;
2880- let mut rect = RECT :: default ( ) ;
2881- let result = unsafe {
2882- DwmGetWindowAttribute (
2883- HWND ( window. hwnd ( ) as _ ) ,
2884- DWMWA_EXTENDED_FRAME_BOUNDS ,
2885- & mut rect as * mut _ as * mut _ ,
2886- std:: mem:: size_of :: < RECT > ( ) as u32 ,
2887- )
2888- } ;
2889- if result. is_ok ( ) {
2890- window_size. height = ( rect. bottom - rect. top ) as u32 ;
2891- }
2892- }
2893- window. set_outer_position ( calculate_window_center_position ( window_size, monitor) ) ;
2894- }
2883+ WindowMessage :: IsEnabled ( tx) => tx. send ( window. is_enabled ( ) ) . unwrap ( ) ,
28952884
2896- #[ cfg( target_os = "macos" ) ]
2897- {
2898- let ns_window: & objc2_app_kit:: NSWindow = unsafe { & * window. ns_window ( ) . cast ( ) } ;
2899- ns_window. center ( ) ;
2900- }
2901- }
2885+ // Setters
2886+ WindowMessage :: Center => window. center ( ) ,
29022887 WindowMessage :: RequestUserAttention ( request_type) => {
29032888 window. request_user_attention ( request_type. map ( |r| r. 0 ) ) ;
29042889 }
@@ -2919,6 +2904,7 @@ fn handle_user_message<T: UserEvent>(
29192904 WindowMessage :: Unmaximize => window. set_maximized ( false ) ,
29202905 WindowMessage :: Minimize => window. set_minimized ( true ) ,
29212906 WindowMessage :: Unminimize => window. set_minimized ( false ) ,
2907+ WindowMessage :: SetEnabled ( enabled) => window. set_enabled ( enabled) ,
29222908 WindowMessage :: Show => window. set_visible ( true ) ,
29232909 WindowMessage :: Hide => window. set_visible ( false ) ,
29242910 WindowMessage :: Close => {
@@ -3421,7 +3407,7 @@ fn handle_user_message<T: UserEvent>(
34213407 let surface = if is_window_transparent {
34223408 if let Ok ( context) = softbuffer:: Context :: new ( window. clone ( ) ) {
34233409 if let Ok ( mut surface) = softbuffer:: Surface :: new ( & context, window. clone ( ) ) {
3424- clear_window_surface ( & window, & mut surface) ;
3410+ window. clear_surface ( & mut surface) ;
34253411 Some ( surface)
34263412 } else {
34273413 None
@@ -3499,7 +3485,7 @@ fn handle_event_loop<T: UserEvent>(
34993485 if window. is_window_transparent {
35003486 if let Some ( surface) = & mut window. surface {
35013487 if let Some ( window) = & window. inner {
3502- clear_window_surface ( window, surface)
3488+ window. clear_surface ( surface) ;
35033489 }
35043490 }
35053491 }
@@ -3842,7 +3828,7 @@ fn create_window<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
38423828 }
38433829 }
38443830 }
3845- let position = calculate_window_center_position ( window_size, monitor) ;
3831+ let position = window :: calculate_window_center_position ( window_size, monitor) ;
38463832 let logical_position = position. to_logical :: < f64 > ( scale_factor) ;
38473833 window_builder = window_builder. position ( logical_position. x , logical_position. y ) ;
38483834 }
@@ -3914,7 +3900,7 @@ fn create_window<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
39143900 let surface = if is_window_transparent {
39153901 if let Ok ( context) = softbuffer:: Context :: new ( window. clone ( ) ) {
39163902 if let Ok ( mut surface) = softbuffer:: Surface :: new ( & context, window. clone ( ) ) {
3917- clear_window_surface ( & window, & mut surface) ;
3903+ window. clear_surface ( & mut surface) ;
39183904 Some ( surface)
39193905 } else {
39203906 None
@@ -4398,49 +4384,3 @@ fn inner_size(
43984384) -> TaoPhysicalSize < u32 > {
43994385 window. inner_size ( )
44004386}
4401-
4402- fn calculate_window_center_position (
4403- window_size : TaoPhysicalSize < u32 > ,
4404- target_monitor : MonitorHandle ,
4405- ) -> TaoPhysicalPosition < i32 > {
4406- #[ cfg( windows) ]
4407- {
4408- use tao:: platform:: windows:: MonitorHandleExtWindows ;
4409- use windows:: Win32 :: Graphics :: Gdi :: { GetMonitorInfoW , HMONITOR , MONITORINFO } ;
4410- let mut monitor_info = MONITORINFO {
4411- cbSize : std:: mem:: size_of :: < MONITORINFO > ( ) as u32 ,
4412- ..Default :: default ( )
4413- } ;
4414- let status =
4415- unsafe { GetMonitorInfoW ( HMONITOR ( target_monitor. hmonitor ( ) as _ ) , & mut monitor_info) } ;
4416- if status. into ( ) {
4417- let available_width = monitor_info. rcWork . right - monitor_info. rcWork . left ;
4418- let available_height = monitor_info. rcWork . bottom - monitor_info. rcWork . top ;
4419- let x = ( available_width - window_size. width as i32 ) / 2 + monitor_info. rcWork . left ;
4420- let y = ( available_height - window_size. height as i32 ) / 2 + monitor_info. rcWork . top ;
4421- return TaoPhysicalPosition :: new ( x, y) ;
4422- }
4423- }
4424- let screen_size = target_monitor. size ( ) ;
4425- let monitor_pos = target_monitor. position ( ) ;
4426- let x = ( screen_size. width as i32 - window_size. width as i32 ) / 2 + monitor_pos. x ;
4427- let y = ( screen_size. height as i32 - window_size. height as i32 ) / 2 + monitor_pos. y ;
4428- TaoPhysicalPosition :: new ( x, y)
4429- }
4430-
4431- #[ cfg( windows) ]
4432- fn clear_window_surface (
4433- window : & Window ,
4434- surface : & mut softbuffer:: Surface < Arc < Window > , Arc < Window > > ,
4435- ) {
4436- let size = window. inner_size ( ) ;
4437- if let ( Some ( width) , Some ( height) ) = (
4438- std:: num:: NonZeroU32 :: new ( size. width ) ,
4439- std:: num:: NonZeroU32 :: new ( size. height ) ,
4440- ) {
4441- surface. resize ( width, height) . unwrap ( ) ;
4442- let mut buffer = surface. buffer_mut ( ) . unwrap ( ) ;
4443- buffer. fill ( 0 ) ;
4444- let _ = buffer. present ( ) ;
4445- }
4446- }
0 commit comments