Skip to content

Commit 67a635e

Browse files
authored
Merge pull request #1261 from ychin/non-native-fullscreen-macbook-notch
Fix non-native full screen on MacBooks with notch
2 parents 9fb0163 + db9a083 commit 67a635e

7 files changed

Lines changed: 43 additions & 9 deletions

File tree

runtime/doc/gui_mac.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ KEY VALUE ~
264264
*MMLoginShellCommand* which shell to use to launch Vim [string]
265265
*MMNativeFullScreen* use native full screen mode [bool]
266266
*MMNonNativeFullScreenShowMenu* show menus when in non-native full screen [bool]
267+
*MMNonNativeFullScreenSafeAreaBehavior*
268+
behavior for non-native full sreen regarding
269+
the safe area (aka the "notch") [int]
267270
*MMNoFontSubstitution* disable automatic font substitution [bool]
268271
(Deprecated: Non-CoreText renderer only)
269272
*MMFontPreserveLineSpacing* use the line-spacing as specified by font [bool]
@@ -330,7 +333,10 @@ There are two types of full screen modes. By default, MacVim uses macOS'
330333
native full screen functionality, which creates a separate space in Mission
331334
Control. MacVim also provides a non-native full screen mode, which can be set
332335
by disabling native full screen in the preference panel, or by setting
333-
|MMNativeFullScreen| to `NO` manually.
336+
|MMNativeFullScreen| to `NO` manually. If you have a MacBook with a "notch"
337+
at the top of the screen, you can set |MMNonNativeFullScreenShowMenu| to `NO`
338+
and |MMNonNativeFullScreenSafeAreaBehavior| to 1 to utilitize the whole screen
339+
(this will cause some of the content to be obscured by the notch).
334340

335341
==============================================================================
336342
5. Special colors *macvim-colors*

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5385,6 +5385,7 @@ MMLoginShellCommand gui_mac.txt /*MMLoginShellCommand*
53855385
MMNativeFullScreen gui_mac.txt /*MMNativeFullScreen*
53865386
MMNoFontSubstitution gui_mac.txt /*MMNoFontSubstitution*
53875387
MMNoTitleBarWindow gui_mac.txt /*MMNoTitleBarWindow*
5388+
MMNonNativeFullScreenSafeAreaBehavior gui_mac.txt /*MMNonNativeFullScreenSafeAreaBehavior*
53885389
MMNonNativeFullScreenShowMenu gui_mac.txt /*MMNonNativeFullScreenShowMenu*
53895390
MMShareFindPboard gui_mac.txt /*MMShareFindPboard*
53905391
MMShowAddTabButton gui_mac.txt /*MMShowAddTabButton*

src/MacVim/MMAppController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ + (void)initialize
250250
[NSNumber numberWithBool:YES], MMNativeFullScreenKey,
251251
[NSNumber numberWithDouble:0.0], MMFullScreenFadeTimeKey,
252252
[NSNumber numberWithBool:NO], MMNonNativeFullScreenShowMenuKey,
253+
[NSNumber numberWithInt:0], MMNonNativeFullScreenSafeAreaBehaviorKey,
253254
[NSNumber numberWithBool:YES], MMShareFindPboardKey,
254255
nil];
255256

src/MacVim/MMFullScreenWindow.m

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/MacVim/MacVim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#ifndef MAC_OS_X_VERSION_10_14
3939
# define MAC_OS_X_VERSION_10_14 101400
4040
#endif
41+
#ifndef MAC_OS_VERSION_12_0
42+
# define MAC_OS_VERSION_12_0 120000
43+
#endif
4144

4245
#ifndef NSAppKitVersionNumber10_10
4346
# define NSAppKitVersionNumber10_10 1343

src/MacVim/Miscellaneous.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extern NSString *MMNativeFullScreenKey;
5757
extern NSString *MMUseMouseTimeKey;
5858
extern NSString *MMFullScreenFadeTimeKey;
5959
extern NSString *MMNonNativeFullScreenShowMenuKey;
60+
extern NSString *MMNonNativeFullScreenSafeAreaBehaviorKey;
6061

6162

6263
// Enum for MMUntitledWindowKey

src/MacVim/Miscellaneous.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
NSString *MMUseMouseTimeKey = @"MMUseMouseTime";
5454
NSString *MMFullScreenFadeTimeKey = @"MMFullScreenFadeTime";
5555
NSString *MMNonNativeFullScreenShowMenuKey = @"MMNonNativeFullScreenShowMenu";
56+
NSString *MMNonNativeFullScreenSafeAreaBehaviorKey = @"MMNonNativeFullScreenSafeAreaBehavior";
5657

5758

5859

0 commit comments

Comments
 (0)