diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 8be97fc8082cc..dd45ea452b8b6 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -31,6 +31,7 @@ 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; @@ -38,6 +39,7 @@ 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 @@ -111,6 +113,7 @@ impl Plugin for WinitPlugin { } app.init_non_send_resource::() + .init_resource::() .init_resource::() .add_event::() .set_runner(winit_runner::) @@ -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>); diff --git a/crates/bevy_winit/src/state.rs b/crates/bevy_winit/src/state.rs index df0aab42dec31..401c2fc82c5b4 100644 --- a/crates/bevy_winit/src/state.rs +++ b/crates/bevy_winit/src/state.rs @@ -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 @@ -371,10 +371,13 @@ impl ApplicationHandler for WinitAppRunnerState { } fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) { + let mut create_monitor = SystemState::::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::>>::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()); diff --git a/crates/bevy_winit/src/system.rs b/crates/bevy_winit/src/system.rs index 822fe5b93cb8f..1b3a29bc25b14 100644 --- a/crates/bevy_winit/src/system.rs +++ b/crates/bevy_winit/src/system.rs @@ -108,7 +108,7 @@ pub fn create_windows( } pub fn create_monitors( - event_loop: &EventLoopWindowTarget, + event_loop: &ActiveEventLoop, (mut commands, mut monitors): SystemParamItem, ) { let primary_monitor = event_loop.primary_monitor(); diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index 640303f2f1636..fdbbb474ff9be 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -49,6 +49,7 @@ impl WinitWindows { adapters: &mut AccessKitAdapters, handlers: &mut WinitActionRequestHandlers, accessibility_requested: &AccessibilityRequested, + monitors: &WinitMonitors, ) -> &WindowWrapper { let mut winit_window_attributes = WinitWindow::default_attributes();