Merge pull request #1587 from Night-Hunter-NF/AlwaysOnTop

add always on top action
This commit is contained in:
Héctor Ramón 2023-02-17 13:39:58 +01:00 committed by GitHub
commit b9b0a9a1f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 17 deletions

View file

@ -70,6 +70,12 @@ pub enum Action<T> {
///
/// - **Web / Wayland:** Unsupported.
GainFocus,
/// Change whether or not the window will always be on top of other windows.
///
/// ## Platform-specific
///
/// - **Web / Wayland:** Unsupported.
ChangeAlwaysOnTop(bool),
}
impl<T> Action<T> {
@ -85,8 +91,8 @@ impl<T> Action<T> {
Self::Close => Action::Close,
Self::Drag => Action::Drag,
Self::Resize { width, height } => Action::Resize { width, height },
Self::Maximize(bool) => Action::Maximize(bool),
Self::Minimize(bool) => Action::Minimize(bool),
Self::Maximize(maximized) => Action::Maximize(maximized),
Self::Minimize(minimized) => Action::Minimize(minimized),
Self::Move { x, y } => Action::Move { x, y },
Self::ChangeMode(mode) => Action::ChangeMode(mode),
Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))),
@ -96,6 +102,9 @@ impl<T> Action<T> {
Action::RequestUserAttention(attention_type)
}
Self::GainFocus => Action::GainFocus,
Self::ChangeAlwaysOnTop(on_top) => {
Action::ChangeAlwaysOnTop(on_top)
}
}
}
}
@ -109,8 +118,12 @@ impl<T> fmt::Debug for Action<T> {
f,
"Action::Resize {{ widget: {width}, height: {height} }}"
),
Self::Maximize(value) => write!(f, "Action::Maximize({value})"),
Self::Minimize(value) => write!(f, "Action::Minimize({value}"),
Self::Maximize(maximized) => {
write!(f, "Action::Maximize({maximized})")
}
Self::Minimize(minimized) => {
write!(f, "Action::Minimize({minimized}")
}
Self::Move { x, y } => {
write!(f, "Action::Move {{ x: {x}, y: {y} }}")
}
@ -122,6 +135,9 @@ impl<T> fmt::Debug for Action<T> {
write!(f, "Action::RequestUserAttention")
}
Self::GainFocus => write!(f, "Action::GainFocus"),
Self::ChangeAlwaysOnTop(on_top) => {
write!(f, "Action::AlwaysOnTop({on_top})")
}
}
}
}

View file

@ -747,11 +747,11 @@ pub fn run_command<A, E>(
height,
});
}
window::Action::Maximize(value) => {
window.set_maximized(value);
window::Action::Maximize(maximized) => {
window.set_maximized(maximized);
}
window::Action::Minimize(value) => {
window.set_minimized(value);
window::Action::Minimize(minimized) => {
window.set_minimized(minimized);
}
window::Action::Move { x, y } => {
window.set_outer_position(winit::dpi::LogicalPosition {
@ -781,13 +781,19 @@ pub fn run_command<A, E>(
window.set_maximized(!window.is_maximized())
}
window::Action::ToggleDecorations => {
window.set_decorations(!window.is_decorated())
window.set_decorations(!window.is_decorated());
}
window::Action::RequestUserAttention(user_attention) => window
.request_user_attention(
window::Action::RequestUserAttention(user_attention) => {
window.request_user_attention(
user_attention.map(conversion::user_attention),
),
window::Action::GainFocus => window.focus_window(),
);
}
window::Action::GainFocus => {
window.focus_window();
}
window::Action::ChangeAlwaysOnTop(on_top) => {
window.set_always_on_top(on_top);
}
},
command::Action::System(action) => match action {
system::Action::QueryInformation(_tag) => {

View file

@ -23,13 +23,17 @@ pub fn resize<Message>(width: u32, height: u32) -> Command<Message> {
}
/// Maximizes the window.
pub fn maximize<Message>(value: bool) -> Command<Message> {
Command::single(command::Action::Window(window::Action::Maximize(value)))
pub fn maximize<Message>(maximized: bool) -> Command<Message> {
Command::single(command::Action::Window(window::Action::Maximize(
maximized,
)))
}
/// Minimes the window.
pub fn minimize<Message>(value: bool) -> Command<Message> {
Command::single(command::Action::Window(window::Action::Minimize(value)))
pub fn minimize<Message>(minimized: bool) -> Command<Message> {
Command::single(command::Action::Window(window::Action::Minimize(
minimized,
)))
}
/// Moves a window to the given logical coordinates.
@ -84,3 +88,10 @@ pub fn request_user_attention<Message>(
pub fn gain_focus<Message>() -> Command<Message> {
Command::single(command::Action::Window(window::Action::GainFocus))
}
/// Changes whether or not the window will always be on top of other windows.
pub fn change_always_on_top<Message>(on_top: bool) -> Command<Message> {
Command::single(command::Action::Window(window::Action::ChangeAlwaysOnTop(
on_top,
)))
}