Skip to content

Commit fae61ad

Browse files
committed
create window as soon as possible (#7668)
# Objective - Fixes #7612 - Since #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
1 parent e950b1e commit fae61ad

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

crates/bevy_winit/src/lib.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -288,34 +288,6 @@ pub fn winit_runner(mut app: App) {
288288
}
289289
}
290290

291-
if winit_state.active {
292-
#[cfg(not(target_arch = "wasm32"))]
293-
let (commands, mut new_windows, created_window_writer, winit_windows) =
294-
create_window_system_state.get_mut(&mut app.world);
295-
296-
#[cfg(target_arch = "wasm32")]
297-
let (
298-
commands,
299-
mut new_windows,
300-
created_window_writer,
301-
winit_windows,
302-
canvas_parent_resize_channel,
303-
) = create_window_system_state.get_mut(&mut app.world);
304-
305-
// Responsible for creating new windows
306-
create_window(
307-
commands,
308-
event_loop,
309-
new_windows.iter_mut(),
310-
created_window_writer,
311-
winit_windows,
312-
#[cfg(target_arch = "wasm32")]
313-
canvas_parent_resize_channel,
314-
);
315-
316-
create_window_system_state.apply(&mut app.world);
317-
}
318-
319291
match event {
320292
event::Event::NewEvents(start) => {
321293
let (winit_config, window_focused_query) = focused_window_state.get(&app.world);
@@ -671,6 +643,34 @@ pub fn winit_runner(mut app: App) {
671643

672644
_ => (),
673645
}
646+
647+
if winit_state.active {
648+
#[cfg(not(target_arch = "wasm32"))]
649+
let (commands, mut new_windows, created_window_writer, winit_windows) =
650+
create_window_system_state.get_mut(&mut app.world);
651+
652+
#[cfg(target_arch = "wasm32")]
653+
let (
654+
commands,
655+
mut new_windows,
656+
created_window_writer,
657+
winit_windows,
658+
canvas_parent_resize_channel,
659+
) = create_window_system_state.get_mut(&mut app.world);
660+
661+
// Responsible for creating new windows
662+
create_window(
663+
commands,
664+
event_loop,
665+
new_windows.iter_mut(),
666+
created_window_writer,
667+
winit_windows,
668+
#[cfg(target_arch = "wasm32")]
669+
canvas_parent_resize_channel,
670+
);
671+
672+
create_window_system_state.apply(&mut app.world);
673+
}
674674
};
675675

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

0 commit comments

Comments
 (0)