macOS: Fix safe area on macOS 10.14 and below (#4028)

This commit is contained in:
Mads Marquart 2024-12-03 17:19:45 +01:00 committed by GitHub
parent 164bf85b5b
commit 132fbe14d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -980,19 +980,24 @@ impl WindowDelegate {
// we've set it up with `additionalSafeAreaInsets`. // we've set it up with `additionalSafeAreaInsets`.
unsafe { self.view().safeAreaInsets() } unsafe { self.view().safeAreaInsets() }
} else { } else {
let content_rect = self.window().contentRectForFrameRect(self.window().frame()); // If `safeAreaInsets` is not available, we'll have to do the calculation ourselves.
// Includes NSWindowStyleMask::FullSizeContentView
// Convert from window coordinates to view coordinates let window_rect = unsafe {
let safe_rect = unsafe { self.window().convertRectFromScreen(
self.view().convertRect_fromView(self.window().contentLayoutRect(), None) 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 { NSEdgeInsets {
top: safe_rect.origin.y - content_rect.origin.y, top: (window_rect.size.height + window_rect.origin.y)
left: safe_rect.origin.x - content_rect.origin.x, - (layout_rect.size.height + layout_rect.origin.y),
bottom: (content_rect.size.height + content_rect.origin.x) left: layout_rect.origin.x - window_rect.origin.x,
- (safe_rect.size.height + safe_rect.origin.x), bottom: layout_rect.origin.y - window_rect.origin.y,
right: (content_rect.size.width + content_rect.origin.y) right: (window_rect.size.width + window_rect.origin.x)
- (safe_rect.size.width + safe_rect.origin.y), - (layout_rect.size.width + layout_rect.origin.x),
} }
}; };
let insets = LogicalInsets::new(insets.top, insets.left, insets.bottom, insets.right); let insets = LogicalInsets::new(insets.top, insets.left, insets.bottom, insets.right);