From 132fbe14d5e638469248b4dc26528ea45751a51f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 3 Dec 2024 17:19:45 +0100 Subject: [PATCH] macOS: Fix safe area on macOS 10.14 and below (#4028) --- .../apple/appkit/window_delegate.rs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/platform_impl/apple/appkit/window_delegate.rs b/src/platform_impl/apple/appkit/window_delegate.rs index 711535aa72..a43952d0a4 100644 --- a/src/platform_impl/apple/appkit/window_delegate.rs +++ b/src/platform_impl/apple/appkit/window_delegate.rs @@ -980,19 +980,24 @@ impl WindowDelegate { // we've set it up with `additionalSafeAreaInsets`. unsafe { self.view().safeAreaInsets() } } else { - let content_rect = self.window().contentRectForFrameRect(self.window().frame()); - // Includes NSWindowStyleMask::FullSizeContentView - // Convert from window coordinates to view coordinates - let safe_rect = unsafe { - self.view().convertRect_fromView(self.window().contentLayoutRect(), None) + // If `safeAreaInsets` is not available, we'll have to do the calculation ourselves. + + let window_rect = unsafe { + self.window().convertRectFromScreen( + self.window().contentRectForFrameRect(self.window().frame()), + ) }; + // This includes NSWindowStyleMask::FullSizeContentView. + let layout_rect = unsafe { self.window().contentLayoutRect() }; + + // Calculate the insets from window coordinates in AppKit's coordinate system. NSEdgeInsets { - top: safe_rect.origin.y - content_rect.origin.y, - left: safe_rect.origin.x - content_rect.origin.x, - bottom: (content_rect.size.height + content_rect.origin.x) - - (safe_rect.size.height + safe_rect.origin.x), - right: (content_rect.size.width + content_rect.origin.y) - - (safe_rect.size.width + safe_rect.origin.y), + top: (window_rect.size.height + window_rect.origin.y) + - (layout_rect.size.height + layout_rect.origin.y), + left: layout_rect.origin.x - window_rect.origin.x, + bottom: layout_rect.origin.y - window_rect.origin.y, + right: (window_rect.size.width + window_rect.origin.x) + - (layout_rect.size.width + layout_rect.origin.x), } }; let insets = LogicalInsets::new(insets.top, insets.left, insets.bottom, insets.right);