From f0093d3c54b3e03a154c14f24555ed7df1c166e7 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Thu, 13 Feb 2020 20:41:41 +0100 Subject: [PATCH] rename dpi_factor to scale_factor where appropriate (#1463) fixes https://github.com/rust-windowing/winit/issues/1457 --- src/dpi.rs | 71 +++++++++++----------- src/platform_impl/android/mod.rs | 12 ++-- src/platform_impl/ios/view.rs | 16 ++--- src/platform_impl/ios/window.rs | 28 ++++----- src/platform_impl/linux/x11/window.rs | 36 +++++------ src/platform_impl/macos/window.rs | 50 +++++++-------- src/platform_impl/macos/window_delegate.rs | 8 +-- src/platform_impl/windows/event_loop.rs | 20 +++--- src/platform_impl/windows/window.rs | 20 +++--- src/platform_impl/windows/window_state.rs | 8 +-- 10 files changed, 136 insertions(+), 133 deletions(-) diff --git a/src/dpi.rs b/src/dpi.rs index 2057d012..8a56ae6e 100644 --- a/src/dpi.rs +++ b/src/dpi.rs @@ -151,8 +151,8 @@ impl Pixel for f64 { /// anywhere other than winit, it's recommended to validate them using this function before passing them to winit; /// otherwise, you risk panics. #[inline] -pub fn validate_scale_factor(dpi_factor: f64) -> bool { - dpi_factor.is_sign_positive() && dpi_factor.is_normal() +pub fn validate_scale_factor(scale_factor: f64) -> bool { + scale_factor.is_sign_positive() && scale_factor.is_normal() } /// A position represented in logical pixels. @@ -178,16 +178,16 @@ impl LogicalPosition

{ #[inline] pub fn from_physical>, X: Pixel>( physical: T, - dpi_factor: f64, + scale_factor: f64, ) -> Self { - physical.into().to_logical(dpi_factor) + physical.into().to_logical(scale_factor) } #[inline] - pub fn to_physical(&self, dpi_factor: f64) -> PhysicalPosition { - assert!(validate_scale_factor(dpi_factor)); - let x = self.x.into() * dpi_factor; - let y = self.y.into() * dpi_factor; + pub fn to_physical(&self, scale_factor: f64) -> PhysicalPosition { + assert!(validate_scale_factor(scale_factor)); + let x = self.x.into() * scale_factor; + let y = self.y.into() * scale_factor; PhysicalPosition::new(x, y).cast() } @@ -243,16 +243,16 @@ impl PhysicalPosition

{ #[inline] pub fn from_logical>, X: Pixel>( logical: T, - dpi_factor: f64, + scale_factor: f64, ) -> Self { - logical.into().to_physical(dpi_factor) + logical.into().to_physical(scale_factor) } #[inline] - pub fn to_logical(&self, dpi_factor: f64) -> LogicalPosition { - assert!(validate_scale_factor(dpi_factor)); - let x = self.x.into() / dpi_factor; - let y = self.y.into() / dpi_factor; + pub fn to_logical(&self, scale_factor: f64) -> LogicalPosition { + assert!(validate_scale_factor(scale_factor)); + let x = self.x.into() / scale_factor; + let y = self.y.into() / scale_factor; LogicalPosition::new(x, y).cast() } @@ -306,15 +306,18 @@ impl

LogicalSize

{ impl LogicalSize

{ #[inline] - pub fn from_physical>, X: Pixel>(physical: T, dpi_factor: f64) -> Self { - physical.into().to_logical(dpi_factor) + pub fn from_physical>, X: Pixel>( + physical: T, + scale_factor: f64, + ) -> Self { + physical.into().to_logical(scale_factor) } #[inline] - pub fn to_physical(&self, dpi_factor: f64) -> PhysicalSize { - assert!(validate_scale_factor(dpi_factor)); - let width = self.width.into() * dpi_factor; - let height = self.height.into() * dpi_factor; + pub fn to_physical(&self, scale_factor: f64) -> PhysicalSize { + assert!(validate_scale_factor(scale_factor)); + let width = self.width.into() * scale_factor; + let height = self.height.into() * scale_factor; PhysicalSize::new(width, height).cast() } @@ -368,15 +371,15 @@ impl

PhysicalSize

{ impl PhysicalSize

{ #[inline] - pub fn from_logical>, X: Pixel>(logical: T, dpi_factor: f64) -> Self { - logical.into().to_physical(dpi_factor) + pub fn from_logical>, X: Pixel>(logical: T, scale_factor: f64) -> Self { + logical.into().to_physical(scale_factor) } #[inline] - pub fn to_logical(&self, dpi_factor: f64) -> LogicalSize { - assert!(validate_scale_factor(dpi_factor)); - let width = self.width.into() / dpi_factor; - let height = self.height.into() / dpi_factor; + pub fn to_logical(&self, scale_factor: f64) -> LogicalSize { + assert!(validate_scale_factor(scale_factor)); + let width = self.width.into() / scale_factor; + let height = self.height.into() / scale_factor; LogicalSize::new(width, height).cast() } @@ -426,17 +429,17 @@ impl Size { size.into() } - pub fn to_logical(&self, dpi_factor: f64) -> LogicalSize

{ + pub fn to_logical(&self, scale_factor: f64) -> LogicalSize

{ match *self { - Size::Physical(size) => size.to_logical(dpi_factor), + Size::Physical(size) => size.to_logical(scale_factor), Size::Logical(size) => size.cast(), } } - pub fn to_physical(&self, dpi_factor: f64) -> PhysicalSize

{ + pub fn to_physical(&self, scale_factor: f64) -> PhysicalSize

{ match *self { Size::Physical(size) => size.cast(), - Size::Logical(size) => size.to_physical(dpi_factor), + Size::Logical(size) => size.to_physical(scale_factor), } } } @@ -468,17 +471,17 @@ impl Position { position.into() } - pub fn to_logical(&self, dpi_factor: f64) -> LogicalPosition

{ + pub fn to_logical(&self, scale_factor: f64) -> LogicalPosition

{ match *self { - Position::Physical(position) => position.to_logical(dpi_factor), + Position::Physical(position) => position.to_logical(scale_factor), Position::Logical(position) => position.cast(), } } - pub fn to_physical(&self, dpi_factor: f64) -> PhysicalPosition

{ + pub fn to_physical(&self, scale_factor: f64) -> PhysicalPosition

{ match *self { Position::Physical(position) => position.cast(), - Position::Logical(position) => position.to_physical(dpi_factor), + Position::Logical(position) => position.to_physical(scale_factor), } } } diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index a4cf29fa..ef0639d1 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -61,10 +61,10 @@ impl EventLoop { while let Ok(event) = self.event_rx.try_recv() { let e = match event { android_glue::Event::EventMotion(motion) => { - let dpi_factor = MonitorHandle.scale_factor(); + let scale_factor = MonitorHandle.scale_factor(); let location = LogicalPosition::from_physical( (motion.x as f64, motion.y as f64), - dpi_factor, + scale_factor, ); Some(Event::WindowEvent { window_id: RootWindowId(WindowId), @@ -102,9 +102,9 @@ impl EventLoop { if native_window.is_null() { None } else { - let dpi_factor = MonitorHandle.scale_factor(); + let scale_factor = MonitorHandle.scale_factor(); let physical_size = MonitorHandle.size(); - let size = LogicalSize::from_physical(physical_size, dpi_factor); + let size = LogicalSize::from_physical(physical_size, scale_factor); Some(Event::WindowEvent { window_id: RootWindowId(WindowId), event: WindowEvent::Resized(size), @@ -319,9 +319,9 @@ impl Window { if self.native_window.is_null() { None } else { - let dpi_factor = self.scale_factor(); + let scale_factor = self.scale_factor(); let physical_size = self.current_monitor().size(); - Some(LogicalSize::from_physical(physical_size, dpi_factor)) + Some(LogicalSize::from_physical(physical_size, scale_factor)) } } diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 33ecac37..77f3fc59 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -127,12 +127,12 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { let screen_space: id = msg_send![screen, coordinateSpace]; let screen_frame: CGRect = msg_send![object, convertRect:bounds toCoordinateSpace:screen_space]; - let dpi_factor: CGFloat = msg_send![screen, scale]; + let scale_factor: CGFloat = msg_send![screen, scale]; let size = crate::dpi::LogicalSize { width: screen_frame.size.width as f64, height: screen_frame.size.height as f64, } - .to_physical(dpi_factor.into()); + .to_physical(scale_factor.into()); app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent { window_id: RootWindowId(window.into()), event: WindowEvent::Resized(size), @@ -162,15 +162,15 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { // `setContentScaleFactor` may be called with a value of 0, which means "reset the // content scale factor to a device-specific default value", so we can't use the // parameter here. We can query the actual factor using the getter - let dpi_factor: CGFloat = msg_send![object, contentScaleFactor]; + let scale_factor: CGFloat = msg_send![object, contentScaleFactor]; assert!( - !dpi_factor.is_nan() - && dpi_factor.is_finite() - && dpi_factor.is_sign_positive() - && dpi_factor > 0.0, + !scale_factor.is_nan() + && scale_factor.is_finite() + && scale_factor.is_sign_positive() + && scale_factor > 0.0, "invalid scale_factor set on UIView", ); - let scale_factor: f64 = dpi_factor.into(); + let scale_factor: f64 = scale_factor.into(); let bounds: CGRect = msg_send![object, bounds]; let screen: id = msg_send![window, screen]; let screen_space: id = msg_send![screen, coordinateSpace]; diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index a5d3e893..ec943116 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -83,8 +83,8 @@ impl Inner { x: safe_area.origin.x as f64, y: safe_area.origin.y as f64, }; - let dpi_factor = self.scale_factor(); - Ok(position.to_physical(dpi_factor)) + let scale_factor = self.scale_factor(); + Ok(position.to_physical(scale_factor)) } } @@ -95,15 +95,15 @@ impl Inner { x: screen_frame.origin.x as f64, y: screen_frame.origin.y as f64, }; - let dpi_factor = self.scale_factor(); - Ok(position.to_physical(dpi_factor)) + let scale_factor = self.scale_factor(); + Ok(position.to_physical(scale_factor)) } } pub fn set_outer_position(&self, physical_position: Position) { unsafe { - let dpi_factor = self.scale_factor(); - let position = physical_position.to_logical::(dpi_factor); + let scale_factor = self.scale_factor(); + let position = physical_position.to_logical::(scale_factor); let screen_frame = self.screen_frame(); let new_screen_frame = CGRect { origin: CGPoint { @@ -119,25 +119,25 @@ impl Inner { pub fn inner_size(&self) -> PhysicalSize { unsafe { - let dpi_factor = self.scale_factor(); + let scale_factor = self.scale_factor(); let safe_area = self.safe_area_screen_space(); let size = LogicalSize { width: safe_area.size.width as f64, height: safe_area.size.height as f64, }; - size.to_physical(dpi_factor) + size.to_physical(scale_factor) } } pub fn outer_size(&self) -> PhysicalSize { unsafe { - let dpi_factor = self.scale_factor(); + let scale_factor = self.scale_factor(); let screen_frame = self.screen_frame(); let size = LogicalSize { width: screen_frame.size.width as f64, height: screen_frame.size.height as f64, }; - size.to_physical(dpi_factor) + size.to_physical(scale_factor) } } @@ -355,8 +355,8 @@ impl Window { let frame = match window_attributes.inner_size { Some(dim) => { - let dpi_factor = msg_send![screen, scale]; - let size = dim.to_logical::(dpi_factor); + let scale_factor = msg_send![screen, scale]; + let size = dim.to_logical::(scale_factor); CGRect { origin: screen_bounds.origin, size: CGSize { @@ -400,8 +400,8 @@ impl Window { // Like the Windows and macOS backends, we send a `ScaleFactorChanged` and `Resized` // event on window creation if the DPI factor != 1.0 - let dpi_factor: CGFloat = msg_send![view, contentScaleFactor]; - let scale_factor: f64 = dpi_factor.into(); + let scale_factor: CGFloat = msg_send![view, contentScaleFactor]; + let scale_factor: f64 = scale_factor.into(); if scale_factor != 1.0 { let bounds: CGRect = msg_send![view, bounds]; let screen: id = msg_send![window, screen]; diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index d8bb99e8..f178ba3a 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -136,23 +136,23 @@ impl UnownedWindow { }) .unwrap_or_else(|| monitors.swap_remove(0)) }; - let dpi_factor = guessed_monitor.scale_factor(); + let scale_factor = guessed_monitor.scale_factor(); - info!("Guessed window scale factor: {}", dpi_factor); + info!("Guessed window scale factor: {}", scale_factor); let max_inner_size: Option<(u32, u32)> = window_attrs .max_inner_size - .map(|size| size.to_physical::(dpi_factor).into()); + .map(|size| size.to_physical::(scale_factor).into()); let min_inner_size: Option<(u32, u32)> = window_attrs .min_inner_size - .map(|size| size.to_physical::(dpi_factor).into()); + .map(|size| size.to_physical::(scale_factor).into()); let dimensions = { // x11 only applies constraints when the window is actively resized // by the user, so we have to manually apply the initial constraints let mut dimensions: (u32, u32) = window_attrs .inner_size - .map(|size| size.to_physical::(dpi_factor)) + .map(|size| size.to_physical::(scale_factor)) .or_else(|| Some((800, 600).into())) .map(Into::into) .unwrap(); @@ -324,10 +324,10 @@ impl UnownedWindow { { let mut min_inner_size = window_attrs .min_inner_size - .map(|size| size.to_physical::(dpi_factor)); + .map(|size| size.to_physical::(scale_factor)); let mut max_inner_size = window_attrs .max_inner_size - .map(|size| size.to_physical::(dpi_factor)); + .map(|size| size.to_physical::(scale_factor)); if !window_attrs.resizable { if util::wm_name_is_one_of(&["Xfwm4"]) { @@ -351,12 +351,12 @@ impl UnownedWindow { normal_hints.set_resize_increments( pl_attribs .resize_increments - .map(|size| size.to_physical::(dpi_factor).into()), + .map(|size| size.to_physical::(scale_factor).into()), ); normal_hints.set_base_size( pl_attribs .base_size - .map(|size| size.to_physical::(dpi_factor).into()), + .map(|size| size.to_physical::(scale_factor).into()), ); xconn.set_normal_hints(window.xwindow, normal_hints).queue(); } @@ -1053,8 +1053,8 @@ impl UnownedWindow { #[inline] pub fn set_inner_size(&self, size: Size) { - let dpi_factor = self.scale_factor(); - let (width, height) = size.to_physical::(dpi_factor).into(); + let scale_factor = self.scale_factor(); + let (width, height) = size.to_physical::(scale_factor).into(); self.set_inner_size_physical(width, height); } @@ -1097,16 +1097,16 @@ impl UnownedWindow { pub(crate) fn adjust_for_dpi( &self, - old_dpi_factor: f64, - new_dpi_factor: f64, + old_scale_factor: f64, + new_scale_factor: f64, width: u32, height: u32, shared_state: &SharedState, ) -> (u32, u32) { - let scale_factor = new_dpi_factor / old_dpi_factor; + let scale_factor = new_scale_factor / old_scale_factor; self.update_normal_hints(|normal_hints| { let dpi_adjuster = - |size: Size| -> (u32, u32) { size.to_physical::(new_dpi_factor).into() }; + |size: Size| -> (u32, u32) { size.to_physical::(new_scale_factor).into() }; let max_size = shared_state.max_inner_size.map(&dpi_adjuster); let min_size = shared_state.min_inner_size.map(&dpi_adjuster); let resize_increments = shared_state.resize_increments.map(&dpi_adjuster); @@ -1146,12 +1146,12 @@ impl UnownedWindow { self.set_maximizable_inner(resizable).queue(); - let dpi_factor = self.scale_factor(); + let scale_factor = self.scale_factor(); let min_inner_size = min_size - .map(|size| size.to_physical::(dpi_factor)) + .map(|size| size.to_physical::(scale_factor)) .map(Into::into); let max_inner_size = max_size - .map(|size| size.to_physical::(dpi_factor)) + .map(|size| size.to_physical::(scale_factor)) .map(Into::into); self.update_normal_hints(|normal_hints| { normal_hints.set_min_size(min_inner_size); diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index b800d4d4..2d692949 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -340,7 +340,7 @@ impl UnownedWindow { let input_context = unsafe { util::create_input_context(*ns_view) }; - let dpi_factor = unsafe { NSWindow::backingScaleFactor(*ns_window) as f64 }; + let scale_factor = unsafe { NSWindow::backingScaleFactor(*ns_window) as f64 }; unsafe { if win_attribs.transparent { @@ -350,11 +350,11 @@ impl UnownedWindow { ns_app.activateIgnoringOtherApps_(YES); win_attribs.min_inner_size.map(|dim| { - let logical_dim = dim.to_logical(dpi_factor); + let logical_dim = dim.to_logical(scale_factor); set_min_inner_size(*ns_window, logical_dim) }); win_attribs.max_inner_size.map(|dim| { - let logical_dim = dim.to_logical(dpi_factor); + let logical_dim = dim.to_logical(scale_factor); set_max_inner_size(*ns_window, logical_dim) }); @@ -378,7 +378,7 @@ impl UnownedWindow { let decorations = win_attribs.decorations; let inner_rect = win_attribs .inner_size - .map(|size| size.to_physical(dpi_factor)); + .map(|size| size.to_physical(scale_factor)); let window = Arc::new(UnownedWindow { ns_view, @@ -450,8 +450,8 @@ impl UnownedWindow { frame_rect.origin.x as f64, util::bottom_left_to_top_left(frame_rect), ); - let dpi_factor = self.scale_factor(); - Ok(position.to_physical(dpi_factor)) + let scale_factor = self.scale_factor(); + Ok(position.to_physical(scale_factor)) } pub fn inner_position(&self) -> Result, NotSupportedError> { @@ -462,13 +462,13 @@ impl UnownedWindow { content_rect.origin.x as f64, util::bottom_left_to_top_left(content_rect), ); - let dpi_factor = self.scale_factor(); - Ok(position.to_physical(dpi_factor)) + let scale_factor = self.scale_factor(); + Ok(position.to_physical(scale_factor)) } pub fn set_outer_position(&self, position: Position) { - let dpi_factor = self.scale_factor(); - let position = position.to_logical(dpi_factor); + let scale_factor = self.scale_factor(); + let position = position.to_logical(scale_factor); let dummy = NSRect::new( NSPoint::new( position.x, @@ -488,8 +488,8 @@ impl UnownedWindow { let view_frame = unsafe { NSView::frame(*self.ns_view) }; let logical: LogicalSize = (view_frame.size.width as f64, view_frame.size.height as f64).into(); - let dpi_factor = self.scale_factor(); - logical.to_physical(dpi_factor) + let scale_factor = self.scale_factor(); + logical.to_physical(scale_factor) } #[inline] @@ -497,15 +497,15 @@ impl UnownedWindow { let view_frame = unsafe { NSWindow::frame(*self.ns_window) }; let logical: LogicalSize = (view_frame.size.width as f64, view_frame.size.height as f64).into(); - let dpi_factor = self.scale_factor(); - logical.to_physical(dpi_factor) + let scale_factor = self.scale_factor(); + logical.to_physical(scale_factor) } #[inline] pub fn set_inner_size(&self, size: Size) { unsafe { - let dpi_factor = self.scale_factor(); - util::set_content_size_async(*self.ns_window, size.to_logical(dpi_factor)); + let scale_factor = self.scale_factor(); + util::set_content_size_async(*self.ns_window, size.to_logical(scale_factor)); } } @@ -515,8 +515,8 @@ impl UnownedWindow { width: 0.0, height: 0.0, })); - let dpi_factor = self.scale_factor(); - set_min_inner_size(*self.ns_window, dimensions.to_logical(dpi_factor)); + let scale_factor = self.scale_factor(); + set_min_inner_size(*self.ns_window, dimensions.to_logical(scale_factor)); } } @@ -526,8 +526,8 @@ impl UnownedWindow { width: std::f32::MAX as f64, height: std::f32::MAX as f64, })); - let dpi_factor = self.scale_factor(); - set_max_inner_size(*self.ns_window, dimensions.to_logical(dpi_factor)); + let scale_factor = self.scale_factor(); + set_max_inner_size(*self.ns_window, dimensions.to_logical(scale_factor)); } } @@ -594,9 +594,9 @@ impl UnownedWindow { #[inline] pub fn set_cursor_position(&self, cursor_position: Position) -> Result<(), ExternalError> { let physical_window_position = self.inner_position().unwrap(); - let dpi_factor = self.scale_factor(); - let window_position = physical_window_position.to_logical::(dpi_factor); - let logical_cursor_position = cursor_position.to_logical::(dpi_factor); + let scale_factor = self.scale_factor(); + let window_position = physical_window_position.to_logical::(scale_factor); + let logical_cursor_position = cursor_position.to_logical::(scale_factor); let point = appkit::CGPoint { x: logical_cursor_position.x + window_position.x, y: logical_cursor_position.y + window_position.y, @@ -933,8 +933,8 @@ impl UnownedWindow { #[inline] pub fn set_ime_position(&self, spot: Position) { - let dpi_factor = self.scale_factor(); - let logical_spot = spot.to_logical(dpi_factor); + let scale_factor = self.scale_factor(); + let logical_spot = spot.to_logical(scale_factor); unsafe { view::set_ime_position( *self.ns_view, diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 77668937..f04d7c73 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -43,7 +43,7 @@ pub struct WindowDelegateState { previous_position: Option<(f64, f64)>, // Used to prevent redundant events. - previous_dpi_factor: f64, + previous_scale_factor: f64, } impl WindowDelegateState { @@ -55,7 +55,7 @@ impl WindowDelegateState { window: Arc::downgrade(&window), initial_fullscreen, previous_position: None, - previous_dpi_factor: scale_factor, + previous_scale_factor: scale_factor, }; if scale_factor != 1.0 { @@ -82,11 +82,11 @@ impl WindowDelegateState { pub fn emit_static_scale_factor_changed_event(&mut self) { let scale_factor = self.get_scale_factor(); - if scale_factor == self.previous_dpi_factor { + if scale_factor == self.previous_scale_factor { return (); }; - self.previous_dpi_factor = scale_factor; + self.previous_scale_factor = scale_factor; let wrapper = EventWrapper::EventProxy(EventProxy::DpiChangedProxy { ns_window: IdRef::retain(*self.ns_window), suggested_size: self.view_size(), diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 0049b09c..7e1d929e 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -1422,7 +1422,7 @@ unsafe extern "system" fn public_window_callback( if window_state.min_size.is_some() || window_state.max_size.is_some() { if let Some(min_size) = window_state.min_size { - let min_size = min_size.to_physical(window_state.dpi_factor); + let min_size = min_size.to_physical(window_state.scale_factor); let (width, height): (u32, u32) = util::adjust_size(window, min_size).into(); (*mmi).ptMinTrackSize = POINT { x: width as i32, @@ -1430,7 +1430,7 @@ unsafe extern "system" fn public_window_callback( }; } if let Some(max_size) = window_state.max_size { - let max_size = max_size.to_physical(window_state.dpi_factor); + let max_size = max_size.to_physical(window_state.scale_factor); let (width, height): (u32, u32) = util::adjust_size(window, max_size).into(); (*mmi).ptMaxTrackSize = POINT { x: width as i32, @@ -1452,15 +1452,15 @@ unsafe extern "system" fn public_window_callback( // application since they are the same". // https://msdn.microsoft.com/en-us/library/windows/desktop/dn312083(v=vs.85).aspx let new_dpi_x = u32::from(LOWORD(wparam as DWORD)); - let new_dpi_factor = dpi_to_scale_factor(new_dpi_x); - let old_dpi_factor: f64; + let new_scale_factor = dpi_to_scale_factor(new_dpi_x); + let old_scale_factor: f64; let allow_resize = { let mut window_state = subclass_input.window_state.lock(); - old_dpi_factor = window_state.dpi_factor; - window_state.dpi_factor = new_dpi_factor; + old_scale_factor = window_state.scale_factor; + window_state.scale_factor = new_scale_factor; - if new_dpi_factor == old_dpi_factor { + if new_scale_factor == old_scale_factor { return 0; } @@ -1516,15 +1516,15 @@ unsafe extern "system" fn public_window_callback( // 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), + .to_logical::(old_scale_factor) + .to_physical::(new_scale_factor), false => old_physical_inner_size, }; let _ = subclass_input.send_event(Event::WindowEvent { window_id: RootWindowId(WindowId(window)), event: ScaleFactorChanged { - scale_factor: new_dpi_factor, + scale_factor: new_scale_factor, new_inner_size: &mut new_physical_inner_size, }, }); diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index f3e7851a..7feb631c 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -217,8 +217,8 @@ impl Window { #[inline] pub fn set_inner_size(&self, size: Size) { - let dpi_factor = self.scale_factor(); - let (width, height) = size.to_physical::(dpi_factor).into(); + let scale_factor = self.scale_factor(); + let (width, height) = size.to_physical::(scale_factor).into(); let window_state = Arc::clone(&self.window_state); let window = self.window.clone(); @@ -325,13 +325,13 @@ impl Window { #[inline] pub fn scale_factor(&self) -> f64 { - self.window_state.lock().dpi_factor + self.window_state.lock().scale_factor } #[inline] pub fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError> { - let dpi_factor = self.scale_factor(); - let (x, y) = position.to_physical::(dpi_factor).into(); + let scale_factor = self.scale_factor(); + let (x, y) = position.to_physical::(scale_factor).into(); let mut point = POINT { x, y }; unsafe { @@ -402,7 +402,7 @@ impl Window { let client_rect = util::get_client_rect(window.0).unwrap(); window_state_lock.saved_window = Some(SavedWindow { client_rect, - dpi_factor: window_state_lock.dpi_factor, + scale_factor: window_state_lock.scale_factor, }); } _ => (), @@ -513,10 +513,10 @@ impl Window { let mut window_state_lock = window_state.lock(); if let Some(SavedWindow { client_rect, - dpi_factor, + scale_factor, }) = window_state_lock.saved_window.take() { - window_state_lock.dpi_factor = dpi_factor; + window_state_lock.scale_factor = scale_factor; drop(window_state_lock); let client_rect = util::adjust_window_rect(window.0, client_rect).unwrap(); @@ -712,7 +712,7 @@ unsafe fn init( } let dpi = hwnd_dpi(real_window.0); - let dpi_factor = dpi_to_scale_factor(dpi); + let scale_factor = dpi_to_scale_factor(dpi); // making the window transparent if attributes.transparent && !pl_attribs.no_redirection_bitmap { @@ -758,7 +758,7 @@ unsafe fn init( &attributes, window_icon, taskbar_icon, - dpi_factor, + scale_factor, dark_mode, ); let window_state = Arc::new(Mutex::new(window_state)); diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 8150d119..c2f8ee36 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -26,7 +26,7 @@ pub struct WindowState { pub taskbar_icon: Option, pub saved_window: Option, - pub dpi_factor: f64, + pub scale_factor: f64, pub fullscreen: Option, /// Used to supress duplicate redraw attempts when calling `request_redraw` multiple @@ -40,7 +40,7 @@ pub struct WindowState { #[derive(Clone)] pub struct SavedWindow { pub client_rect: RECT, - pub dpi_factor: f64, + pub scale_factor: f64, } #[derive(Clone)] @@ -98,7 +98,7 @@ impl WindowState { attributes: &WindowAttributes, window_icon: Option, taskbar_icon: Option, - dpi_factor: f64, + scale_factor: f64, is_dark_mode: bool, ) -> WindowState { WindowState { @@ -115,7 +115,7 @@ impl WindowState { taskbar_icon, saved_window: None, - dpi_factor, + scale_factor, fullscreen: None, queued_out_of_band_redraw: false,