Skip to content

Fix non-native full screen on MacBooks with notch #1261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion runtime/doc/gui_mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ KEY VALUE ~
*MMLoginShellCommand* which shell to use to launch Vim [string]
*MMNativeFullScreen* use native full screen mode [bool]
*MMNonNativeFullScreenShowMenu* show menus when in non-native full screen [bool]
*MMNonNativeFullScreenSafeAreaBehavior*
behavior for non-native full sreen regarding
the safe area (aka the "notch") [int]
*MMNoFontSubstitution* disable automatic font substitution [bool]
(Deprecated: Non-CoreText renderer only)
*MMFontPreserveLineSpacing* use the line-spacing as specified by font [bool]
Expand Down Expand Up @@ -330,7 +333,10 @@ There are two types of full screen modes. By default, MacVim uses macOS'
native full screen functionality, which creates a separate space in Mission
Control. MacVim also provides a non-native full screen mode, which can be set
by disabling native full screen in the preference panel, or by setting
|MMNativeFullScreen| to `NO` manually.
|MMNativeFullScreen| to `NO` manually. If you have a MacBook with a "notch"
at the top of the screen, you can set |MMNonNativeFullScreenShowMenu| to `NO`
and |MMNonNativeFullScreenSafeAreaBehavior| to 1 to utilitize the whole screen
(this will cause some of the content to be obscured by the notch).

==============================================================================
5. Special colors *macvim-colors*
Expand Down
1 change: 1 addition & 0 deletions runtime/doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -5364,6 +5364,7 @@ MMLoginShellCommand gui_mac.txt /*MMLoginShellCommand*
MMNativeFullScreen gui_mac.txt /*MMNativeFullScreen*
MMNoFontSubstitution gui_mac.txt /*MMNoFontSubstitution*
MMNoTitleBarWindow gui_mac.txt /*MMNoTitleBarWindow*
MMNonNativeFullScreenSafeAreaBehavior gui_mac.txt /*MMNonNativeFullScreenSafeAreaBehavior*
MMNonNativeFullScreenShowMenu gui_mac.txt /*MMNonNativeFullScreenShowMenu*
MMShareFindPboard gui_mac.txt /*MMShareFindPboard*
MMShowAddTabButton gui_mac.txt /*MMShowAddTabButton*
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ + (void)initialize
[NSNumber numberWithBool:YES], MMNativeFullScreenKey,
[NSNumber numberWithDouble:0.0], MMFullScreenFadeTimeKey,
[NSNumber numberWithBool:NO], MMNonNativeFullScreenShowMenuKey,
[NSNumber numberWithInt:0], MMNonNativeFullScreenSafeAreaBehaviorKey,
[NSNumber numberWithBool:YES], MMShareFindPboardKey,
nil];

Expand Down
37 changes: 29 additions & 8 deletions src/MacVim/MMFullScreenWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,33 @@ - (void)applicationDidChangeScreenParameters:(NSNotification *)notification
[self setFrame:[screen frame] display:NO];
}

/// Get the view vertical offset to allow us space to show the menu bar and what not.
- (CGFloat) viewOffset {
/// 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.
- (NSEdgeInsets) viewOffset {
NSEdgeInsets offset = NSEdgeInsetsMake(0, 0, 0, 0);

#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_12_0)
// Account for newer MacBook Pro's which have a notch, which can be queried using the safe area API.
if ([NSScreen instancesRespondToSelector:@selector(safeAreaInsets)]) {
const int safeAreaBehavior = [[NSUserDefaults standardUserDefaults]
integerForKey:MMNonNativeFullScreenSafeAreaBehaviorKey];

// The safe area utilization is configuration. Right now, we only have two choices.
// In the future there may be more, e.g. showing tabs in the safe area.
if (safeAreaBehavior == 0) {
offset = [[self screen] safeAreaInsets];
}
}
#endif

if ([[NSUserDefaults standardUserDefaults]
boolForKey:MMNonNativeFullScreenShowMenuKey]) {
return [[[NSApplication sharedApplication] mainMenu] menuBarHeight]-1;
} else {
return 0;
const CGFloat menuBarHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
if (menuBarHeight > offset.top) {
offset.top = menuBarHeight;
}
}

return offset;
}

/// Returns the desired frame of the Vim view, which takes fuopts into account
Expand All @@ -395,16 +414,18 @@ - (CGFloat) viewOffset {
- (NSRect)getDesiredFrame;
{
NSRect windowFrame = [self frame];
const NSEdgeInsets viewOffset = [self viewOffset];
windowFrame.size.height -= (viewOffset.top + viewOffset.bottom);
windowFrame.size.width -= (viewOffset.left + viewOffset.right);
NSSize desiredFrameSize = windowFrame.size;
desiredFrameSize.height -= [self viewOffset];

if (!(options & FUOPT_MAXVERT))
desiredFrameSize.height = MIN(desiredFrameSize.height, nonFuVimViewSize.height);
if (!(options & FUOPT_MAXHORZ))
desiredFrameSize.width = MIN(desiredFrameSize.width, nonFuVimViewSize.width);

NSPoint origin = { floor((windowFrame.size.width - desiredFrameSize.width)/2),
floor((windowFrame.size.height - desiredFrameSize.height)/2 - [self viewOffset] / 2) };
NSPoint origin = { floor((windowFrame.size.width - desiredFrameSize.width)/2) + viewOffset.left,
floor((windowFrame.size.height - desiredFrameSize.height)/2) + viewOffset.bottom };

return NSMakeRect(origin.x, origin.y, desiredFrameSize.width, desiredFrameSize.height);
}
Expand Down
3 changes: 3 additions & 0 deletions src/MacVim/MacVim.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#ifndef MAC_OS_X_VERSION_10_14
# define MAC_OS_X_VERSION_10_14 101400
#endif
#ifndef MAC_OS_VERSION_12_0
# define MAC_OS_VERSION_12_0 120000
#endif

#ifndef NSAppKitVersionNumber10_10
# define NSAppKitVersionNumber10_10 1343
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/Miscellaneous.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern NSString *MMNativeFullScreenKey;
extern NSString *MMUseMouseTimeKey;
extern NSString *MMFullScreenFadeTimeKey;
extern NSString *MMNonNativeFullScreenShowMenuKey;
extern NSString *MMNonNativeFullScreenSafeAreaBehaviorKey;


// Enum for MMUntitledWindowKey
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/Miscellaneous.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
NSString *MMUseMouseTimeKey = @"MMUseMouseTime";
NSString *MMFullScreenFadeTimeKey = @"MMFullScreenFadeTime";
NSString *MMNonNativeFullScreenShowMenuKey = @"MMNonNativeFullScreenShowMenu";
NSString *MMNonNativeFullScreenSafeAreaBehaviorKey = @"MMNonNativeFullScreenSafeAreaBehavior";



Expand Down