diff options
Diffstat (limited to 'native/src/window')
| -rw-r--r-- | native/src/window/action.rs | 30 | ||||
| -rw-r--r-- | native/src/window/user_attention.rs | 21 | 
2 files changed, 46 insertions, 5 deletions
diff --git a/native/src/window/action.rs b/native/src/window/action.rs index da307e97..f0fe845d 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -1,4 +1,4 @@ -use crate::window::Mode; +use crate::window::{Mode, UserAttention};  use iced_futures::MaybeSend;  use std::fmt; @@ -35,6 +35,8 @@ pub enum Action<T> {      },      /// Set the [`Mode`] of the window.      SetMode(Mode), +    /// Fetch the current [`Mode`] of the window. +    FetchMode(Box<dyn FnOnce(Mode) -> T + 'static>),      /// Sets the window to maximized or back      ToggleMaximize,      /// Toggles whether window has decorations @@ -42,8 +44,20 @@ pub enum Action<T> {      /// - **X11:** Not implemented.      /// - **Web:** Unsupported.      ToggleDecorations, -    /// Fetch the current [`Mode`] of the window. -    FetchMode(Box<dyn FnOnce(Mode) -> T + 'static>), +    /// Requests user attention to the window, this has no effect if the application +    /// is already focused. How requesting for user attention manifests is platform dependent, +    /// see [`UserAttentionType`] for details. +    /// +    /// Providing `None` will unset the request for user attention. Unsetting the request for +    /// user attention might not be done automatically by the WM when the window receives input. +    /// +    /// ## Platform-specific +    /// +    /// - **iOS / Android / Web:** Unsupported. +    /// - **macOS:** `None` has no effect. +    /// - **X11:** Requests for user attention must be manually cleared. +    /// - **Wayland:** Requires `xdg_activation_v1` protocol, `None` has no effect. +    RequestUserAttention(Option<UserAttention>),  }  impl<T> Action<T> { @@ -63,9 +77,12 @@ impl<T> Action<T> {              Self::Minimize(bool) => Action::Minimize(bool),              Self::Move { x, y } => Action::Move { x, y },              Self::SetMode(mode) => Action::SetMode(mode), +            Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))),              Self::ToggleMaximize => Action::ToggleMaximize,              Self::ToggleDecorations => Action::ToggleDecorations, -            Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))), +            Self::RequestUserAttention(attention_type) => { +                Action::RequestUserAttention(attention_type) +            }          }      }  } @@ -86,9 +103,12 @@ impl<T> fmt::Debug for Action<T> {                  write!(f, "Action::Move {{ x: {}, y: {} }}", x, y)              }              Self::SetMode(mode) => write!(f, "Action::SetMode({:?})", mode), +            Self::FetchMode(_) => write!(f, "Action::FetchMode"),              Self::ToggleMaximize => write!(f, "Action::ToggleMaximize"),              Self::ToggleDecorations => write!(f, "Action::ToggleDecorations"), -            Self::FetchMode(_) => write!(f, "Action::FetchMode"), +            Self::RequestUserAttention(_) => { +                write!(f, "Action::RequestUserAttention") +            }          }      }  } diff --git a/native/src/window/user_attention.rs b/native/src/window/user_attention.rs new file mode 100644 index 00000000..b03dfeef --- /dev/null +++ b/native/src/window/user_attention.rs @@ -0,0 +1,21 @@ +/// The type of user attention to request. +/// +/// ## Platform-specific +/// +/// - **X11:** Sets the WM's `XUrgencyHint`. No distinction between [`Critical`] and [`Informational`]. +/// +/// [`Critical`]: Self::Critical +/// [`Informational`]: Self::Informational +#[derive(Debug, Clone, Copy)] +pub enum UserAttention { +    /// ## Platform-specific +    /// +    /// - **macOS:** Bounces the dock icon until the application is in focus. +    /// - **Windows:** Flashes both the window and the taskbar button until the application is in focus. +    Critical, +    /// ## Platform-specific +    /// +    /// - **macOS:** Bounces the dock icon once. +    /// - **Windows:** Flashes the taskbar button until the application is in focus. +    Informational, +}  | 
