diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 91c9858c79293..7e08e8646fde5 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -165,6 +165,7 @@ impl Plugin for WinitPlugin { Commands, Query<(Entity, &mut Window)>, EventWriter, + EventWriter, NonSendMut, NonSendMut, ResMut, @@ -176,6 +177,7 @@ impl Plugin for WinitPlugin { Commands, Query<(Entity, &mut Window)>, EventWriter, + EventWriter, NonSendMut, NonSendMut, ResMut, @@ -187,7 +189,8 @@ impl Plugin for WinitPlugin { let ( commands, mut windows, - event_writer, + event_writer_window, + event_writer_scale_factor, winit_windows, adapters, handlers, @@ -198,7 +201,8 @@ impl Plugin for WinitPlugin { let ( commands, mut windows, - event_writer, + event_writer_window, + event_writer_scale_factor, winit_windows, adapters, handlers, @@ -210,7 +214,8 @@ impl Plugin for WinitPlugin { &event_loop, commands, windows.iter_mut(), - event_writer, + event_writer_window, + event_writer_scale_factor, winit_windows, adapters, handlers, @@ -380,6 +385,7 @@ pub fn winit_runner(mut app: App) { Commands, Query<(Entity, &mut Window), Added>, EventWriter, + EventWriter, NonSendMut, NonSendMut, ResMut, @@ -391,6 +397,7 @@ pub fn winit_runner(mut app: App) { Commands, Query<(Entity, &mut Window), Added>, EventWriter, + EventWriter, NonSendMut, NonSendMut, ResMut, @@ -431,7 +438,8 @@ pub fn winit_runner(mut app: App) { let ( commands, mut windows, - event_writer, + event_writer_window, + event_writer_scale_factor, winit_windows, adapters, handlers, @@ -454,7 +462,8 @@ pub fn winit_runner(mut app: App) { event_loop, commands, windows.iter_mut(), - event_writer, + event_writer_window, + event_writer_scale_factor, winit_windows, adapters, handlers, @@ -869,7 +878,8 @@ pub fn winit_runner(mut app: App) { let ( commands, mut windows, - event_writer, + event_writer_window, + event_writer_scale_factor, winit_windows, adapters, handlers, @@ -880,7 +890,8 @@ pub fn winit_runner(mut app: App) { let ( commands, mut windows, - event_writer, + event_writer_window, + event_writer_scale_factor, winit_windows, adapters, handlers, @@ -892,7 +903,8 @@ pub fn winit_runner(mut app: App) { event_loop, commands, windows.iter_mut(), - event_writer, + event_writer_window, + event_writer_scale_factor, winit_windows, adapters, handlers, diff --git a/crates/bevy_winit/src/system.rs b/crates/bevy_winit/src/system.rs index 896466f3c7073..046532ef2f273 100644 --- a/crates/bevy_winit/src/system.rs +++ b/crates/bevy_winit/src/system.rs @@ -11,7 +11,9 @@ use bevy_utils::{ tracing::{error, info, warn}, HashMap, }; -use bevy_window::{RawHandleWrapper, Window, WindowClosed, WindowCreated}; +use bevy_window::{ + RawHandleWrapper, Window, WindowClosed, WindowCreated, WindowScaleFactorChanged, +}; use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; use winit::{ @@ -40,7 +42,8 @@ pub(crate) fn create_windows<'a>( event_loop: &EventLoopWindowTarget<()>, mut commands: Commands, created_windows: impl Iterator)>, - mut event_writer: EventWriter, + mut event_writer_window: EventWriter, + mut event_writer_scale_factor: EventWriter, mut winit_windows: NonSendMut, mut adapters: NonSendMut, mut handlers: ResMut, @@ -71,6 +74,13 @@ pub(crate) fn create_windows<'a>( window.window_theme = Some(convert_winit_theme(theme)); } + if window.resolution.scale_factor() != winit_window.scale_factor() { + event_writer_scale_factor.send(WindowScaleFactorChanged { + window: entity, + scale_factor: winit_window.scale_factor(), + }); + } + window .resolution .set_scale_factor(winit_window.scale_factor()); @@ -96,7 +106,7 @@ pub(crate) fn create_windows<'a>( } } - event_writer.send(WindowCreated { window: entity }); + event_writer_window.send(WindowCreated { window: entity }); } }