@@ -376,14 +376,33 @@ - (void)applicationDidChangeScreenParameters:(NSNotification *)notification
376376 [self setFrame: [screen frame ] display: NO ];
377377}
378378
379- // / Get the view vertical offset to allow us space to show the menu bar and what not.
380- - (CGFloat) viewOffset {
379+ // / Get the view offset to allow us space to show the menu bar, or account for "safe area" (a.k.a. notch) in certain MacBook Pro's.
380+ - (NSEdgeInsets ) viewOffset {
381+ NSEdgeInsets offset = NSEdgeInsetsMake (0 , 0 , 0 , 0 );
382+
383+ #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_12_0)
384+ // Account for newer MacBook Pro's which have a notch, which can be queried using the safe area API.
385+ if ([NSScreen instancesRespondToSelector: @selector (safeAreaInsets )]) {
386+ const int safeAreaBehavior = [[NSUserDefaults standardUserDefaults ]
387+ integerForKey: MMNonNativeFullScreenSafeAreaBehaviorKey];
388+
389+ // The safe area utilization is configuration. Right now, we only have two choices.
390+ // In the future there may be more, e.g. showing tabs in the safe area.
391+ if (safeAreaBehavior == 0 ) {
392+ offset = [[self screen ] safeAreaInsets ];
393+ }
394+ }
395+ #endif
396+
381397 if ([[NSUserDefaults standardUserDefaults ]
382398 boolForKey: MMNonNativeFullScreenShowMenuKey]) {
383- return [[[NSApplication sharedApplication ] mainMenu ] menuBarHeight ]-1 ;
384- } else {
385- return 0 ;
399+ const CGFloat menuBarHeight = [[[NSApplication sharedApplication ] mainMenu ] menuBarHeight ];
400+ if (menuBarHeight > offset.top ) {
401+ offset.top = menuBarHeight;
402+ }
386403 }
404+
405+ return offset;
387406}
388407
389408// / Returns the desired frame of the Vim view, which takes fuopts into account
@@ -395,16 +414,18 @@ - (CGFloat) viewOffset {
395414- (NSRect )getDesiredFrame ;
396415{
397416 NSRect windowFrame = [self frame ];
417+ const NSEdgeInsets viewOffset = [self viewOffset ];
418+ windowFrame.size .height -= (viewOffset.top + viewOffset.bottom );
419+ windowFrame.size .width -= (viewOffset.left + viewOffset.right );
398420 NSSize desiredFrameSize = windowFrame.size ;
399- desiredFrameSize.height -= [self viewOffset ];
400421
401422 if (!(options & FUOPT_MAXVERT))
402423 desiredFrameSize.height = MIN (desiredFrameSize.height , nonFuVimViewSize.height );
403424 if (!(options & FUOPT_MAXHORZ))
404425 desiredFrameSize.width = MIN (desiredFrameSize.width , nonFuVimViewSize.width );
405426
406- NSPoint origin = { floor ((windowFrame.size .width - desiredFrameSize.width )/2 ),
407- floor ((windowFrame.size .height - desiredFrameSize.height )/2 - [ self viewOffset ] / 2 ) };
427+ NSPoint origin = { floor ((windowFrame.size .width - desiredFrameSize.width )/2 ) + viewOffset. left ,
428+ floor ((windowFrame.size .height - desiredFrameSize.height )/2 ) + viewOffset. bottom };
408429
409430 return NSMakeRect (origin.x , origin.y , desiredFrameSize.width , desiredFrameSize.height );
410431}
0 commit comments