diff options
author | 2023-01-02 21:28:14 +0100 | |
---|---|---|
committer | 2023-01-02 21:28:14 +0100 | |
commit | f641e20f7fb43932bb30776c607fe3745311ccd6 (patch) | |
tree | 725a56c081144ae5fe8f15b009246a296340f6dd | |
parent | c740b3af75624c5faa6982fca56a1ebe03e03e98 (diff) | |
parent | dd25e93be0d5e5772bf535de38894f285cfb7768 (diff) | |
download | iced-f641e20f7fb43932bb30776c607fe3745311ccd6.tar.gz iced-f641e20f7fb43932bb30776c607fe3745311ccd6.tar.bz2 iced-f641e20f7fb43932bb30776c607fe3745311ccd6.zip |
Merge pull request #1585 from Night-Hunter-NF/FocusWindow
add action to make window focus
Diffstat (limited to '')
-rw-r--r-- | native/src/window/action.rs | 13 | ||||
-rw-r--r-- | winit/src/application.rs | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/native/src/window/action.rs b/native/src/window/action.rs index f0fe845d..37fcc273 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -58,6 +58,17 @@ pub enum Action<T> { /// - **X11:** Requests for user attention must be manually cleared. /// - **Wayland:** Requires `xdg_activation_v1` protocol, `None` has no effect. RequestUserAttention(Option<UserAttention>), + /// Brings the window to the front and sets input focus. Has no effect if the window is + /// already in focus, minimized, or not visible. + /// + /// This method steals input focus from other applications. Do not use this method unless + /// you are certain that's what the user wants. Focus stealing can cause an extremely disruptive + /// user experience. + /// + /// ## Platform-specific + /// + /// - **Web / Wayland:** Unsupported. + GainFocus, } impl<T> Action<T> { @@ -83,6 +94,7 @@ impl<T> Action<T> { Self::RequestUserAttention(attention_type) => { Action::RequestUserAttention(attention_type) } + Self::GainFocus => Action::GainFocus, } } } @@ -109,6 +121,7 @@ impl<T> fmt::Debug for Action<T> { Self::RequestUserAttention(_) => { write!(f, "Action::RequestUserAttention") } + Self::GainFocus => write!(f, "Action::GainFocus"), } } } diff --git a/winit/src/application.rs b/winit/src/application.rs index 7092e124..1973fdce 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -678,6 +678,7 @@ pub fn run_command<A, E>( .request_user_attention( user_attention.map(conversion::user_attention), ), + window::Action::GainFocus => window.focus_window(), }, command::Action::System(action) => match action { system::Action::QueryInformation(_tag) => { |