Skip to content

Commit 1406963

Browse files
committed
update winit to 0.28 (#7480)
# Objective - Update winit to 0.28 ## Solution - Small API change - A security advisory has been added for a unmaintained crate used by a dependency of winit build script for wayland I didn't do anything for Android support in this PR though it should be fixable, it should be done in a separate one, maybe #6830 --- ## Changelog - `window.always_on_top` has been removed, you can now use `window.window_level` ## Migration Guide before: ```rust app.new() .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { always_on_top: true, ..default() }), ..default() })); ``` after: ```rust app.new() .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { window_level: bevy::window::WindowLevel::AlwaysOnTop, ..default() }), ..default() })); ```
1 parent 4f3ed19 commit 1406963

File tree

8 files changed

+65
-29
lines changed

8 files changed

+65
-29
lines changed

crates/bevy_window/src/window.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub struct Window {
141141
/// ## Platform-specific
142142
///
143143
/// - iOS / Android / Web / Wayland: Unsupported.
144-
pub always_on_top: bool,
144+
pub window_level: WindowLevel,
145145
/// The "html canvas" element selector.
146146
///
147147
/// If set, this selector will be used to find a matching html canvas element,
@@ -205,7 +205,7 @@ impl Default for Window {
205205
decorations: true,
206206
transparent: false,
207207
focused: true,
208-
always_on_top: false,
208+
window_level: Default::default(),
209209
fit_canvas_to_parent: false,
210210
prevent_default_event_handling: true,
211211
canvas: None,
@@ -800,3 +800,30 @@ pub enum WindowMode {
800800
/// Creates a fullscreen window that uses the maximum supported size.
801801
Fullscreen,
802802
}
803+
804+
/// A window level groups windows with respect to their z-position.
805+
///
806+
/// The relative ordering between windows in different window levels is fixed.
807+
/// The z-order of a window within the same window level may change dynamically on user interaction.
808+
///
809+
/// ## Platform-specific
810+
///
811+
/// - **iOS / Android / Web / Wayland:** Unsupported.
812+
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Reflect, FromReflect)]
813+
#[cfg_attr(
814+
feature = "serialize",
815+
derive(serde::Serialize, serde::Deserialize),
816+
reflect(Serialize, Deserialize)
817+
)]
818+
#[reflect(Debug, PartialEq)]
819+
pub enum WindowLevel {
820+
/// The window will always be below normal windows.
821+
///
822+
/// This is useful for a widget-based app.
823+
AlwaysOnBottom,
824+
/// The default.
825+
#[default]
826+
Normal,
827+
/// The window will always be on top of normal windows.
828+
AlwaysOnTop,
829+
}

crates/bevy_winit/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bevy_window = { path = "../bevy_window", version = "0.9.0" }
2323
bevy_utils = { path = "../bevy_utils", version = "0.9.0" }
2424

2525
# other
26-
winit = { version = "0.27", default-features = false }
26+
winit = { version = "0.28", default-features = false }
2727
approx = { version = "0.5", default-features = false }
2828
raw-window-handle = "0.5"
2929

crates/bevy_winit/src/converters.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bevy_input::{
55
ButtonState,
66
};
77
use bevy_math::Vec2;
8-
use bevy_window::CursorIcon;
8+
use bevy_window::{CursorIcon, WindowLevel};
99

1010
pub fn convert_keyboard_input(keyboard_input: &winit::event::KeyboardInput) -> KeyboardInput {
1111
KeyboardInput {
@@ -266,3 +266,11 @@ pub fn convert_cursor_icon(cursor_icon: CursorIcon) -> winit::window::CursorIcon
266266
CursorIcon::RowResize => winit::window::CursorIcon::RowResize,
267267
}
268268
}
269+
270+
pub fn convert_window_level(window_level: WindowLevel) -> winit::window::WindowLevel {
271+
match window_level {
272+
WindowLevel::AlwaysOnBottom => winit::window::WindowLevel::AlwaysOnBottom,
273+
WindowLevel::Normal => winit::window::WindowLevel::Normal,
274+
WindowLevel::AlwaysOnTop => winit::window::WindowLevel::AlwaysOnTop,
275+
}
276+
}

crates/bevy_winit/src/system.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use winit::{
1919

2020
#[cfg(target_arch = "wasm32")]
2121
use crate::web_resize::{CanvasParentResizeEventChannel, WINIT_CANVAS_SELECTOR};
22-
use crate::{converters, get_best_videomode, get_fitting_videomode, WinitWindows};
22+
use crate::{
23+
converters::{self, convert_window_level},
24+
get_best_videomode, get_fitting_videomode, WinitWindows,
25+
};
2326
#[cfg(target_arch = "wasm32")]
2427
use bevy_ecs::system::ResMut;
2528

@@ -262,8 +265,8 @@ pub(crate) fn changed_window(
262265
winit_window.focus_window();
263266
}
264267

265-
if window.always_on_top != previous.always_on_top {
266-
winit_window.set_always_on_top(window.always_on_top);
268+
if window.window_level != previous.window_level {
269+
winit_window.set_window_level(convert_window_level(window.window_level));
267270
}
268271

269272
// Currently unsupported changes

crates/bevy_winit/src/winit_windows.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use winit::{
88
monitor::MonitorHandle,
99
};
1010

11+
use crate::converters::convert_window_level;
12+
1113
#[derive(Debug, Default)]
1214
pub struct WinitWindows {
1315
pub windows: HashMap<winit::window::WindowId, winit::window::Window>,
@@ -65,7 +67,7 @@ impl WinitWindows {
6567
};
6668

6769
winit_window_builder = winit_window_builder
68-
.with_always_on_top(window.always_on_top)
70+
.with_window_level(convert_window_level(window.window_level))
6971
.with_resizable(window.resizable)
7072
.with_decorations(window.decorations)
7173
.with_transparent(window.transparent);

deny.toml

+3-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ yanked = "deny"
77
notice = "deny"
88
ignore = [
99
"RUSTSEC-2020-0056", # from cpal v0.14.1 - unmaintained - https://github.com/koute/stdweb/issues/403
10+
"RUSTSEC-2022-0048", # from xml-rs 0.8.4 - unmaintained - it's used in a build script of winit
1011
]
1112

1213
[licenses]
@@ -36,16 +37,11 @@ highlight = "all"
3637
skip = [
3738
{ name = "ndk-sys", version = "0.3" }, # from rodio v0.16.0
3839
{ name = "ndk", version = "0.6" }, # from rodio v0.16.0
39-
{ name = "raw-window-handle", version = "0.4" }, # from winit v0.27.4
4040
{ name = "nix", version = "0.23" }, # from cpal v0.14.1
41+
{ name = "redox_syscall", version = "0.2" }, # from notify v5.1.0
4142
{ name = "rustc_version", version = "0.2" }, # from postcard v1.0.2
4243
{ name = "semver", version = "0.9" }, # from postcard v1.0.2
43-
{ name = "windows_aarch64_msvc", version = "0.36" }, # from notify v5.0.0
44-
{ name = "windows_i686_gnu", version = "0.36" }, # from notify v5.0.0
45-
{ name = "windows_i686_msvc", version = "0.36" }, # from notify v5.0.0
46-
{ name = "windows_x86_64_gnu", version = "0.36" }, # from notify v5.0.0
47-
{ name = "windows_x86_64_msvc", version = "0.36" }, # from notify v5.0.0
48-
{ name = "windows-sys", version = "0.36" }, # from notify v5.0.0
44+
{ name = "windows-sys", version = "0.42" }, # from notify v5.1.0
4945
{ name = "windows", version = "0.37" }, # from rodio v0.16.0
5046
{ name = "windows_aarch64_msvc", version = "0.37" }, # from rodio v0.16.0
5147
{ name = "windows_i686_gnu", version = "0.37" }, # from rodio v0.16.0

examples/ui/window_fallthrough.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
// Set the window's parameters, note we're setting the window to always be on top.
1212
transparent: true,
1313
decorations: true,
14-
always_on_top: true,
14+
window_level: bevy::window::WindowLevel::AlwaysOnTop,
1515
..default()
1616
}),
1717
..default()

examples/window/window_settings.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use bevy::{
55
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
66
prelude::*,
7-
window::{CursorGrabMode, PresentMode},
7+
window::{CursorGrabMode, PresentMode, WindowLevel},
88
};
99

1010
fn main() {
@@ -28,7 +28,7 @@ fn main() {
2828
.add_system(toggle_cursor)
2929
.add_system(toggle_vsync)
3030
.add_system(cycle_cursor_icon)
31-
.add_system(toggle_always_on_top)
31+
.add_system(switch_level)
3232
.run();
3333
}
3434

@@ -47,23 +47,23 @@ fn toggle_vsync(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
4747
}
4848
}
4949

50-
/// This system toggles whether the window is always on top when pressing the T button
51-
/// You'll notice it won't be covered by other windows.
50+
/// This system switches the window level when pressing the T button
51+
/// You'll notice it won't be covered by other windows, or will be covered by all the other
52+
/// windows depending on the level.
5253
///
5354
/// This feature only works on some platforms. Please check the
54-
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.WindowDescriptor.html#structfield.always_on_top)
55+
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.window_level)
5556
/// for more details.
56-
fn toggle_always_on_top(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
57+
fn switch_level(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
5758
if input.just_pressed(KeyCode::T) {
5859
let mut window = windows.single_mut();
5960

60-
window.always_on_top = !window.always_on_top;
61-
62-
if window.always_on_top {
63-
info!("LOCKING WINDOW ON TOP");
64-
} else {
65-
info!("UNLOCKING WINDOW");
66-
}
61+
window.window_level = match window.window_level {
62+
WindowLevel::AlwaysOnBottom => WindowLevel::Normal,
63+
WindowLevel::Normal => WindowLevel::AlwaysOnTop,
64+
WindowLevel::AlwaysOnTop => WindowLevel::AlwaysOnBottom,
65+
};
66+
info!("WINDOW_LEVEL: {:?}", window.window_level);
6767
}
6868
}
6969

0 commit comments

Comments
 (0)