From d1d13f6f160af73e549e2c2dd8a9d7991f10f1f6 Mon Sep 17 00:00:00 2001 From: Night_Hunter Date: Sat, 10 Dec 2022 01:42:51 +1300 Subject: add always on top action --- native/src/window/action.rs | 10 ++++++++++ winit/src/application.rs | 3 +++ 2 files changed, 13 insertions(+) diff --git a/native/src/window/action.rs b/native/src/window/action.rs index 168974bc..b16b7243 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -70,6 +70,12 @@ pub enum Action { /// /// - **Web / Wayland:** Unsupported. GainFocus, + /// Change whether or not the window will always be on top of other windows. + /// + /// ## Platform-specific + /// + /// - **iOS / Android / Web / Wayland:** Unsupported. + AlwaysOnTop(bool), } impl Action { @@ -96,6 +102,7 @@ impl Action { Action::RequestUserAttention(attention_type) } Self::GainFocus => Action::GainFocus, + Self::AlwaysOnTop(bool) => Action::AlwaysOnTop(bool), } } } @@ -122,6 +129,9 @@ impl fmt::Debug for Action { write!(f, "Action::RequestUserAttention") } Self::GainFocus => write!(f, "Action::GainFocus"), + Self::AlwaysOnTop(value) => { + write!(f, "Action::AlwaysOnTop({})", value) + } } } } diff --git a/winit/src/application.rs b/winit/src/application.rs index 769fe9dd..fda559d0 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -788,6 +788,9 @@ pub fn run_command( user_attention.map(conversion::user_attention), ), window::Action::GainFocus => window.focus_window(), + window::Action::AlwaysOnTop(value) => { + window.set_always_on_top(value) + } }, command::Action::System(action) => match action { system::Action::QueryInformation(_tag) => { -- cgit From 095ecf016b53ad25337663fb9f11a84f373150e0 Mon Sep 17 00:00:00 2001 From: Night_Hunter Date: Thu, 29 Dec 2022 13:30:14 +1300 Subject: update docs and change to SetAlwaysOnTop --- native/src/window/action.rs | 8 ++++---- winit/src/application.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/native/src/window/action.rs b/native/src/window/action.rs index b16b7243..0c711090 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -74,8 +74,8 @@ pub enum Action { /// /// ## Platform-specific /// - /// - **iOS / Android / Web / Wayland:** Unsupported. - AlwaysOnTop(bool), + /// - **Web / Wayland:** Unsupported. + SetAlwaysOnTop(bool), } impl Action { @@ -102,7 +102,7 @@ impl Action { Action::RequestUserAttention(attention_type) } Self::GainFocus => Action::GainFocus, - Self::AlwaysOnTop(bool) => Action::AlwaysOnTop(bool), + Self::SetAlwaysOnTop(bool) => Action::SetAlwaysOnTop(bool), } } } @@ -129,7 +129,7 @@ impl fmt::Debug for Action { write!(f, "Action::RequestUserAttention") } Self::GainFocus => write!(f, "Action::GainFocus"), - Self::AlwaysOnTop(value) => { + Self::SetAlwaysOnTop(value) => { write!(f, "Action::AlwaysOnTop({})", value) } } diff --git a/winit/src/application.rs b/winit/src/application.rs index fda559d0..d2e40de0 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -788,7 +788,7 @@ pub fn run_command( user_attention.map(conversion::user_attention), ), window::Action::GainFocus => window.focus_window(), - window::Action::AlwaysOnTop(value) => { + window::Action::SetAlwaysOnTop(value) => { window.set_always_on_top(value) } }, -- cgit From df861d9ece5e8695d05d08f104d37f55222fb363 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 17 Feb 2023 13:22:45 +0100 Subject: Rename `SetAlwaysOnTop` to `ChangeAlwaysOnTop` --- native/src/window/action.rs | 22 ++++++++++++++-------- winit/src/application.rs | 25 ++++++++++++++----------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/native/src/window/action.rs b/native/src/window/action.rs index 0c711090..c6361449 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -75,7 +75,7 @@ pub enum Action { /// ## Platform-specific /// /// - **Web / Wayland:** Unsupported. - SetAlwaysOnTop(bool), + ChangeAlwaysOnTop(bool), } impl Action { @@ -91,8 +91,8 @@ impl Action { 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)))), @@ -102,7 +102,9 @@ impl Action { Action::RequestUserAttention(attention_type) } Self::GainFocus => Action::GainFocus, - Self::SetAlwaysOnTop(bool) => Action::SetAlwaysOnTop(bool), + Self::ChangeAlwaysOnTop(on_top) => { + Action::ChangeAlwaysOnTop(on_top) + } } } } @@ -116,8 +118,12 @@ impl fmt::Debug for Action { 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} }}") } @@ -129,8 +135,8 @@ impl fmt::Debug for Action { write!(f, "Action::RequestUserAttention") } Self::GainFocus => write!(f, "Action::GainFocus"), - Self::SetAlwaysOnTop(value) => { - write!(f, "Action::AlwaysOnTop({})", value) + Self::ChangeAlwaysOnTop(on_top) => { + write!(f, "Action::AlwaysOnTop({on_top})") } } } diff --git a/winit/src/application.rs b/winit/src/application.rs index d2e40de0..1f37ffef 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -747,11 +747,11 @@ pub fn run_command( 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,15 +781,18 @@ pub fn run_command( 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::SetAlwaysOnTop(value) => { - window.set_always_on_top(value) + ); + } + window::Action::GainFocus => { + window.focus_window(); + } + window::Action::ChangeAlwaysOnTop(on_top) => { + window.set_always_on_top(on_top); } }, command::Action::System(action) => match action { -- cgit From db65c6904d38fe37ad0c31a11242d55f5f773c94 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 17 Feb 2023 13:24:46 +0100 Subject: Expose `change_always_on_top` helper in `window` module --- winit/src/window.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/winit/src/window.rs b/winit/src/window.rs index 6e3a383a..3d5a765b 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -23,13 +23,17 @@ pub fn resize(width: u32, height: u32) -> Command { } /// Maximizes the window. -pub fn maximize(value: bool) -> Command { - Command::single(command::Action::Window(window::Action::Maximize(value))) +pub fn maximize(maximized: bool) -> Command { + Command::single(command::Action::Window(window::Action::Maximize( + maximized, + ))) } /// Minimes the window. -pub fn minimize(value: bool) -> Command { - Command::single(command::Action::Window(window::Action::Minimize(value))) +pub fn minimize(minimized: bool) -> Command { + 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( pub fn gain_focus() -> Command { 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(on_top: bool) -> Command { + Command::single(command::Action::Window(window::Action::ChangeAlwaysOnTop( + on_top, + ))) +} -- cgit