macOS: Fix safe area on macOS 10.14 and below (#4028)
This commit is contained in:
parent
164bf85b5b
commit
132fbe14d5
1 changed files with 16 additions and 11 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue