From c7b61fa39be5b91b7f49a132bbcc3ae49a248468 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 2 Dec 2022 19:54:18 +0100 Subject: [PATCH] Also resize the OpenGL view on macOS This fixes resizing with OpenGL applications. --- src/gl/macos.rs | 9 +++++++++ src/gl/mod.rs | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/gl/macos.rs b/src/gl/macos.rs index 0610879..215dd94 100644 --- a/src/gl/macos.rs +++ b/src/gl/macos.rs @@ -11,6 +11,7 @@ use cocoa::appkit::{ NSOpenGLProfileVersionLegacy, NSOpenGLView, NSView, }; use cocoa::base::{id, nil, YES}; +use cocoa::foundation::NSSize; use core_foundation::base::TCFType; use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName}; @@ -134,6 +135,14 @@ impl GlContext { let () = msg_send![self.view, setNeedsDisplay: YES]; } } + + /// On macOS the `NSOpenGLView` needs to be resized separtely from our main view. + pub(crate) fn resize(&self, size: NSSize) { + unsafe { NSView::setFrameSize(self.view, size) }; + unsafe { + let _: () = msg_send![self.view, setNeedsDisplay: YES]; + } + } } impl Drop for GlContext { diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a7922b7..adfc12d 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -106,4 +106,10 @@ impl GlContext { pub fn swap_buffers(&self) { self.context.swap_buffers(); } + + /// On macOS the `NSOpenGLView` needs to be resized separtely from our main view. + #[cfg(target_os = "macos")] + pub(crate) fn resize(&self, size: cocoa::foundation::NSSize) { + self.context.resize(size); + } }