Skip to content

Commit

Permalink
Allow changing at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett committed Nov 9, 2022
1 parent 8c62151 commit fd2a706
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ pub struct Window {
fit_canvas_to_parent: bool,
command_queue: Vec<WindowCommand>,
alpha_mode: CompositeAlphaMode,
always_on_top: bool,
}
/// A command to be sent to a window.
///
Expand Down Expand Up @@ -369,6 +370,9 @@ pub enum WindowCommand {
SetResizeConstraints {
resize_constraints: WindowResizeConstraints,
},
SetAlwaysOnTop {
always_on_top: bool,
},
Close,
}

Expand Down Expand Up @@ -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`].
Expand Down Expand Up @@ -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<IVec2> {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fd2a706

Please sign in to comment.