Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor non-eventloop setup logic from WinitPlugin into WinitCorePlugin #12786

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,7 @@ impl Plugin for WinitPlugin {
event_loop_builder.with_android_app(ANDROID_APP.get().expect(msg).clone());
}

app.init_non_send_resource::<WinitWindows>()
.init_resource::<WinitSettings>()
.add_event::<WinitEvent>()
.set_runner(winit_runner)
.add_systems(
Last,
(
// `exit_on_all_closed` only checks if windows exist but doesn't access data,
// so we don't need to care about its ordering relative to `changed_windows`
changed_windows.ambiguous_with(exit_on_all_closed),
despawn_windows,
)
.chain(),
);

app.add_plugins(AccessKitPlugin);
app.add_plugins(WinitCorePlugin).set_runner(winit_runner);

let event_loop = event_loop_builder
.build()
Expand Down Expand Up @@ -169,6 +154,31 @@ impl Plugin for WinitPlugin {
}
}

/// A [`Plugin`] that adds systems and resources to sync with the `winit` backend.
///
/// This plugin does not set up a `winit` event loop. For full `winit` setup use [`WinitPlugin`].
pub struct WinitCorePlugin;

impl Plugin for WinitCorePlugin {
fn build(&self, app: &mut App) {
app.init_non_send_resource::<WinitWindows>()
.init_resource::<WinitSettings>()
.add_event::<WinitEvent>()
.add_systems(
Last,
(
// `exit_on_all_closed` only checks if windows exist but doesn't access data,
// so we don't need to care about its ordering relative to `changed_windows`
changed_windows.ambiguous_with(exit_on_all_closed),
despawn_windows,
)
.chain(),
);

app.add_plugins(AccessKitPlugin);
}
}

trait AppSendEvent {
fn send(&mut self, event: impl Into<WinitEvent>);
}
Expand Down