Skip to content

Commit 5051a56

Browse files
committed
Add an alternative winit runner that can be started when not on the main thread
1 parent e511cdb commit 5051a56

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

crates/bevy_winit/src/lib.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ use winit::{
2222
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
2323
};
2424

25+
#[cfg(any(
26+
target_os = "linux",
27+
target_os = "dragonfly",
28+
target_os = "freebsd",
29+
target_os = "netbsd",
30+
target_os = "openbsd"
31+
))]
32+
use winit::platform::unix::EventLoopExtUnix;
33+
2534
#[derive(Default)]
2635
pub struct WinitPlugin;
2736

@@ -158,8 +167,24 @@ where
158167
panic!("Run return is not supported on this platform!")
159168
}
160169

161-
pub fn winit_runner(mut app: App) {
162-
let mut event_loop = EventLoop::new();
170+
pub fn winit_runner(app: App)
171+
{
172+
winit_runner_with(app, EventLoop::new());
173+
}
174+
175+
#[cfg(any(
176+
target_os = "linux",
177+
target_os = "dragonfly",
178+
target_os = "freebsd",
179+
target_os = "netbsd",
180+
target_os = "openbsd"
181+
))]
182+
pub fn winit_runner_any_thread(app: App)
183+
{
184+
winit_runner_with(app, EventLoop::new_any_thread());
185+
}
186+
187+
pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop::<()>) {
163188
let mut create_window_event_reader = EventReader::<CreateWindow>::default();
164189
let mut app_exit_event_reader = EventReader::<AppExit>::default();
165190

0 commit comments

Comments
 (0)