Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macos with_disallow_hidpi #821

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
9 changes: 9 additions & 0 deletions src/os/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions src/platform/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogicalSize>,
}

Expand Down Expand Up @@ -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] };
Expand Down Expand Up @@ -952,12 +953,17 @@ impl Window2 {
}
}

fn create_view(window: id, shared: Weak<Shared>) -> Option<(IdRef, Weak<Mutex<util::Cursor>>)> {
fn create_view(
window: id,
shared: Weak<Shared>,
pl_attribs: &PlatformSpecificWindowBuilderAttributes
) -> Option<(IdRef, Weak<Mutex<util::Cursor>>)> {
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
Expand Down