Skip to content

Commit

Permalink
Simplify primary window closed system
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceeri committed Aug 11, 2022
1 parent 08daf4b commit 0f044bb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
21 changes: 3 additions & 18 deletions crates/bevy_window/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -27,24 +26,10 @@ pub fn exit_on_all_closed(mut app_exit_events: EventWriter<AppExit>, windows: Qu
pub fn exit_on_primary_closed(
mut app_exit_events: EventWriter<AppExit>,
primary_window: Option<Res<PrimaryWindow>>,
mut window_close: EventReader<WindowClosed>,
) {
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);
}
}

Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion crates/bevy_winit/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 0f044bb

Please sign in to comment.