diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b287ee76..d80535eba4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased - On Windows, fix `CursorMoved(0, 0)` getting dispatched on window focus. +- On macOS, add `WindowBuilderExt::with_disallow_hidpi` to have the option to turn off best resolution openGL surface - On macOS, fix command key event left and right reverse. - On FreeBSD, NetBSD, and OpenBSD, fix build of X11 backend. diff --git a/src/os/macos.rs b/src/os/macos.rs index b9ea993b39..fcea7cc7f9 100644 --- a/src/os/macos.rs +++ b/src/os/macos.rs @@ -82,6 +82,7 @@ impl Default for ActivationPolicy { /// - `with_titlebar_hidden` /// - `with_titlebar_buttons_hidden` /// - `with_fullsize_content_view` +/// - `with_disallow_hidpi` pub trait WindowBuilderExt { /// Sets the activation policy for the window being built. fn with_activation_policy(self, activation_policy: ActivationPolicy) -> WindowBuilder; @@ -99,6 +100,8 @@ pub trait WindowBuilderExt { fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder; /// Build window with `resizeIncrements` property. Values must not be 0. fn with_resize_increments(self, increments: LogicalSize) -> WindowBuilder; + /// Disables hidpi. + fn with_disallow_hidpi(self, disallow_hidpi: bool) -> WindowBuilder; } impl WindowBuilderExt for WindowBuilder { @@ -149,6 +152,12 @@ impl WindowBuilderExt for WindowBuilder { self.platform_specific.resize_increments = Some(increments.into()); self } + + #[inline] + fn with_disallow_hidpi(mut self, disallow_hidpi: bool) -> WindowBuilder { + self.platform_specific.disallow_hidpi = disallow_hidpi; + self + } } /// Additional methods on `MonitorId` that are specific to MacOS. diff --git a/src/platform/macos/window.rs b/src/platform/macos/window.rs index 4fc27328a3..eb51f524a3 100644 --- a/src/platform/macos/window.rs +++ b/src/platform/macos/window.rs @@ -539,6 +539,7 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub titlebar_hidden: bool, pub titlebar_buttons_hidden: bool, pub fullsize_content_view: bool, + pub disallow_hidpi: bool, pub resize_increments: Option, } @@ -715,7 +716,7 @@ impl Window2 { return Err(OsError(format!("Couldn't create NSWindow"))); }, }; - let (view, cursor) = match Window2::create_view(*window, Weak::clone(&shared)) { + let (view, cursor) = match Window2::create_view(*window, Weak::clone(&shared), &pl_attribs) { Some(view) => view, None => { let _: () = unsafe { msg_send![autoreleasepool, drain] }; @@ -952,12 +953,17 @@ impl Window2 { } } - fn create_view(window: id, shared: Weak) -> Option<(IdRef, Weak>)> { + fn create_view( + window: id, + shared: Weak, + pl_attribs: &PlatformSpecificWindowBuilderAttributes + ) -> Option<(IdRef, Weak>)> { unsafe { let (view, cursor) = new_view(window, shared); view.non_nil().map(|view| { - view.setWantsBestResolutionOpenGLSurface_(YES); - + if !pl_attribs.disallow_hidpi { + view.setWantsBestResolutionOpenGLSurface_(YES); + } // On Mojave, views automatically become layer-backed shortly after being added to // a window. Changing the layer-backedness of a view breaks the association between // the view and its associated OpenGL context. To work around this, on Mojave we