Skip to content

Commit 77076bc

Browse files
committed
Simplify primary window closed system
1 parent af3206a commit 77076bc

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
@@ -69,7 +69,7 @@ impl Plugin for WinitPlugin {
6969
.with_system(update_cursor_position)
7070
.with_system(update_resize_constraints),
7171
)
72-
.add_system_to_stage(CoreStage::PostUpdate, despawn_window.after(ModifiesWindows));
72+
.add_system_to_stage(CoreStage::Last, despawn_window);
7373

7474
#[cfg(target_arch = "wasm32")]
7575
app.add_plugin(web_resize::CanvasParentResizePlugin);
@@ -600,9 +600,13 @@ pub fn winit_runner(mut app: App) {
600600
winit_state.active = true;
601601
}
602602
event::Event::MainEventsCleared => {
603-
let (commands, new_windows, winit_windows, winit_config, window_focused_query) =
603+
let (mut commands, new_windows, winit_windows, winit_config, window_focused_query) =
604604
create_window_system_state.get_mut(&mut app.world);
605605

606+
for (window, components) in &new_windows {
607+
commands.entity(window).insert(*components.state);
608+
}
609+
606610
// Responsible for creating new windows
607611
create_window(commands, event_loop, new_windows, winit_windows);
608612

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
@@ -125,7 +125,7 @@ impl WinitWindows {
125125

126126
// I don't think we can do this immediately with some platforms.
127127
if components.state.minimized() {
128-
//winit_window.set_minimized(true);
128+
winit_window.set_minimized(true);
129129
}
130130

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

0 commit comments

Comments
 (0)