Skip to content

Commit

Permalink
create window as soon as possible (bevyengine#7668)
Browse files Browse the repository at this point in the history
# Objective

- Fixes bevyengine#7612 
- Since bevyengine#7493, windows started as unfocused

## Solution

- Creating the window at the end of the event loop after the resume event instead of at the beginning of the loop of the next event fixes the focus
  • Loading branch information
mockersf authored and myreprise1 committed Feb 15, 2023
1 parent c136dbd commit abc2760
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,34 +288,6 @@ pub fn winit_runner(mut app: App) {
}
}

if winit_state.active {
#[cfg(not(target_arch = "wasm32"))]
let (commands, mut new_windows, created_window_writer, winit_windows) =
create_window_system_state.get_mut(&mut app.world);

#[cfg(target_arch = "wasm32")]
let (
commands,
mut new_windows,
created_window_writer,
winit_windows,
canvas_parent_resize_channel,
) = create_window_system_state.get_mut(&mut app.world);

// Responsible for creating new windows
create_window(
commands,
event_loop,
new_windows.iter_mut(),
created_window_writer,
winit_windows,
#[cfg(target_arch = "wasm32")]
canvas_parent_resize_channel,
);

create_window_system_state.apply(&mut app.world);
}

match event {
event::Event::NewEvents(start) => {
let (winit_config, window_focused_query) = focused_window_state.get(&app.world);
Expand Down Expand Up @@ -671,6 +643,34 @@ pub fn winit_runner(mut app: App) {

_ => (),
}

if winit_state.active {
#[cfg(not(target_arch = "wasm32"))]
let (commands, mut new_windows, created_window_writer, winit_windows) =
create_window_system_state.get_mut(&mut app.world);

#[cfg(target_arch = "wasm32")]
let (
commands,
mut new_windows,
created_window_writer,
winit_windows,
canvas_parent_resize_channel,
) = create_window_system_state.get_mut(&mut app.world);

// Responsible for creating new windows
create_window(
commands,
event_loop,
new_windows.iter_mut(),
created_window_writer,
winit_windows,
#[cfg(target_arch = "wasm32")]
canvas_parent_resize_channel,
);

create_window_system_state.apply(&mut app.world);
}
};

// If true, returns control from Winit back to the main Bevy loop
Expand Down

0 comments on commit abc2760

Please sign in to comment.