diff --git a/CHANGELOG.md b/CHANGELOG.md index c91fbe43..a0eece88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - On macOS, drop the run closure on exit. - On Windows, location of `WindowEvent::Touch` are window client coordinates instead of screen coordinates. - On X11, fix delayed events after window redraw. +- On macOS, add `WindowBuilderExt::with_disallow_hidpi` to have the option to turn off best resolution openGL surface. # 0.20.0 Alpha 2 (2019-07-09) diff --git a/src/platform/macos.rs b/src/platform/macos.rs index f08c774b..8101f0f7 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -129,6 +129,7 @@ pub trait WindowBuilderExtMacOS { 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; + fn with_disallow_hidpi(self, disallow_hidpi: bool) -> WindowBuilder; } impl WindowBuilderExtMacOS for WindowBuilder { @@ -182,6 +183,12 @@ impl WindowBuilderExtMacOS 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 `MonitorHandle` that are specific to MacOS. diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 4f6bf255..a99e7f6c 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -66,6 +66,7 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub titlebar_buttons_hidden: bool, pub fullsize_content_view: bool, pub resize_increments: Option, + pub disallow_hidpi: bool, } fn create_app(activation_policy: ActivationPolicy) -> Option { @@ -86,10 +87,15 @@ fn create_app(activation_policy: ActivationPolicy) -> Option { } } -unsafe fn create_view(ns_window: id) -> Option<(IdRef, Weak>)> { +unsafe fn create_view( + ns_window: id, + pl_attribs: &PlatformSpecificWindowBuilderAttributes, +) -> Option<(IdRef, Weak>)> { let (ns_view, cursor) = new_view(ns_window); ns_view.non_nil().map(|ns_view| { - ns_view.setWantsBestResolutionOpenGLSurface_(YES); + if !pl_attribs.disallow_hidpi { + ns_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 @@ -301,10 +307,11 @@ impl UnownedWindow { os_error!(OsError::CreationError("Couldn't create `NSWindow`")) })?; - let (ns_view, cursor) = unsafe { create_view(*ns_window) }.ok_or_else(|| { - unsafe { pool.drain() }; - os_error!(OsError::CreationError("Couldn't create `NSView`")) - })?; + let (ns_view, cursor) = + unsafe { create_view(*ns_window, &pl_attribs) }.ok_or_else(|| { + unsafe { pool.drain() }; + os_error!(OsError::CreationError("Couldn't create `NSView`")) + })?; let input_context = unsafe { util::create_input_context(*ns_view) };