mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 13:31:29 +11:00
Implement public API for high-DPI (#319)
* Implement public API for high-DPI #105 * Recover get_inner_size_points and get_inner_size_pixels and change their implementation assuming get_inner_size() returns size in pixels * Update changelog for high-DPI changes
This commit is contained in:
parent
eff3440482
commit
48902297b7
|
@ -1,5 +1,10 @@
|
||||||
# Unreleased
|
# 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)
|
# Version 0.8.3 (2017-10-11)
|
||||||
|
|
||||||
- Fixed issue of calls to `set_inner_size` blocking on Windows.
|
- Fixed issue of calls to `set_inner_size` blocking on Windows.
|
||||||
|
|
|
@ -87,6 +87,15 @@ pub enum WindowEvent {
|
||||||
|
|
||||||
/// Touch event has been received
|
/// Touch event has been received
|
||||||
Touch(Touch),
|
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.
|
/// Represents raw hardware events that are not associated with any particular window.
|
||||||
|
|
|
@ -164,6 +164,11 @@ impl MonitorId {
|
||||||
// Android assumes single screen
|
// Android assumes single screen
|
||||||
(0, 0)
|
(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
|
|
|
@ -42,6 +42,11 @@ impl MonitorId {
|
||||||
pub fn get_dimensions(&self) -> (u32, u32) {
|
pub fn get_dimensions(&self) -> (u32, u32) {
|
||||||
(0, 0)
|
(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to assign a callback to emscripten main loop
|
// Used to assign a callback to emscripten main loop
|
||||||
|
|
|
@ -145,6 +145,11 @@ impl MonitorId {
|
||||||
// iOS assumes single screen
|
// iOS assumes single screen
|
||||||
(0, 0)
|
(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventsLoop {
|
pub struct EventsLoop {
|
||||||
|
|
|
@ -94,6 +94,11 @@ impl MonitorId {
|
||||||
&MonitorId::Wayland(ref m) => m.get_position(),
|
&MonitorId::Wayland(ref m) => m.get_position(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
|
|
|
@ -407,6 +407,11 @@ impl MonitorId {
|
||||||
// if we reach here, this monitor does not exist any more
|
// if we reach here, this monitor does not exist any more
|
||||||
(0,0)
|
(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
|
// a handler to release the ressources acquired to draw the initial white screen as soon as
|
||||||
|
|
|
@ -101,4 +101,9 @@ impl MonitorId {
|
||||||
pub fn get_position(&self) -> (u32, u32) {
|
pub fn get_position(&self) -> (u32, u32) {
|
||||||
self.position
|
self.position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -473,7 +473,7 @@ impl Window2 {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_inner_size(&self) -> Option<(u32, u32)> {
|
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]
|
#[inline]
|
||||||
|
|
|
@ -53,4 +53,9 @@ impl MonitorId {
|
||||||
pub fn get_position(&self) -> (u32, u32) {
|
pub fn get_position(&self) -> (u32, u32) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,4 +181,9 @@ impl MonitorId {
|
||||||
pub fn get_position(&self) -> (u32, u32) {
|
pub fn get_position(&self) -> (u32, u32) {
|
||||||
self.position
|
self.position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl WindowBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enables multitouch
|
/// Enables multitouch.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_multitouch(mut self) -> WindowBuilder {
|
pub fn with_multitouch(mut self) -> WindowBuilder {
|
||||||
self.window.multitouch = true;
|
self.window.multitouch = true;
|
||||||
|
@ -183,7 +183,7 @@ impl Window {
|
||||||
|
|
||||||
/// Modifies the position of the 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.
|
/// This is a no-op if the window has already been closed.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -191,14 +191,12 @@ impl Window {
|
||||||
self.window.set_position(x, y)
|
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.
|
/// 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.
|
/// Returns `None` if the window no longer exists.
|
||||||
///
|
|
||||||
/// DEPRECATED
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_inner_size(&self) -> Option<(u32, u32)> {
|
pub fn get_inner_size(&self) -> Option<(u32, u32)> {
|
||||||
self.window.get_inner_size()
|
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.
|
/// To get the dimensions of the frame buffer when calling `glViewport`, multiply with hidpi factor.
|
||||||
///
|
///
|
||||||
/// Returns `None` if the window no longer exists.
|
/// Returns `None` if the window no longer exists.
|
||||||
|
///
|
||||||
|
/// DEPRECATED
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[deprecated]
|
||||||
pub fn get_inner_size_points(&self) -> Option<(u32, u32)> {
|
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.
|
/// 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.
|
/// 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`.
|
/// when you call `glViewport`.
|
||||||
///
|
///
|
||||||
/// Returns `None` if the window no longer exists.
|
/// Returns `None` if the window no longer exists.
|
||||||
|
///
|
||||||
|
/// DEPRECATED
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[deprecated]
|
||||||
pub fn get_inner_size_pixels(&self) -> Option<(u32, u32)> {
|
pub fn get_inner_size_pixels(&self) -> Option<(u32, u32)> {
|
||||||
self.window.get_inner_size().map(|(x, y)| {
|
self.window.get_inner_size()
|
||||||
let hidpi = self.hidpi_factor();
|
|
||||||
((x as f32 * hidpi) as u32, (y as f32 * hidpi) as u32)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the size in pixels of the window.
|
/// Returns the size in pixels of the window.
|
||||||
|
@ -244,7 +247,7 @@ impl Window {
|
||||||
|
|
||||||
/// Modifies the inner size of the 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.
|
/// This is a no-op if the window has already been closed.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -323,7 +326,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator for the list of available monitors.
|
/// 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.
|
// This may change in the future.
|
||||||
pub struct AvailableMonitorsIter {
|
pub struct AvailableMonitorsIter {
|
||||||
pub(crate) data: VecDequeIter<platform::MonitorId>,
|
pub(crate) data: VecDequeIter<platform::MonitorId>,
|
||||||
|
@ -370,4 +373,10 @@ impl MonitorId {
|
||||||
pub fn get_position(&self) -> (u32, u32) {
|
pub fn get_position(&self) -> (u32, u32) {
|
||||||
self.inner.get_position()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue