Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Expose winit always_on_top #6527

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,17 @@ category = "UI (User Interface)"
wasm = true

# Window
[[example]]
name = "always_on_top"
path = "examples/window/always_on_top.rs"

[package.metadata.example.always_on_top]
name = "Always On Top"
description = "A Window which is always over other windows."
category = "Window"
wasm = false


[[example]]
name = "clear_color"
path = "examples/window/clear_color.rs"
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,12 @@ pub struct WindowDescriptor {
pub fit_canvas_to_parent: bool,
/// Specifies how the alpha channel of the textures should be handled during compositing.
pub alpha_mode: CompositeAlphaMode,
/// Sets the window to always be on top of other windows.
///
/// ## Platform-specific
/// - iOS / Android / Web: Unsupported.
/// - Linux (Wayland): Unsupported.
pub always_on_top: bool,
}

impl Default for WindowDescriptor {
Expand All @@ -994,6 +1000,7 @@ impl Default for WindowDescriptor {
canvas: None,
fit_canvas_to_parent: false,
alpha_mode: CompositeAlphaMode::Auto,
always_on_top: false,
}
}
}
3 changes: 2 additions & 1 deletion crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ impl WinitWindows {
}
.with_resizable(window_descriptor.resizable)
.with_decorations(window_descriptor.decorations)
.with_transparent(window_descriptor.transparent),
.with_transparent(window_descriptor.transparent)
.with_always_on_top(window_descriptor.always_on_top),
};

let constraints = window_descriptor.resize_constraints.check_constraints();
Expand Down
29 changes: 29 additions & 0 deletions examples/window/always_on_top.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Shows how to display a window which stays on top of others.
//!
//! This feature works as expected depending on the platform. Please check the
laundmo marked this conversation as resolved.
Show resolved Hide resolved
//! [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.WindowDescriptor.html#structfield.always_on_top)
//! for more details.

use bevy::prelude::*;

fn main() {
App::new()
.add_startup_system(setup)
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
// Set always_on_top to force the window to stay on top of other windows.
always_on_top: true,
..default()
},
..default()
}))
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(SpriteBundle {
texture: asset_server.load("branding/icon.png"),
..default()
});
}