Skip to content

Commit b9b0a9a

Browse files
authored
Merge pull request #1587 from Night-Hunter-NF/AlwaysOnTop
add always on top action
2 parents 871f59f + db65c69 commit b9b0a9a

3 files changed

Lines changed: 50 additions & 17 deletions

File tree

native/src/window/action.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ pub enum Action<T> {
7070
///
7171
/// - **Web / Wayland:** Unsupported.
7272
GainFocus,
73+
/// Change whether or not the window will always be on top of other windows.
74+
///
75+
/// ## Platform-specific
76+
///
77+
/// - **Web / Wayland:** Unsupported.
78+
ChangeAlwaysOnTop(bool),
7379
}
7480

7581
impl<T> Action<T> {
@@ -85,8 +91,8 @@ impl<T> Action<T> {
8591
Self::Close => Action::Close,
8692
Self::Drag => Action::Drag,
8793
Self::Resize { width, height } => Action::Resize { width, height },
88-
Self::Maximize(bool) => Action::Maximize(bool),
89-
Self::Minimize(bool) => Action::Minimize(bool),
94+
Self::Maximize(maximized) => Action::Maximize(maximized),
95+
Self::Minimize(minimized) => Action::Minimize(minimized),
9096
Self::Move { x, y } => Action::Move { x, y },
9197
Self::ChangeMode(mode) => Action::ChangeMode(mode),
9298
Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))),
@@ -96,6 +102,9 @@ impl<T> Action<T> {
96102
Action::RequestUserAttention(attention_type)
97103
}
98104
Self::GainFocus => Action::GainFocus,
105+
Self::ChangeAlwaysOnTop(on_top) => {
106+
Action::ChangeAlwaysOnTop(on_top)
107+
}
99108
}
100109
}
101110
}
@@ -109,8 +118,12 @@ impl<T> fmt::Debug for Action<T> {
109118
f,
110119
"Action::Resize {{ widget: {width}, height: {height} }}"
111120
),
112-
Self::Maximize(value) => write!(f, "Action::Maximize({value})"),
113-
Self::Minimize(value) => write!(f, "Action::Minimize({value}"),
121+
Self::Maximize(maximized) => {
122+
write!(f, "Action::Maximize({maximized})")
123+
}
124+
Self::Minimize(minimized) => {
125+
write!(f, "Action::Minimize({minimized}")
126+
}
114127
Self::Move { x, y } => {
115128
write!(f, "Action::Move {{ x: {x}, y: {y} }}")
116129
}
@@ -122,6 +135,9 @@ impl<T> fmt::Debug for Action<T> {
122135
write!(f, "Action::RequestUserAttention")
123136
}
124137
Self::GainFocus => write!(f, "Action::GainFocus"),
138+
Self::ChangeAlwaysOnTop(on_top) => {
139+
write!(f, "Action::AlwaysOnTop({on_top})")
140+
}
125141
}
126142
}
127143
}

winit/src/application.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,11 @@ pub fn run_command<A, E>(
747747
height,
748748
});
749749
}
750-
window::Action::Maximize(value) => {
751-
window.set_maximized(value);
750+
window::Action::Maximize(maximized) => {
751+
window.set_maximized(maximized);
752752
}
753-
window::Action::Minimize(value) => {
754-
window.set_minimized(value);
753+
window::Action::Minimize(minimized) => {
754+
window.set_minimized(minimized);
755755
}
756756
window::Action::Move { x, y } => {
757757
window.set_outer_position(winit::dpi::LogicalPosition {
@@ -781,13 +781,19 @@ pub fn run_command<A, E>(
781781
window.set_maximized(!window.is_maximized())
782782
}
783783
window::Action::ToggleDecorations => {
784-
window.set_decorations(!window.is_decorated())
784+
window.set_decorations(!window.is_decorated());
785785
}
786-
window::Action::RequestUserAttention(user_attention) => window
787-
.request_user_attention(
786+
window::Action::RequestUserAttention(user_attention) => {
787+
window.request_user_attention(
788788
user_attention.map(conversion::user_attention),
789-
),
790-
window::Action::GainFocus => window.focus_window(),
789+
);
790+
}
791+
window::Action::GainFocus => {
792+
window.focus_window();
793+
}
794+
window::Action::ChangeAlwaysOnTop(on_top) => {
795+
window.set_always_on_top(on_top);
796+
}
791797
},
792798
command::Action::System(action) => match action {
793799
system::Action::QueryInformation(_tag) => {

winit/src/window.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ pub fn resize<Message>(width: u32, height: u32) -> Command<Message> {
2323
}
2424

2525
/// Maximizes the window.
26-
pub fn maximize<Message>(value: bool) -> Command<Message> {
27-
Command::single(command::Action::Window(window::Action::Maximize(value)))
26+
pub fn maximize<Message>(maximized: bool) -> Command<Message> {
27+
Command::single(command::Action::Window(window::Action::Maximize(
28+
maximized,
29+
)))
2830
}
2931

3032
/// Minimes the window.
31-
pub fn minimize<Message>(value: bool) -> Command<Message> {
32-
Command::single(command::Action::Window(window::Action::Minimize(value)))
33+
pub fn minimize<Message>(minimized: bool) -> Command<Message> {
34+
Command::single(command::Action::Window(window::Action::Minimize(
35+
minimized,
36+
)))
3337
}
3438

3539
/// Moves a window to the given logical coordinates.
@@ -84,3 +88,10 @@ pub fn request_user_attention<Message>(
8488
pub fn gain_focus<Message>() -> Command<Message> {
8589
Command::single(command::Action::Window(window::Action::GainFocus))
8690
}
91+
92+
/// Changes whether or not the window will always be on top of other windows.
93+
pub fn change_always_on_top<Message>(on_top: bool) -> Command<Message> {
94+
Command::single(command::Action::Window(window::Action::ChangeAlwaysOnTop(
95+
on_top,
96+
)))
97+
}

0 commit comments

Comments
 (0)