add macos with_disallow_hidpi (#1073)

* add macos with_disallow_hidpi

add CHANGELOG

* Always use stable rustfmt for CI. (#1074)

Signed-off-by: Hal Gentz <zegentzy@protonmail.com>

* add macos with_disallow_hidpi

add CHANGELOG
This commit is contained in:
t嘎 2019-07-29 16:07:36 +08:00 committed by Hal Gentz
parent 03f9e8fce0
commit f4e9bf51db
3 changed files with 21 additions and 6 deletions

View file

@ -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)

View file

@ -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.

View file

@ -66,6 +66,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub titlebar_buttons_hidden: bool,
pub fullsize_content_view: bool,
pub resize_increments: Option<LogicalSize>,
pub disallow_hidpi: bool,
}
fn create_app(activation_policy: ActivationPolicy) -> Option<id> {
@ -86,10 +87,15 @@ fn create_app(activation_policy: ActivationPolicy) -> Option<id> {
}
}
unsafe fn create_view(ns_window: id) -> Option<(IdRef, Weak<Mutex<util::Cursor>>)> {
unsafe fn create_view(
ns_window: id,
pl_attribs: &PlatformSpecificWindowBuilderAttributes,
) -> Option<(IdRef, Weak<Mutex<util::Cursor>>)> {
let (ns_view, cursor) = new_view(ns_window);
ns_view.non_nil().map(|ns_view| {
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,7 +307,8 @@ impl UnownedWindow {
os_error!(OsError::CreationError("Couldn't create `NSWindow`"))
})?;
let (ns_view, cursor) = unsafe { create_view(*ns_window) }.ok_or_else(|| {
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`"))
})?;