Use correct canvas size for scale factor change

This commit is contained in:
dAxpeDDa 2023-06-04 14:29:59 +02:00 committed by daxpedda
parent 8f7f3efc0d
commit c88a4ab221
7 changed files with 69 additions and 52 deletions

View file

@ -327,16 +327,14 @@ impl<T: 'static> Shared<T> {
// Now handle the `ScaleFactorChanged` events.
for &(id, ref canvas) in &*self.0.all_canvases.borrow() {
let canvas = match canvas.upgrade() {
Some(rc) => rc.borrow().raw().clone(),
let rc = match canvas.upgrade() {
Some(rc) => rc,
// This shouldn't happen, but just in case...
None => continue,
};
let canvas = rc.borrow();
// First, we send the `ScaleFactorChanged` event:
let current_size = crate::dpi::PhysicalSize {
width: canvas.width(),
height: canvas.height(),
};
let current_size = canvas.size().get();
let logical_size = current_size.to_logical::<f64>(old_scale);
let mut new_size = logical_size.to_physical(new_scale);
self.handle_single_event_sync(
@ -351,7 +349,7 @@ impl<T: 'static> Shared<T> {
);
// Then we resize the canvas to the new size and send a `Resized` event:
backend::set_canvas_size(self.window(), &canvas, crate::dpi::Size::Physical(new_size));
backend::set_canvas_size(&canvas, crate::dpi::Size::Physical(new_size));
self.handle_single_event_sync(
Event::WindowEvent {
window_id: id,

View file

@ -16,7 +16,7 @@ use super::{
runner,
window::WindowId,
};
use crate::dpi::{PhysicalSize, Size};
use crate::dpi::Size;
use crate::event::{
DeviceEvent, DeviceId as RootDeviceId, ElementState, Event, KeyEvent, Touch, TouchPhase,
WindowEvent,
@ -89,6 +89,7 @@ impl<T> EventLoopWindowTarget<T> {
has_focus: Arc<AtomicBool>,
) {
self.runner.add_canvas(RootWindowId(id), canvas);
let canvas_clone = canvas.clone();
let mut canvas = canvas.borrow_mut();
canvas.set_attribute("data-raw-handle", &id.0.to_string());
@ -502,32 +503,27 @@ impl<T> EventLoopWindowTarget<T> {
prevent_default,
);
let runner = self.runner.clone();
let raw = canvas.raw().clone();
// The size to restore to after exiting fullscreen.
let mut intended_size = PhysicalSize {
width: raw.width(),
height: raw.height(),
};
let mut intended_size = canvas.size().get();
canvas.on_fullscreen_change({
let window = self.runner.window().clone();
let runner = self.runner.clone();
move || {
let canvas = canvas_clone.borrow();
// If the canvas is marked as fullscreen, it is moving *into* fullscreen
// If it is not, it is moving *out of* fullscreen
let new_size = if backend::is_fullscreen(&window, &raw) {
intended_size = PhysicalSize {
width: raw.width(),
height: raw.height(),
};
let new_size = if backend::is_fullscreen(&window, canvas.raw()) {
intended_size = canvas.size().get();
backend::window_size(&window).to_physical(backend::scale_factor(&window))
} else {
intended_size
};
backend::set_canvas_size(&window, &raw, Size::Physical(new_size));
backend::set_canvas_size(&canvas, Size::Physical(new_size));
runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::Resized(new_size),