From 0f044bb416aa97e8cf260a73e8c68338d90d6241 Mon Sep 17 00:00:00 2001 From: Aceeri Date: Thu, 11 Aug 2022 15:20:53 -0700 Subject: [PATCH] Simplify primary window closed system --- crates/bevy_window/src/system.rs | 21 +++------------------ crates/bevy_winit/src/lib.rs | 8 ++++++-- crates/bevy_winit/src/system.rs | 1 - crates/bevy_winit/src/winit_windows.rs | 2 +- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/crates/bevy_window/src/system.rs b/crates/bevy_window/src/system.rs index 8dac5e4cb2ac4..e29cf48bf7953 100644 --- a/crates/bevy_window/src/system.rs +++ b/crates/bevy_window/src/system.rs @@ -3,7 +3,6 @@ use crate::{PrimaryWindow, Window, WindowCloseRequested, WindowClosed, WindowFoc use bevy_app::AppExit; use bevy_ecs::prelude::*; use bevy_input::{keyboard::KeyCode, Input}; -use bevy_utils::tracing::warn; /// Exit the application when there are no open windows. /// @@ -27,24 +26,10 @@ pub fn exit_on_all_closed(mut app_exit_events: EventWriter, windows: Qu pub fn exit_on_primary_closed( mut app_exit_events: EventWriter, primary_window: Option>, - mut window_close: EventReader, ) { - match primary_window.as_ref() { - Some(primary_window) => { - for window in window_close.iter() { - warn!( - "primary_window: {:?}, closed: {:?}", - primary_window.window, window.window - ); - if primary_window.window == window.window { - // Primary window has been closed - app_exit_events.send(AppExit); - } - } - } - None => { - app_exit_events.send(AppExit); - } + if primary_window.is_none() { + // Primary window has been closed + app_exit_events.send(AppExit); } } diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 75b8d17e7aa75..a584201fa537e 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -67,7 +67,7 @@ impl Plugin for WinitPlugin { .with_system(update_cursor_position) .with_system(update_resize_constraints), ) - .add_system_to_stage(CoreStage::PostUpdate, despawn_window.after(ModifiesWindows)); + .add_system_to_stage(CoreStage::Last, despawn_window); #[cfg(target_arch = "wasm32")] app.add_plugin(web_resize::CanvasParentResizePlugin); @@ -591,9 +591,13 @@ pub fn winit_runner(mut app: App) { winit_state.active = true; } event::Event::MainEventsCleared => { - let (commands, new_windows, winit_windows, winit_config, window_focused_query) = + let (mut commands, new_windows, winit_windows, winit_config, window_focused_query) = create_window_system_state.get_mut(&mut app.world); + for (window, components) in &new_windows { + commands.entity(window).insert(*components.state); + } + // Responsible for creating new windows create_window(commands, event_loop, new_windows, winit_windows); diff --git a/crates/bevy_winit/src/system.rs b/crates/bevy_winit/src/system.rs index e0b812791ba34..41d7b7adec55b 100644 --- a/crates/bevy_winit/src/system.rs +++ b/crates/bevy_winit/src/system.rs @@ -240,7 +240,6 @@ pub fn update_window_state( winit_window.set_maximized(false); } WindowState::Maximized => { - // should we call `set_minimized(false)` here? winit_window.set_maximized(true); } WindowState::Minimized => { diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index 30d342e6721f6..3e97a7224c845 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -121,7 +121,7 @@ impl WinitWindows { // I don't think we can do this immediately with some platforms. if components.state.minimized() { - //winit_window.set_minimized(true); + winit_window.set_minimized(true); } self.window_id_to_winit.insert(entity, winit_window.id());