diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index 3a912619bdd5f..7849c508de198 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -294,6 +294,7 @@ pub struct Window { fit_canvas_to_parent: bool, command_queue: Vec, alpha_mode: CompositeAlphaMode, + always_on_top: bool, } /// A command to be sent to a window. /// @@ -369,6 +370,9 @@ pub enum WindowCommand { SetResizeConstraints { resize_constraints: WindowResizeConstraints, }, + SetAlwaysOnTop { + always_on_top: bool, + }, Close, } @@ -438,6 +442,7 @@ impl Window { fit_canvas_to_parent: window_descriptor.fit_canvas_to_parent, command_queue: Vec::new(), alpha_mode: window_descriptor.alpha_mode, + always_on_top: window_descriptor.always_on_top, } } /// Get the window's [`WindowId`]. @@ -496,6 +501,10 @@ impl Window { self.resize_constraints } + pub fn always_on_top(&self) -> bool { + self.always_on_top + } + /// The window's client position in physical pixels. #[inline] pub fn position(&self) -> Option { @@ -588,6 +597,12 @@ impl Window { }); } + pub fn set_always_on_top(&mut self, always_on_top: bool) { + self.always_on_top = always_on_top; + self.command_queue + .push(WindowCommand::SetAlwaysOnTop { always_on_top }); + } + #[allow(missing_docs)] #[inline] pub fn update_scale_factor_from_backend(&mut self, scale_factor: f64) { diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index b4dcb56b00cac..fc6d162097d6e 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -140,6 +140,10 @@ fn change_window( .set_cursor_grab(convert_cursor_grab_mode(grab_mode)) .unwrap_or_else(|e| error!("Unable to un/grab cursor: {}", e)); } + bevy_window::WindowCommand::SetAlwaysOnTop { always_on_top } => { + let window = winit_windows.get_window(id).unwrap(); + window.set_always_on_top(always_on_top) + } bevy_window::WindowCommand::SetCursorVisibility { visible } => { let window = winit_windows.get_window(id).unwrap(); window.set_cursor_visible(visible);