@@ -16,7 +16,7 @@ use crate::{
1616 runtime:: {
1717 http:: { Request as HttpRequest , Response as HttpResponse } ,
1818 webview:: { WebviewAttributes , WindowBuilder as _} ,
19- window:: { PendingWindow , WindowEvent } ,
19+ window:: { PendingWindow , WindowEvent as RuntimeWindowEvent } ,
2020 Dispatch , ExitRequestedEventAction , RunEvent as RuntimeRunEvent ,
2121 } ,
2222 scope:: FsScope ,
@@ -32,6 +32,10 @@ use crate::{
3232use crate :: scope:: ShellScope ;
3333
3434use tauri_macros:: default_runtime;
35+ use tauri_runtime:: window:: {
36+ dpi:: { PhysicalPosition , PhysicalSize } ,
37+ FileDropEvent ,
38+ } ;
3539use tauri_utils:: PackageInfo ;
3640
3741use std:: {
@@ -69,7 +73,7 @@ impl ExitRequestApi {
6973}
7074
7175/// Api exposed on the `CloseRequested` event.
72- #[ derive( Debug ) ]
76+ #[ derive( Debug , Clone ) ]
7377pub struct CloseRequestApi ( Sender < bool > ) ;
7478
7579impl CloseRequestApi {
@@ -79,6 +83,66 @@ impl CloseRequestApi {
7983 }
8084}
8185
86+ /// An event from a window.
87+ #[ derive( Debug , Clone ) ]
88+ #[ non_exhaustive]
89+ pub enum WindowEvent {
90+ /// The size of the window has changed. Contains the client area's new dimensions.
91+ Resized ( PhysicalSize < u32 > ) ,
92+ /// The position of the window has changed. Contains the window's new position.
93+ Moved ( PhysicalPosition < i32 > ) ,
94+ /// The window has been requested to close.
95+ #[ non_exhaustive]
96+ CloseRequested {
97+ /// An API modify the behavior of the close requested event.
98+ api : CloseRequestApi ,
99+ } ,
100+ /// The window has been destroyed.
101+ Destroyed ,
102+ /// The window gained or lost focus.
103+ ///
104+ /// The parameter is true if the window has gained focus, and false if it has lost focus.
105+ Focused ( bool ) ,
106+ /// The window's scale factor has changed.
107+ ///
108+ /// The following user actions can cause DPI changes:
109+ ///
110+ /// - Changing the display's resolution.
111+ /// - Changing the display's scale factor (e.g. in Control Panel on Windows).
112+ /// - Moving the window to a display with a different scale factor.
113+ #[ non_exhaustive]
114+ ScaleFactorChanged {
115+ /// The new scale factor.
116+ scale_factor : f64 ,
117+ /// The window inner size.
118+ new_inner_size : PhysicalSize < u32 > ,
119+ } ,
120+ /// An event associated with the file drop action.
121+ FileDrop ( FileDropEvent ) ,
122+ }
123+
124+ impl From < RuntimeWindowEvent > for WindowEvent {
125+ fn from ( event : RuntimeWindowEvent ) -> Self {
126+ match event {
127+ RuntimeWindowEvent :: Resized ( size) => Self :: Resized ( size) ,
128+ RuntimeWindowEvent :: Moved ( position) => Self :: Moved ( position) ,
129+ RuntimeWindowEvent :: CloseRequested { signal_tx } => Self :: CloseRequested {
130+ api : CloseRequestApi ( signal_tx) ,
131+ } ,
132+ RuntimeWindowEvent :: Destroyed => Self :: Destroyed ,
133+ RuntimeWindowEvent :: Focused ( flag) => Self :: Focused ( flag) ,
134+ RuntimeWindowEvent :: ScaleFactorChanged {
135+ scale_factor,
136+ new_inner_size,
137+ } => Self :: ScaleFactorChanged {
138+ scale_factor,
139+ new_inner_size,
140+ } ,
141+ RuntimeWindowEvent :: FileDrop ( event) => Self :: FileDrop ( event) ,
142+ }
143+ }
144+ }
145+
82146/// An application event, triggered from the event loop.
83147#[ derive( Debug ) ]
84148#[ non_exhaustive]
@@ -91,16 +155,14 @@ pub enum RunEvent {
91155 /// Event API
92156 api : ExitRequestApi ,
93157 } ,
94- /// Window close was requested by the user .
158+ /// An event associated with a window .
95159 #[ non_exhaustive]
96- CloseRequested {
160+ WindowEvent {
97161 /// The window label.
98162 label : String ,
99- /// Event API .
100- api : CloseRequestApi ,
163+ /// The detailed event .
164+ event : WindowEvent ,
101165 } ,
102- /// Window closed.
103- WindowClosed ( String ) ,
104166 /// Application ready.
105167 Ready ,
106168 /// Sent if the event loop is being resumed.
@@ -1428,7 +1490,11 @@ fn on_event_loop_event<R: Runtime, F: FnMut(&AppHandle<R>, RunEvent) + 'static>(
14281490 manager : & WindowManager < R > ,
14291491 callback : Option < & mut F > ,
14301492) {
1431- if let RuntimeRunEvent :: WindowClose ( label) = & event {
1493+ if let RuntimeRunEvent :: WindowEvent {
1494+ label,
1495+ event : RuntimeWindowEvent :: Destroyed ,
1496+ } = & event
1497+ {
14321498 manager. on_window_close ( label) ;
14331499 }
14341500
@@ -1437,11 +1503,10 @@ fn on_event_loop_event<R: Runtime, F: FnMut(&AppHandle<R>, RunEvent) + 'static>(
14371503 RuntimeRunEvent :: ExitRequested { tx } => RunEvent :: ExitRequested {
14381504 api : ExitRequestApi ( tx) ,
14391505 } ,
1440- RuntimeRunEvent :: CloseRequested { label, signal_tx } => RunEvent :: CloseRequested {
1506+ RuntimeRunEvent :: WindowEvent { label, event } => RunEvent :: WindowEvent {
14411507 label,
1442- api : CloseRequestApi ( signal_tx ) ,
1508+ event : event . into ( ) ,
14431509 } ,
1444- RuntimeRunEvent :: WindowClose ( label) => RunEvent :: WindowClosed ( label) ,
14451510 RuntimeRunEvent :: Ready => RunEvent :: Ready ,
14461511 RuntimeRunEvent :: Resumed => RunEvent :: Resumed ,
14471512 RuntimeRunEvent :: MainEventsCleared => RunEvent :: MainEventsCleared ,
0 commit comments