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

Update window scale on window creation #10554

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
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
28 changes: 20 additions & 8 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl Plugin for WinitPlugin {
Commands,
Query<(Entity, &mut Window)>,
EventWriter<WindowCreated>,
EventWriter<WindowScaleFactorChanged>,
NonSendMut<WinitWindows>,
NonSendMut<AccessKitAdapters>,
ResMut<WinitActionHandlers>,
Expand All @@ -176,6 +177,7 @@ impl Plugin for WinitPlugin {
Commands,
Query<(Entity, &mut Window)>,
EventWriter<WindowCreated>,
EventWriter<WindowScaleFactorChanged>,
NonSendMut<WinitWindows>,
NonSendMut<AccessKitAdapters>,
ResMut<WinitActionHandlers>,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -380,6 +385,7 @@ pub fn winit_runner(mut app: App) {
Commands,
Query<(Entity, &mut Window), Added<Window>>,
EventWriter<WindowCreated>,
EventWriter<WindowScaleFactorChanged>,
NonSendMut<WinitWindows>,
NonSendMut<AccessKitAdapters>,
ResMut<WinitActionHandlers>,
Expand All @@ -391,6 +397,7 @@ pub fn winit_runner(mut app: App) {
Commands,
Query<(Entity, &mut Window), Added<Window>>,
EventWriter<WindowCreated>,
EventWriter<WindowScaleFactorChanged>,
NonSendMut<WinitWindows>,
NonSendMut<AccessKitAdapters>,
ResMut<WinitActionHandlers>,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions crates/bevy_winit/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -40,7 +42,8 @@ pub(crate) fn create_windows<'a>(
event_loop: &EventLoopWindowTarget<()>,
mut commands: Commands,
created_windows: impl Iterator<Item = (Entity, Mut<'a, Window>)>,
mut event_writer: EventWriter<WindowCreated>,
mut event_writer_window: EventWriter<WindowCreated>,
mut event_writer_scale_factor: EventWriter<WindowScaleFactorChanged>,
mut winit_windows: NonSendMut<WinitWindows>,
mut adapters: NonSendMut<AccessKitAdapters>,
mut handlers: ResMut<WinitActionHandlers>,
Expand Down Expand Up @@ -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());
Expand All @@ -96,7 +106,7 @@ pub(crate) fn create_windows<'a>(
}
}

event_writer.send(WindowCreated { window: entity });
event_writer_window.send(WindowCreated { window: entity });
}
}

Expand Down