-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
It looks like this sends an event but doesn't actually change anything in the app. Are additional changes needed to fix the text issues (follow-up PR?)? |
Good question. Basically the situation is the following:
Window creation log may be printed after first frame (F0), so on Retina display it may be situation that Frame 1: scale has default value 1 BUT I am not sure that this is a proper fix, another option is to revert PR#9826... or maybe someone more familiar with the engine internals has better idea how to tackle this issue. |
Hmm this reminds me of another MacOS issue: #8391. It seems like winit events are not sent in some circumstances. Honestly the execution flow around I am concerned this PR may only be a bandaid on a much bigger problem - how many other window events are not being processed correctly? Also, does this PR need to take into account the other stuff going on here? WindowEvent::ScaleFactorChanged {
scale_factor,
new_inner_size,
} => {
event_writers.window_backend_scale_factor_changed.send(
WindowBackendScaleFactorChanged {
window: window_entity,
scale_factor,
},
);
let prior_factor = window.resolution.scale_factor();
window.resolution.set_scale_factor(scale_factor);
let new_factor = window.resolution.scale_factor();
if let Some(forced_factor) = window.resolution.scale_factor_override() {
// This window is overriding the OS-suggested DPI, so its physical size
// should be set based on the overriding value. Its logical size already
// incorporates any resize constraints.
*new_inner_size =
winit::dpi::LogicalSize::new(window.width(), window.height())
.to_physical::<u32>(forced_factor);
} else if approx::relative_ne!(new_factor, prior_factor) {
event_writers.window_scale_factor_changed.send(
WindowScaleFactorChanged {
window: window_entity,
scale_factor,
},
);
}
let new_logical_width = (new_inner_size.width as f64 / new_factor) as f32;
let new_logical_height = (new_inner_size.height as f64 / new_factor) as f32;
if approx::relative_ne!(window.width(), new_logical_width)
|| approx::relative_ne!(window.height(), new_logical_height)
{
event_writers.window_resized.send(WindowResized {
window: window_entity,
width: new_logical_width,
height: new_logical_height,
});
}
window
.resolution
.set_physical_resolution(new_inner_size.width, new_inner_size.height);
} |
@devil-ira, I would appreciate your input here as well if you have opinions. |
@alice-i-cecile according to this comment it was not fixed by #10389 @rparrett. |
These changes seem basically fine to me as a robustness improvement / workaround, but I'd like to verify that we can reproduce the problem before merging. |
@UkoeHB in this case it's another situation, smt like:
the current fix is basically
|
Tested just now on the latest main (33cd59f). Issue still occurs for me. |
My question is, where is the scale changing so that a winit event used to be emitted but now is not emitted? Are there other winit events that are not being emitted because the window creation is delayed? What about all that other logic that |
As far as I understand the code (may be wrong) before user could read in setup system window scale and that value was "not default one" but from winit (2 for Retina display) (because window was created before setup system run)... so in the previous version of code we don't need to fire bevy's window scale event change... because it's always 2 for a Retina user :) I am not sure about that invariant... code changes seems work fine for me but surely more testing is appreciated. It just sounds logical to me if we had scale 1 we have to send scale change event if scale is 2... better option would be to properly fix it and create window as it was before.. before the first frame. |
I believe this is not the right fix. with this, text will be rendered once without the proper scale, then once more with it. With #9826 or #10389, there is still an I think instead we should investigate on each platform where the proper step to create windows should be, and ensure it's correctly place relative to the update |
@mockersf yep, completely agree that the proper fix is to move window creation back as it was in 0.11 for MacOS. |
@mockersf what do you think about running recently introduced |
Objective
Fixes #10407
I guess this is not a proper fix but more like a workaround, just sharing maybe someone will come up with better idea...
Solution
WindowScaleFactorChanged
is fired on window creation, allowing to refresh window scale.