From 6ed36db472ee7717a1c6ace30d770b033ddeb47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 27 Dec 2021 13:00:16 +0000 Subject: [PATCH] Bug 1737831 - Also detect when the screen has a notch and, if so, don't shift by the menubar height either. r=mac-reviewers,mstange This should fix the M1 mac case. Not sure if the SDKDeclarations bits is in the right place, hopefully it is. Differential Revision: https://phabricator.services.mozilla.com/D134632 --- widget/cocoa/SDKDeclarations.h | 5 +++++ widget/cocoa/nsCocoaWindow.mm | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/widget/cocoa/SDKDeclarations.h b/widget/cocoa/SDKDeclarations.h index 242c15eced43..dca3ff66bc94 100644 --- a/widget/cocoa/SDKDeclarations.h +++ b/widget/cocoa/SDKDeclarations.h @@ -118,6 +118,11 @@ AXTextMarkerRef AXTextMarkerRangeCopyStartMarker(AXTextMarkerRangeRef text_marke AXTextMarkerRef AXTextMarkerRangeCopyEndMarker(AXTextMarkerRangeRef text_marker_range); } +@interface NSScreen (NSScreen12_0) +// https://developer.apple.com/documentation/appkit/nsscreen/3882821-safeareainsets?language=objc&changes=latest_major +@property(readonly) NSEdgeInsets safeAreaInsets; +@end + #endif #endif // SDKDefines_h diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index e9f4bc386f8f..1dcb7fc7ac83 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -3686,6 +3686,15 @@ static const NSString* kStateWantsTitleDrawn = @"wantsTitleDrawn"; } } +static bool ScreenHasNotch(nsCocoaWindow* aGeckoWindow) { + if (@available(macOS 12.0, *)) { + nsCOMPtr widgetScreen = aGeckoWindow->GetWidgetScreen(); + NSScreen* cocoaScreen = ScreenHelperCocoa::CocoaScreenForScreen(widgetScreen); + return cocoaScreen.safeAreaInsets.top != 0.0f; + } + return false; +} + - (void)updateTitlebarShownAmount:(CGFloat)aShownAmount { NSInteger styleMask = [self styleMask]; if (!(styleMask & NSWindowStyleMaskFullScreen)) { @@ -3714,7 +3723,7 @@ static const NSString* kStateWantsTitleDrawn = @"wantsTitleDrawn"; // [ToolbarWindow titlebarHeight]. titlebarHeight returns 0 when we're in // fullscreen. CGFloat shiftByPixels = mInitialTitlebarHeight * aShownAmount; - if (!gMenubarAlwaysShownInFullScreen) { + if (!gMenubarAlwaysShownInFullScreen && !ScreenHasNotch(geckoWindow)) { shiftByPixels += mMenuBarHeight * aShownAmount; } // Use mozilla::DesktopToLayoutDeviceScale rather than the