Skip to content

Commit 0f044bb

Browse files
committed
Simplify primary window closed system
1 parent 08daf4b commit 0f044bb

File tree

4 files changed

+10
-22
lines changed

4 files changed

+10
-22
lines changed

crates/bevy_window/src/system.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{PrimaryWindow, Window, WindowCloseRequested, WindowClosed, WindowFoc
33
use bevy_app::AppExit;
44
use bevy_ecs::prelude::*;
55
use bevy_input::{keyboard::KeyCode, Input};
6-
use bevy_utils::tracing::warn;
76

87
/// Exit the application when there are no open windows.
98
///
@@ -27,24 +26,10 @@ pub fn exit_on_all_closed(mut app_exit_events: EventWriter<AppExit>, windows: Qu
2726
pub fn exit_on_primary_closed(
2827
mut app_exit_events: EventWriter<AppExit>,
2928
primary_window: Option<Res<PrimaryWindow>>,
30-
mut window_close: EventReader<WindowClosed>,
3129
) {
32-
match primary_window.as_ref() {
33-
Some(primary_window) => {
34-
for window in window_close.iter() {
35-
warn!(
36-
"primary_window: {:?}, closed: {:?}",
37-
primary_window.window, window.window
38-
);
39-
if primary_window.window == window.window {
40-
// Primary window has been closed
41-
app_exit_events.send(AppExit);
42-
}
43-
}
44-
}
45-
None => {
46-
app_exit_events.send(AppExit);
47-
}
30+
if primary_window.is_none() {
31+
// Primary window has been closed
32+
app_exit_events.send(AppExit);
4833
}
4934
}
5035

crates/bevy_winit/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Plugin for WinitPlugin {
6767
.with_system(update_cursor_position)
6868
.with_system(update_resize_constraints),
6969
)
70-
.add_system_to_stage(CoreStage::PostUpdate, despawn_window.after(ModifiesWindows));
70+
.add_system_to_stage(CoreStage::Last, despawn_window);
7171

7272
#[cfg(target_arch = "wasm32")]
7373
app.add_plugin(web_resize::CanvasParentResizePlugin);
@@ -591,9 +591,13 @@ pub fn winit_runner(mut app: App) {
591591
winit_state.active = true;
592592
}
593593
event::Event::MainEventsCleared => {
594-
let (commands, new_windows, winit_windows, winit_config, window_focused_query) =
594+
let (mut commands, new_windows, winit_windows, winit_config, window_focused_query) =
595595
create_window_system_state.get_mut(&mut app.world);
596596

597+
for (window, components) in &new_windows {
598+
commands.entity(window).insert(*components.state);
599+
}
600+
597601
// Responsible for creating new windows
598602
create_window(commands, event_loop, new_windows, winit_windows);
599603

crates/bevy_winit/src/system.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ pub fn update_window_state(
240240
winit_window.set_maximized(false);
241241
}
242242
WindowState::Maximized => {
243-
// should we call `set_minimized(false)` here?
244243
winit_window.set_maximized(true);
245244
}
246245
WindowState::Minimized => {

crates/bevy_winit/src/winit_windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl WinitWindows {
121121

122122
// I don't think we can do this immediately with some platforms.
123123
if components.state.minimized() {
124-
//winit_window.set_minimized(true);
124+
winit_window.set_minimized(true);
125125
}
126126

127127
self.window_id_to_winit.insert(entity, winit_window.id());

0 commit comments

Comments
 (0)