Merge pull request #1587 from Night-Hunter-NF/AlwaysOnTop
add always on top action
This commit is contained in:
commit
b9b0a9a1f4
3 changed files with 50 additions and 17 deletions
|
|
@ -70,6 +70,12 @@ pub enum Action<T> {
|
||||||
///
|
///
|
||||||
/// - **Web / Wayland:** Unsupported.
|
/// - **Web / Wayland:** Unsupported.
|
||||||
GainFocus,
|
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> {
|
impl<T> Action<T> {
|
||||||
|
|
@ -85,8 +91,8 @@ impl<T> Action<T> {
|
||||||
Self::Close => Action::Close,
|
Self::Close => Action::Close,
|
||||||
Self::Drag => Action::Drag,
|
Self::Drag => Action::Drag,
|
||||||
Self::Resize { width, height } => Action::Resize { width, height },
|
Self::Resize { width, height } => Action::Resize { width, height },
|
||||||
Self::Maximize(bool) => Action::Maximize(bool),
|
Self::Maximize(maximized) => Action::Maximize(maximized),
|
||||||
Self::Minimize(bool) => Action::Minimize(bool),
|
Self::Minimize(minimized) => Action::Minimize(minimized),
|
||||||
Self::Move { x, y } => Action::Move { x, y },
|
Self::Move { x, y } => Action::Move { x, y },
|
||||||
Self::ChangeMode(mode) => Action::ChangeMode(mode),
|
Self::ChangeMode(mode) => Action::ChangeMode(mode),
|
||||||
Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))),
|
Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))),
|
||||||
|
|
@ -96,6 +102,9 @@ impl<T> Action<T> {
|
||||||
Action::RequestUserAttention(attention_type)
|
Action::RequestUserAttention(attention_type)
|
||||||
}
|
}
|
||||||
Self::GainFocus => Action::GainFocus,
|
Self::GainFocus => Action::GainFocus,
|
||||||
|
Self::ChangeAlwaysOnTop(on_top) => {
|
||||||
|
Action::ChangeAlwaysOnTop(on_top)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,8 +118,12 @@ impl<T> fmt::Debug for Action<T> {
|
||||||
f,
|
f,
|
||||||
"Action::Resize {{ widget: {width}, height: {height} }}"
|
"Action::Resize {{ widget: {width}, height: {height} }}"
|
||||||
),
|
),
|
||||||
Self::Maximize(value) => write!(f, "Action::Maximize({value})"),
|
Self::Maximize(maximized) => {
|
||||||
Self::Minimize(value) => write!(f, "Action::Minimize({value}"),
|
write!(f, "Action::Maximize({maximized})")
|
||||||
|
}
|
||||||
|
Self::Minimize(minimized) => {
|
||||||
|
write!(f, "Action::Minimize({minimized}")
|
||||||
|
}
|
||||||
Self::Move { x, y } => {
|
Self::Move { x, y } => {
|
||||||
write!(f, "Action::Move {{ x: {x}, y: {y} }}")
|
write!(f, "Action::Move {{ x: {x}, y: {y} }}")
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +135,9 @@ impl<T> fmt::Debug for Action<T> {
|
||||||
write!(f, "Action::RequestUserAttention")
|
write!(f, "Action::RequestUserAttention")
|
||||||
}
|
}
|
||||||
Self::GainFocus => write!(f, "Action::GainFocus"),
|
Self::GainFocus => write!(f, "Action::GainFocus"),
|
||||||
|
Self::ChangeAlwaysOnTop(on_top) => {
|
||||||
|
write!(f, "Action::AlwaysOnTop({on_top})")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -747,11 +747,11 @@ pub fn run_command<A, E>(
|
||||||
height,
|
height,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
window::Action::Maximize(value) => {
|
window::Action::Maximize(maximized) => {
|
||||||
window.set_maximized(value);
|
window.set_maximized(maximized);
|
||||||
}
|
}
|
||||||
window::Action::Minimize(value) => {
|
window::Action::Minimize(minimized) => {
|
||||||
window.set_minimized(value);
|
window.set_minimized(minimized);
|
||||||
}
|
}
|
||||||
window::Action::Move { x, y } => {
|
window::Action::Move { x, y } => {
|
||||||
window.set_outer_position(winit::dpi::LogicalPosition {
|
window.set_outer_position(winit::dpi::LogicalPosition {
|
||||||
|
|
@ -781,13 +781,19 @@ pub fn run_command<A, E>(
|
||||||
window.set_maximized(!window.is_maximized())
|
window.set_maximized(!window.is_maximized())
|
||||||
}
|
}
|
||||||
window::Action::ToggleDecorations => {
|
window::Action::ToggleDecorations => {
|
||||||
window.set_decorations(!window.is_decorated())
|
window.set_decorations(!window.is_decorated());
|
||||||
}
|
}
|
||||||
window::Action::RequestUserAttention(user_attention) => window
|
window::Action::RequestUserAttention(user_attention) => {
|
||||||
.request_user_attention(
|
window.request_user_attention(
|
||||||
user_attention.map(conversion::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 {
|
command::Action::System(action) => match action {
|
||||||
system::Action::QueryInformation(_tag) => {
|
system::Action::QueryInformation(_tag) => {
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,17 @@ pub fn resize<Message>(width: u32, height: u32) -> Command<Message> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Maximizes the window.
|
/// Maximizes the window.
|
||||||
pub fn maximize<Message>(value: bool) -> Command<Message> {
|
pub fn maximize<Message>(maximized: bool) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(window::Action::Maximize(value)))
|
Command::single(command::Action::Window(window::Action::Maximize(
|
||||||
|
maximized,
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Minimes the window.
|
/// Minimes the window.
|
||||||
pub fn minimize<Message>(value: bool) -> Command<Message> {
|
pub fn minimize<Message>(minimized: bool) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(window::Action::Minimize(value)))
|
Command::single(command::Action::Window(window::Action::Minimize(
|
||||||
|
minimized,
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Moves a window to the given logical coordinates.
|
/// 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> {
|
pub fn gain_focus<Message>() -> Command<Message> {
|
||||||
Command::single(command::Action::Window(window::Action::GainFocus))
|
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,
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue