File tree Expand file tree Collapse file tree 7 files changed +58
-10
lines changed
Expand file tree Collapse file tree 7 files changed +58
-10
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " api " : patch
3+ ---
4+
5+ Adds ` setFocus ` to the window API.
Original file line number Diff line number Diff line change 1+ ---
2+ " tauri " : patch
3+ " tauri-runtime " : patch
4+ " tauri-runtime-wry " : patch
5+ ---
6+
7+ Adds ` set_focus ` API on Window.
Original file line number Diff line number Diff line change @@ -423,6 +423,7 @@ enum WindowMessage {
423423 SetMaxSize ( Option < Size > ) ,
424424 SetPosition ( Position ) ,
425425 SetFullscreen ( bool ) ,
426+ SetFocus ,
426427 SetIcon ( WindowIcon ) ,
427428 DragWindow ,
428429}
@@ -763,6 +764,14 @@ impl Dispatch for WryDispatcher {
763764 . map_err ( |_| Error :: FailedToSendMessage )
764765 }
765766
767+ fn set_focus ( & self ) -> Result < ( ) > {
768+ self
769+ . context
770+ . proxy
771+ . send_event ( Message :: Window ( self . window_id , WindowMessage :: SetFocus ) )
772+ . map_err ( |_| Error :: FailedToSendMessage )
773+ }
774+
766775 fn set_icon ( & self , icon : Icon ) -> Result < ( ) > {
767776 self
768777 . context
@@ -1193,6 +1202,9 @@ fn handle_event_loop(
11931202 window. set_fullscreen ( None )
11941203 }
11951204 }
1205+ WindowMessage :: SetFocus => {
1206+ window. set_focus ( ) ;
1207+ }
11961208 WindowMessage :: SetIcon ( icon) => {
11971209 window. set_window_icon ( Some ( icon) ) ;
11981210 }
Original file line number Diff line number Diff line change @@ -289,6 +289,9 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
289289 /// Updates the window fullscreen state.
290290 fn set_fullscreen ( & self , fullscreen : bool ) -> crate :: Result < ( ) > ;
291291
292+ /// Bring the window to front and focus.
293+ fn set_focus ( & self ) -> crate :: Result < ( ) > ;
294+
292295 /// Updates the window icon.
293296 fn set_icon ( & self , icon : Icon ) -> crate :: Result < ( ) > ;
294297
Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ pub enum Cmd {
6969 SetMaxSize ( Option < Size > ) ,
7070 SetPosition ( Position ) ,
7171 SetFullscreen ( bool ) ,
72+ SetFocus ,
7273 SetIcon {
7374 icon : IconDto ,
7475 } ,
@@ -153,6 +154,7 @@ impl Cmd {
153154 Self :: SetMaxSize ( size) => window. set_max_size ( size) ?,
154155 Self :: SetPosition ( position) => window. set_position ( position) ?,
155156 Self :: SetFullscreen ( fullscreen) => window. set_fullscreen ( fullscreen) ?,
157+ Self :: SetFocus => window. set_focus ( ) ?,
156158 Self :: SetIcon { icon } => window. set_icon ( icon. into ( ) ) ?,
157159 Self :: StartDragging => window. start_dragging ( ) ?,
158160 Self :: Print => window. print ( ) ?,
Original file line number Diff line number Diff line change @@ -528,6 +528,11 @@ impl<P: Params> Window<P> {
528528 . map_err ( Into :: into)
529529 }
530530
531+ /// Bring the window to front and focus.
532+ pub fn set_focus ( & self ) -> crate :: Result < ( ) > {
533+ self . window . dispatcher . set_focus ( ) . map_err ( Into :: into)
534+ }
535+
531536 /// Sets this window' icon.
532537 pub fn set_icon ( & self , icon : Icon ) -> crate :: Result < ( ) > {
533538 self . window . dispatcher . set_icon ( icon) . map_err ( Into :: into)
Original file line number Diff line number Diff line change @@ -593,12 +593,12 @@ class WindowManager {
593593 cmd : 'setMinSize' ,
594594 data : size
595595 ? {
596- type : size . type ,
597- data : {
598- width : size . width ,
599- height : size . height
600- }
596+ type : size . type ,
597+ data : {
598+ width : size . width ,
599+ height : size . height
601600 }
601+ }
602602 : null
603603 }
604604 } )
@@ -629,12 +629,12 @@ class WindowManager {
629629 cmd : 'setMaxSize' ,
630630 data : size
631631 ? {
632- type : size . type ,
633- data : {
634- width : size . width ,
635- height : size . height
636- }
632+ type : size . type ,
633+ data : {
634+ width : size . width ,
635+ height : size . height
637636 }
637+ }
638638 : null
639639 }
640640 } )
@@ -693,6 +693,20 @@ class WindowManager {
693693 } )
694694 }
695695
696+ /**
697+ * Bring the window to front and focus.
698+ *
699+ * @returns A promise indicating the success or failure of the operation.
700+ */
701+ async setFocus ( ) : Promise < void > {
702+ return invokeTauriCommand ( {
703+ __tauriModule : 'Window' ,
704+ message : {
705+ cmd : 'setFocus'
706+ }
707+ } )
708+ }
709+
696710 /**
697711 * Sets the window icon.
698712 *
You can’t perform that action at this time.
0 commit comments