From 25189a79956f04a15efb24760bbae3d153461050 Mon Sep 17 00:00:00 2001 From: Tiga Wu Date: Wed, 20 Mar 2019 23:24:49 -0400 Subject: [PATCH 1/2] add option on macos to disallow highdpi --- src/os/macos.rs | 9 +++++++++ src/platform/macos/window.rs | 14 ++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) 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 From 4a36f406a0eeadf3d4af9f746b8dd0d2781aeaf2 Mon Sep 17 00:00:00 2001 From: Tiga Wu Date: Wed, 20 Mar 2019 23:29:13 -0400 Subject: [PATCH 2/2] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8783afba1c..aaa5475a67 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 # Version 0.19.0 (2019-03-06)