diff --git a/CHANGELOG.md b/CHANGELOG.md index d9728275..1cfa5bdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Unreleased +- Added event `WindowEvent::HiDPIFactorChanged`. +- Added method `MonitorId::get_hidpi_factor`. +- Deprecated `get_inner_size_pixels` and `get_inner_size_points` methods of `Window` in favor of +`get_inner_size`. + # Version 0.8.3 (2017-10-11) - Fixed issue of calls to `set_inner_size` blocking on Windows. diff --git a/src/events.rs b/src/events.rs index 24b815ef..ef5c6e9b 100644 --- a/src/events.rs +++ b/src/events.rs @@ -87,6 +87,15 @@ pub enum WindowEvent { /// Touch event has been received Touch(Touch), + + /// DPI scaling factor of the window has changed. + /// + /// The following actions cause DPI changes: + /// + /// * A user changes the resolution. + /// * A user changes the desktop scaling value (e.g. in Control Panel on Windows). + /// * A user moves the application window to a display with a different DPI. + HiDPIFactorChanged(f32), } /// Represents raw hardware events that are not associated with any particular window. diff --git a/src/platform/android/mod.rs b/src/platform/android/mod.rs index 037477be..ca10a94e 100644 --- a/src/platform/android/mod.rs +++ b/src/platform/android/mod.rs @@ -164,6 +164,11 @@ impl MonitorId { // Android assumes single screen (0, 0) } + + #[inline] + pub fn get_hidpi_factor(&self) -> f32 { + 1.0 + } } #[derive(Clone, Default)] diff --git a/src/platform/emscripten/mod.rs b/src/platform/emscripten/mod.rs index 1d893928..a3389cf0 100644 --- a/src/platform/emscripten/mod.rs +++ b/src/platform/emscripten/mod.rs @@ -42,6 +42,11 @@ impl MonitorId { pub fn get_dimensions(&self) -> (u32, u32) { (0, 0) } + + #[inline] + pub fn get_hidpi_factor(&self) -> f32 { + 1.0 + } } // Used to assign a callback to emscripten main loop diff --git a/src/platform/ios/mod.rs b/src/platform/ios/mod.rs index 9d746264..51480977 100644 --- a/src/platform/ios/mod.rs +++ b/src/platform/ios/mod.rs @@ -145,6 +145,11 @@ impl MonitorId { // iOS assumes single screen (0, 0) } + + #[inline] + pub fn get_hidpi_factor(&self) -> f32 { + 1.0 + } } pub struct EventsLoop { diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index ba147f12..6079466a 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -94,6 +94,11 @@ impl MonitorId { &MonitorId::Wayland(ref m) => m.get_position(), } } + + #[inline] + pub fn get_hidpi_factor(&self) -> f32 { + 1.0 + } } impl Window { diff --git a/src/platform/linux/wayland/context.rs b/src/platform/linux/wayland/context.rs index ca399fce..8c592de8 100644 --- a/src/platform/linux/wayland/context.rs +++ b/src/platform/linux/wayland/context.rs @@ -407,6 +407,11 @@ impl MonitorId { // if we reach here, this monitor does not exist any more (0,0) } + + #[inline] + pub fn get_hidpi_factor(&self) -> f32 { + 1.0 + } } // a handler to release the ressources acquired to draw the initial white screen as soon as diff --git a/src/platform/linux/x11/monitor.rs b/src/platform/linux/x11/monitor.rs index 463dde6c..cd05b153 100644 --- a/src/platform/linux/x11/monitor.rs +++ b/src/platform/linux/x11/monitor.rs @@ -101,4 +101,9 @@ impl MonitorId { pub fn get_position(&self) -> (u32, u32) { self.position } + + #[inline] + pub fn get_hidpi_factor(&self) -> f32 { + 1.0 + } } diff --git a/src/platform/linux/x11/window.rs b/src/platform/linux/x11/window.rs index e0e75b6b..be8bcdd8 100644 --- a/src/platform/linux/x11/window.rs +++ b/src/platform/linux/x11/window.rs @@ -473,7 +473,7 @@ impl Window2 { #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { - self.get_geometry().map(|(_, _, w, h, _)| ((w as f32 / self.hidpi_factor()) as u32, (h as f32 / self.hidpi_factor()) as u32)) + self.get_geometry().map(|(_, _, w, h, _)| (w, h)) } #[inline] diff --git a/src/platform/macos/monitor.rs b/src/platform/macos/monitor.rs index 76b5dfe8..85bca223 100644 --- a/src/platform/macos/monitor.rs +++ b/src/platform/macos/monitor.rs @@ -53,4 +53,9 @@ impl MonitorId { pub fn get_position(&self) -> (u32, u32) { unimplemented!() } + + #[inline] + pub fn get_hidpi_factor(&self) -> f32 { + 1.0 + } } diff --git a/src/platform/windows/monitor.rs b/src/platform/windows/monitor.rs index 14eea3ee..7653fd78 100644 --- a/src/platform/windows/monitor.rs +++ b/src/platform/windows/monitor.rs @@ -181,4 +181,9 @@ impl MonitorId { pub fn get_position(&self) -> (u32, u32) { self.position } + + #[inline] + pub fn get_hidpi_factor(&self) -> f32 { + 1.0 + } } diff --git a/src/window.rs b/src/window.rs index cdc07172..55ed9e15 100644 --- a/src/window.rs +++ b/src/window.rs @@ -91,7 +91,7 @@ impl WindowBuilder { self } - /// Enables multitouch + /// Enables multitouch. #[inline] pub fn with_multitouch(mut self) -> WindowBuilder { self.window.multitouch = true; @@ -183,7 +183,7 @@ impl Window { /// Modifies the position of the window. /// - /// See `get_position` for more informations about the coordinates. + /// See `get_position` for more information about the coordinates. /// /// This is a no-op if the window has already been closed. #[inline] @@ -191,14 +191,12 @@ impl Window { self.window.set_position(x, y) } - /// Returns the size in points of the client area of the window. + /// Returns the size in pixels of the client area of the window. /// /// The client area is the content of the window, excluding the title bar and borders. - /// To get the dimensions of the frame buffer when calling `glViewport`, multiply with hidpi factor. + /// These are the dimensions that need to be supplied to `glViewport`. /// /// Returns `None` if the window no longer exists. - /// - /// DEPRECATED #[inline] pub fn get_inner_size(&self) -> Option<(u32, u32)> { self.window.get_inner_size() @@ -210,12 +208,17 @@ impl Window { /// To get the dimensions of the frame buffer when calling `glViewport`, multiply with hidpi factor. /// /// Returns `None` if the window no longer exists. + /// + /// DEPRECATED #[inline] + #[deprecated] pub fn get_inner_size_points(&self) -> Option<(u32, u32)> { - self.window.get_inner_size() + self.window.get_inner_size().map(|(x, y)| { + let hidpi = self.hidpi_factor(); + ((x as f32 / hidpi) as u32, (y as f32 / hidpi) as u32) + }) } - /// Returns the size in pixels of the client area of the window. /// /// The client area is the content of the window, excluding the title bar and borders. @@ -223,12 +226,12 @@ impl Window { /// when you call `glViewport`. /// /// Returns `None` if the window no longer exists. + /// + /// DEPRECATED #[inline] + #[deprecated] pub fn get_inner_size_pixels(&self) -> Option<(u32, u32)> { - self.window.get_inner_size().map(|(x, y)| { - let hidpi = self.hidpi_factor(); - ((x as f32 * hidpi) as u32, (y as f32 * hidpi) as u32) - }) + self.window.get_inner_size() } /// Returns the size in pixels of the window. @@ -244,7 +247,7 @@ impl Window { /// Modifies the inner size of the window. /// - /// See `get_inner_size` for more informations about the values. + /// See `get_inner_size` for more information about the values. /// /// This is a no-op if the window has already been closed. #[inline] @@ -323,7 +326,7 @@ impl Window { } /// An iterator for the list of available monitors. -// Implementation note: we retreive the list once, then serve each element by one by one. +// Implementation note: we retrieve the list once, then serve each element by one by one. // This may change in the future. pub struct AvailableMonitorsIter { pub(crate) data: VecDequeIter, @@ -370,4 +373,10 @@ impl MonitorId { pub fn get_position(&self) -> (u32, u32) { self.inner.get_position() } + + /// Returns the ratio between the monitor's physical pixels and logical pixels. + #[inline] + pub fn get_hidpi_factor(&self) -> f32 { + self.inner.get_hidpi_factor() + } }