Merge pull request #1584 from Night-Hunter-NF/RequestUserAttention
add action to request user attention
This commit is contained in:
commit
d956b8a9fb
6 changed files with 75 additions and 12 deletions
|
|
@ -2,7 +2,9 @@
|
||||||
mod action;
|
mod action;
|
||||||
mod event;
|
mod event;
|
||||||
mod mode;
|
mod mode;
|
||||||
|
mod user_attention;
|
||||||
|
|
||||||
pub use action::Action;
|
pub use action::Action;
|
||||||
pub use event::Event;
|
pub use event::Event;
|
||||||
pub use mode::Mode;
|
pub use mode::Mode;
|
||||||
|
pub use user_attention::UserAttention;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::window::Mode;
|
use crate::window::{Mode, UserAttention};
|
||||||
|
|
||||||
use iced_futures::MaybeSend;
|
use iced_futures::MaybeSend;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
@ -35,6 +35,8 @@ pub enum Action<T> {
|
||||||
},
|
},
|
||||||
/// Set the [`Mode`] of the window.
|
/// Set the [`Mode`] of the window.
|
||||||
SetMode(Mode),
|
SetMode(Mode),
|
||||||
|
/// Fetch the current [`Mode`] of the window.
|
||||||
|
FetchMode(Box<dyn FnOnce(Mode) -> T + 'static>),
|
||||||
/// Sets the window to maximized or back
|
/// Sets the window to maximized or back
|
||||||
ToggleMaximize,
|
ToggleMaximize,
|
||||||
/// Toggles whether window has decorations
|
/// Toggles whether window has decorations
|
||||||
|
|
@ -42,8 +44,20 @@ pub enum Action<T> {
|
||||||
/// - **X11:** Not implemented.
|
/// - **X11:** Not implemented.
|
||||||
/// - **Web:** Unsupported.
|
/// - **Web:** Unsupported.
|
||||||
ToggleDecorations,
|
ToggleDecorations,
|
||||||
/// Fetch the current [`Mode`] of the window.
|
/// Requests user attention to the window, this has no effect if the application
|
||||||
FetchMode(Box<dyn FnOnce(Mode) -> T + 'static>),
|
/// 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> {
|
impl<T> Action<T> {
|
||||||
|
|
@ -63,9 +77,12 @@ impl<T> Action<T> {
|
||||||
Self::Minimize(bool) => Action::Minimize(bool),
|
Self::Minimize(bool) => Action::Minimize(bool),
|
||||||
Self::Move { x, y } => Action::Move { x, y },
|
Self::Move { x, y } => Action::Move { x, y },
|
||||||
Self::SetMode(mode) => Action::SetMode(mode),
|
Self::SetMode(mode) => Action::SetMode(mode),
|
||||||
|
Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))),
|
||||||
Self::ToggleMaximize => Action::ToggleMaximize,
|
Self::ToggleMaximize => Action::ToggleMaximize,
|
||||||
Self::ToggleDecorations => Action::ToggleDecorations,
|
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)
|
write!(f, "Action::Move {{ x: {}, y: {} }}", x, y)
|
||||||
}
|
}
|
||||||
Self::SetMode(mode) => write!(f, "Action::SetMode({:?})", mode),
|
Self::SetMode(mode) => write!(f, "Action::SetMode({:?})", mode),
|
||||||
|
Self::FetchMode(_) => write!(f, "Action::FetchMode"),
|
||||||
Self::ToggleMaximize => write!(f, "Action::ToggleMaximize"),
|
Self::ToggleMaximize => write!(f, "Action::ToggleMaximize"),
|
||||||
Self::ToggleDecorations => write!(f, "Action::ToggleDecorations"),
|
Self::ToggleDecorations => write!(f, "Action::ToggleDecorations"),
|
||||||
Self::FetchMode(_) => write!(f, "Action::FetchMode"),
|
Self::RequestUserAttention(_) => {
|
||||||
|
write!(f, "Action::RequestUserAttention")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
native/src/window/user_attention.rs
Normal file
21
native/src/window/user_attention.rs
Normal file
|
|
@ -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,
|
||||||
|
}
|
||||||
|
|
@ -657,12 +657,6 @@ pub fn run_command<A, E>(
|
||||||
mode,
|
mode,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
window::Action::ToggleMaximize => {
|
|
||||||
window.set_maximized(!window.is_maximized())
|
|
||||||
}
|
|
||||||
window::Action::ToggleDecorations => {
|
|
||||||
window.set_decorations(!window.is_decorated())
|
|
||||||
}
|
|
||||||
window::Action::FetchMode(tag) => {
|
window::Action::FetchMode(tag) => {
|
||||||
let mode = if window.is_visible().unwrap_or(true) {
|
let mode = if window.is_visible().unwrap_or(true) {
|
||||||
conversion::mode(window.fullscreen())
|
conversion::mode(window.fullscreen())
|
||||||
|
|
@ -674,6 +668,16 @@ pub fn run_command<A, E>(
|
||||||
.send_event(tag(mode))
|
.send_event(tag(mode))
|
||||||
.expect("Send message to event loop");
|
.expect("Send message to event loop");
|
||||||
}
|
}
|
||||||
|
window::Action::ToggleMaximize => {
|
||||||
|
window.set_maximized(!window.is_maximized())
|
||||||
|
}
|
||||||
|
window::Action::ToggleDecorations => {
|
||||||
|
window.set_decorations(!window.is_decorated())
|
||||||
|
}
|
||||||
|
window::Action::RequestUserAttention(user_attention) => window
|
||||||
|
.request_user_attention(
|
||||||
|
user_attention.map(conversion::user_attention),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
command::Action::System(action) => match action {
|
command::Action::System(action) => match action {
|
||||||
system::Action::QueryInformation(_tag) => {
|
system::Action::QueryInformation(_tag) => {
|
||||||
|
|
|
||||||
|
|
@ -493,6 +493,22 @@ pub fn key_code(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts some [`UserAttention`] into it's `winit` counterpart.
|
||||||
|
///
|
||||||
|
/// [`UserAttention`]: window::UserAttention
|
||||||
|
pub fn user_attention(
|
||||||
|
user_attention: window::UserAttention,
|
||||||
|
) -> winit::window::UserAttentionType {
|
||||||
|
match user_attention {
|
||||||
|
window::UserAttention::Critical => {
|
||||||
|
winit::window::UserAttentionType::Critical
|
||||||
|
}
|
||||||
|
window::UserAttention::Informational => {
|
||||||
|
winit::window::UserAttentionType::Informational
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// As defined in: http://www.unicode.org/faq/private_use.html
|
// As defined in: http://www.unicode.org/faq/private_use.html
|
||||||
pub(crate) fn is_private_use_character(c: char) -> bool {
|
pub(crate) fn is_private_use_character(c: char) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
use crate::command::{self, Command};
|
use crate::command::{self, Command};
|
||||||
use iced_native::window;
|
use iced_native::window;
|
||||||
|
|
||||||
pub use window::{Event, Mode};
|
pub use window::{Event, Mode, UserAttention};
|
||||||
|
|
||||||
/// Closes the current window and exits the application.
|
/// Closes the current window and exits the application.
|
||||||
pub fn close<Message>() -> Command<Message> {
|
pub fn close<Message>() -> Command<Message> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue