Skip to content

Commit

Permalink
Rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Jun 4, 2024
1 parent 3e1378d commit 29458b4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ pub use winit_windows::*;

use crate::accessibility::{AccessKitAdapters, AccessKitPlugin, WinitActionRequestHandlers};
use crate::state::winit_runner;
use crate::winit_monitors::WinitMonitors;

pub mod accessibility;
mod converters;
mod state;
mod system;
mod winit_config;
pub mod winit_event;
mod winit_monitors;
mod winit_windows;

/// [`AndroidApp`] provides an interface to query the application state as well as monitor events
Expand Down Expand Up @@ -111,6 +113,7 @@ impl<T: Event> Plugin for WinitPlugin<T> {
}

app.init_non_send_resource::<WinitWindows>()
.init_resource::<WinitMonitors>()
.init_resource::<WinitSettings>()
.add_event::<WinitEvent>()
.set_runner(winit_runner::<T>)
Expand Down Expand Up @@ -177,4 +180,8 @@ pub type CreateWindowParams<'w, 's, F = ()> = (
NonSendMut<'w, AccessKitAdapters>,
ResMut<'w, WinitActionRequestHandlers>,
Res<'w, AccessibilityRequested>,
Res<'w, WinitMonitors>,
);

/// The parameters of the [`create_monitors`] system.
pub type CreateMonitorParams<'w, 's> = (Commands<'w, 's>, ResMut<'w, WinitMonitors>);
9 changes: 6 additions & 3 deletions crates/bevy_winit/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ use bevy_window::{
use bevy_window::{PrimaryWindow, RawHandleWrapper};

use crate::accessibility::AccessKitAdapters;
use crate::system::CachedWindow;
use crate::system::{create_monitors, CachedWindow};
use crate::{
converters, create_windows, AppSendEvent, CreateWindowParams, UpdateMode, WinitEvent,
WinitSettings, WinitWindows,
converters, create_windows, AppSendEvent, CreateMonitorParams, CreateWindowParams, UpdateMode,
WinitEvent, WinitSettings, WinitWindows,
};

/// Persistent state that is used to run the [`App`] according to the current
Expand Down Expand Up @@ -371,10 +371,13 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> {
}

fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
let mut create_monitor = SystemState::<CreateMonitorParams>::from_world(self.world_mut());
// create any new windows
// (even if app did not update, some may have been created by plugin setup)
let mut create_window =
SystemState::<CreateWindowParams<Added<Window>>>::from_world(self.world_mut());
create_monitors(event_loop, create_monitor.get_mut(self.world_mut()));
create_monitor.apply(self.world_mut());
create_windows(event_loop, create_window.get_mut(self.world_mut()));
create_window.apply(self.world_mut());

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_winit/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn create_windows<F: QueryFilter + 'static>(
}

pub fn create_monitors(
event_loop: &EventLoopWindowTarget<crate::UserEvent>,
event_loop: &ActiveEventLoop,
(mut commands, mut monitors): SystemParamItem<CreateMonitorParams>,
) {
let primary_monitor = event_loop.primary_monitor();
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl WinitWindows {
adapters: &mut AccessKitAdapters,
handlers: &mut WinitActionRequestHandlers,
accessibility_requested: &AccessibilityRequested,
monitors: &WinitMonitors,
) -> &WindowWrapper<WinitWindow> {
let mut winit_window_attributes = WinitWindow::default_attributes();

Expand Down

0 comments on commit 29458b4

Please sign in to comment.