diff --git a/src/event.rs b/src/event.rs index 87f6943c..12e58e74 100644 --- a/src/event.rs +++ b/src/event.rs @@ -302,13 +302,12 @@ pub enum WindowEvent<'a> { /// /// After this event callback has been processed, the window will be resized to whatever value /// is pointed to by the `new_inner_size` reference. By default, this will contain the size suggested - /// by the OS, but it can be changed to any value. If `new_inner_size` is set to `None`, no resizing - /// will occur. + /// by the OS, but it can be changed to any value. /// /// For more information about DPI in general, see the [`dpi`](dpi/index.html) module. HiDpiFactorChanged { hidpi_factor: f64, - new_inner_size: &'a mut Option>, + new_inner_size: &'a mut PhysicalSize, }, /// The system window theme has changed. diff --git a/src/platform_impl/ios/app_state.rs b/src/platform_impl/ios/app_state.rs index e2950916..229e17d7 100644 --- a/src/platform_impl/ios/app_state.rs +++ b/src/platform_impl/ios/app_state.rs @@ -861,8 +861,8 @@ fn handle_hidpi_proxy( hidpi_factor: f64, window_id: id, ) { - let size = suggested_size.to_physical(hidpi_factor); - let new_inner_size = &mut Some(size); + let mut size = suggested_size.to_physical(hidpi_factor); + let new_inner_size = &mut size; let event = Event::WindowEvent { window_id: RootWindowId(window_id.into()), event: WindowEvent::HiDpiFactorChanged { @@ -872,13 +872,12 @@ fn handle_hidpi_proxy( }; event_handler.handle_nonuser_event(event, &mut control_flow); let (view, screen_frame) = get_view_and_screen_frame(window_id); - if let Some(physical_size) = new_inner_size { - let logical_size = physical_size.to_logical(hidpi_factor); - let size = CGSize::new(logical_size); - let new_frame: CGRect = CGRect::new(screen_frame.origin, size); - unsafe { - let () = msg_send![view, setFrame: new_frame]; - } + let physical_size = *new_inner_size; + let logical_size = physical_size.to_logical(hidpi_factor); + let size = CGSize::new(logical_size); + let new_frame: CGRect = CGRect::new(screen_frame.origin, size); + unsafe { + let () = msg_send![view, setFrame: new_frame]; } } diff --git a/src/platform_impl/linux/wayland/event_loop.rs b/src/platform_impl/linux/wayland/event_loop.rs index 72d78156..4eded253 100644 --- a/src/platform_impl/linux/wayland/event_loop.rs +++ b/src/platform_impl/linux/wayland/event_loop.rs @@ -730,7 +730,7 @@ impl EventLoop { if let Some(dpi) = window.new_dpi { let dpi = dpi as f64; let logical_size = LogicalSize::::from(*window.size); - let mut new_inner_size = Some(logical_size.to_physical(dpi)); + let mut new_inner_size = logical_size.to_physical(dpi); callback(Event::WindowEvent { window_id, @@ -740,11 +740,9 @@ impl EventLoop { }, }); - if let Some(new_size) = new_inner_size { - let (w, h) = new_size.to_logical::(dpi).into(); - frame.resize(w, h); - *window.size = (w, h); - } + let (w, h) = new_inner_size.to_logical::(dpi).into(); + frame.resize(w, h); + *window.size = (w, h); } } if window.closed { diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 33a5e149..9ce17f27 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -422,7 +422,8 @@ impl EventProcessor { height, ); - let mut new_inner_size = Some(PhysicalSize::new(new_width, new_height)); + let old_inner_size = PhysicalSize::new(width, height); + let mut new_inner_size = PhysicalSize::new(new_width, new_height); callback(Event::WindowEvent { window_id, @@ -432,9 +433,12 @@ impl EventProcessor { }, }); - if let Some(new_size) = new_inner_size { - window.set_inner_size_physical(new_size.width, new_size.height); - shared_state_lock.dpi_adjusted = Some(new_size.into()); + if new_inner_size != old_inner_size { + window.set_inner_size_physical( + new_inner_size.width, + new_inner_size.height, + ); + shared_state_lock.dpi_adjusted = Some(new_inner_size.into()); // if the DPI factor changed, force a resize event to ensure the logical // size is computed with the right DPI factor resized = true; @@ -1135,9 +1139,10 @@ impl EventProcessor { *window_id, ), ); - let mut new_inner_size = Some( - PhysicalSize::new(new_width, new_height), - ); + let old_inner_size = + PhysicalSize::new(width, height); + let mut new_inner_size = + PhysicalSize::new(new_width, new_height); callback(Event::WindowEvent { window_id, @@ -1147,9 +1152,9 @@ impl EventProcessor { }, }); - if let Some(new_size) = new_inner_size { + if new_inner_size != old_inner_size { let (new_width, new_height) = - new_size.into(); + new_inner_size.into(); window.set_inner_size_physical( new_width, new_height, ); diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index 7d6b92b2..a60d6861 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -188,8 +188,8 @@ impl Handler { suggested_size: LogicalSize, hidpi_factor: f64, ) { - let size = suggested_size.to_physical(hidpi_factor); - let new_inner_size = &mut Some(size); + let mut size = suggested_size.to_physical(hidpi_factor); + let new_inner_size = &mut size; let event = Event::WindowEvent { window_id: WindowId(get_window_id(*ns_window)), event: WindowEvent::HiDpiFactorChanged { @@ -200,7 +200,7 @@ impl Handler { callback.handle_nonuser_event(event, &mut *self.control_flow.lock().unwrap()); - let physical_size = new_inner_size.unwrap_or(size); + let physical_size = *new_inner_size; let logical_size = physical_size.to_logical(hidpi_factor); let size = NSSize::new(logical_size.width, logical_size.height); unsafe { NSWindow::setContentSize_(*ns_window, size) }; diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 7783c679..ebcabcef 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -1486,27 +1486,25 @@ unsafe extern "system" fn public_window_callback( (old_physical_inner_rect.bottom - old_physical_inner_rect.top) as u32, ); - // We calculate our own size because the default suggested rect doesn't do a great job - // of preserving the window's logical size. - let suggested_physical_inner_size = old_physical_inner_size - .to_logical::(old_dpi_factor) - .to_physical::(new_dpi_factor); - // `allow_resize` prevents us from re-applying DPI adjustment to the restored size after // exiting fullscreen (the restored size is already DPI adjusted). - let mut new_inner_size_opt = - Some(suggested_physical_inner_size).filter(|_| allow_resize); + let mut new_physical_inner_size = match allow_resize { + // We calculate our own size because the default suggested rect doesn't do a great job + // of preserving the window's logical size. + true => old_physical_inner_size + .to_logical::(old_dpi_factor) + .to_physical::(new_dpi_factor), + false => old_physical_inner_size, + }; let _ = subclass_input.send_event_unbuffered(Event::WindowEvent { window_id: RootWindowId(WindowId(window)), event: HiDpiFactorChanged { hidpi_factor: new_dpi_factor, - new_inner_size: &mut new_inner_size_opt, + new_inner_size: &mut new_physical_inner_size, }, }); - let new_physical_inner_size = new_inner_size_opt.unwrap_or(old_physical_inner_size); - // Unset maximized if we're changing the window's size. if new_physical_inner_size != old_physical_inner_size { WindowState::set_window_flags(subclass_input.window_state.lock(), window, |f| {