Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion nannou/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! with no `unsafe` and no builder machinery. See the [`context`] module and the `system_param`
//! example for details.
use bevy::diagnostic::FrameTimeDiagnosticsPlugin;
use bevy::prelude::{App as BevyApp, IntoScheduleConfigs, Plugin, PostUpdate};
use bevy::prelude::{App as BevyApp, IntoScheduleConfigs, Last, Plugin, PostUpdate};
use bevy::winit::WinitSettings;

pub use find_folder;
Expand Down Expand Up @@ -61,6 +61,7 @@ impl Plugin for NannouPlugin {
PostUpdate,
window::update_default_camera_z_range.before(bevy::camera::CameraUpdateSystems),
);
app.add_systems(Last, window::reapply_initial_window_level);
// `FramePlugin` extracts per-window scale factors so a `Frame` can be constructed from a
// (custom or classic) render-world system.
app.add_plugins(crate::frame::FramePlugin);
Expand Down
25 changes: 25 additions & 0 deletions nannou/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use bevy::{
camera::Hdr,
camera::RenderTarget,
camera::visibility::RenderLayers,
ecs::system::NonSendMarker,
input::mouse::MouseWheel,
prelude::*,
render::extract_component::ExtractComponent,
window::{PresentMode, PrimaryWindow, WindowLevel, WindowRef},
winit::{WINIT_WINDOWS, converters::convert_window_level},
};

/// A context for building a window.
Expand Down Expand Up @@ -691,3 +693,26 @@ pub(crate) fn update_default_camera_z_range(
}
}
}

/// Marks a window whose initial [`WindowLevel`] nannou has already re-applied to the underlying
/// winit window.
#[derive(Component)]
pub(crate) struct WindowLevelApplied;

/// Re-apply each window's [`WindowLevel`] once, as soon as its winit window exists.
pub(crate) fn reapply_initial_window_level(
mut commands: Commands,
windows: Query<(Entity, &bevy::window::Window), Without<WindowLevelApplied>>,
_non_send_marker: NonSendMarker,
) {
WINIT_WINDOWS.with_borrow(|winit_windows| {
for (entity, window) in windows.iter() {
// The winit window may not have been created yet, retry on a later frame.
let Some(winit_window) = winit_windows.get_window(entity) else {
continue;
};
winit_window.set_window_level(convert_window_level(window.window_level));
commands.entity(entity).insert(WindowLevelApplied);
}
});
}
Loading