Skip to content

Commit b200f56

Browse files
committed
Fix non-native full screen show menu with notch, and changing resolution
Currently MacVim's "show menu bar" option for non-native full screen does not work properly on newer MacBook's with a notch, as macOS's API for menu bar height for some reason does not return the full height of the menu bar (it only returns the height of the "normal" menu bar). We need to manually use visibleArea instead but that API also has an issue where it's for some reason 1 pixel less, meaning you see a black bar at the top, so we have to hack it to add 1 pixel. This is really not ideal and hopefully Apple fixes it with a new API. Also fix it so changing resolution when MacVim is in non-native full screen will work properly. When working on this, identified an issue that the dock detection logic doesn't really work, as we don't really know if the current screen has the dock visible or not due to lack of API to query it. Just left a comment for future reference.
1 parent 8aa089e commit b200f56

File tree

3 files changed

+61
-19
lines changed

3 files changed

+61
-19
lines changed

runtime/doc/gui_mac.txt

+8-5
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,14 @@ MacVim can be used in full screen mode, see 'fullscreen'.
370370

371371
There are two types of full screen modes. By default, MacVim uses macOS'
372372
native full screen functionality, which creates a separate space in Mission
373-
Control. MacVim also provides a non-native full screen mode, which can be set
374-
by disabling native full screen in the settings panel, or by setting
375-
|MMNativeFullScreen| to `NO` manually. If you have a MacBook with a "notch"
376-
at the top of the screen, you can set |MMNonNativeFullScreenShowMenu| to `NO`
377-
and |MMNonNativeFullScreenSafeAreaBehavior| to 1 to utilitize the whole screen
373+
Control.
374+
375+
MacVim also provides a non-native full screen mode, which can be set by
376+
disabling native full screen in the settings panel (see |MMNativeFullScreen|).
377+
Use 'fuoptions' to configure the background color and whether to maximize the
378+
rows/columns. If you have a MacBook with a camera housing ("notch") at the
379+
top of the screen, you can set |MMNonNativeFullScreenShowMenu| to `NO` and
380+
|MMNonNativeFullScreenSafeAreaBehavior| to 1 to utilitize the whole screen
378381
(this will cause some of the content to be obscured by the notch).
379382

380383
==============================================================================

src/MacVim/MMFullScreenWindow.m

+42-13
Original file line numberDiff line numberDiff line change
@@ -376,29 +376,48 @@ - (void)applicationDidChangeScreenParameters:(NSNotification *)notification
376376
[self setFrame:[screen frame] display:NO];
377377
}
378378

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.
379+
/// Get the view offset to allow us space to show the menu bar, or account for "safe area" (a.k.a.
380+
/// notch) in certain MacBook Pro's.
380381
- (NSEdgeInsets) viewOffset {
381382
NSEdgeInsets offset = NSEdgeInsetsMake(0, 0, 0, 0);
382383

384+
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
385+
const BOOL showMenu = [ud boolForKey:MMNonNativeFullScreenShowMenuKey];
386+
383387
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_12_0)
384388
// Account for newer MacBook Pro's which have a notch, which can be queried using the safe area API.
385389
if (@available(macos 12.0, *)) {
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];
390+
const int safeAreaBehavior = [ud integerForKey:MMNonNativeFullScreenSafeAreaBehaviorKey];
391+
392+
// The safe area utilization is configuration. Right now, we only have two choices:
393+
// - 0: avoid the safe area (default)
394+
// - 1: draw into the safe area, which would cause some contents to be obscured.
395+
// In the future there may be more. E.g. we can draw tabs in the safe area.
396+
// If menu is shown, we ignore this because this doesn't make sense.
397+
if (safeAreaBehavior == 0 || showMenu) {
398+
offset = [self screen].safeAreaInsets;
393399
}
394400
}
395401
#endif
396402

397-
if ([[NSUserDefaults standardUserDefaults]
398-
boolForKey:MMNonNativeFullScreenShowMenuKey]) {
399-
const CGFloat menuBarHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
400-
if (menuBarHeight > offset.top) {
401-
offset.top = menuBarHeight;
403+
if (showMenu) {
404+
// Offset by menu height
405+
if (offset.top == 0) {
406+
const CGFloat menuBarHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
407+
if (menuBarHeight > offset.top) {
408+
offset.top = menuBarHeight;
409+
}
410+
} else {
411+
// Unfortunately, if there is a notch (safe area != 0), menuBarHeight does *not* return
412+
// the menu height shown in the main screen, so we need to calculate it otherwise.
413+
// visibleArea is supposed to give us this information but it's oddly off by one, leading
414+
// to a one-pixel black line, so we need to manually increment it by one. Yes, it sucks.
415+
NSRect visibleFrame = [self screen].visibleFrame;
416+
visibleFrame.size.height += 1;
417+
const CGFloat menuBarHeight = [self screen].frame.size.height - NSMaxY(visibleFrame);
418+
if (menuBarHeight > offset.top) {
419+
offset.top = menuBarHeight;
420+
}
402421
}
403422
}
404423

@@ -482,6 +501,16 @@ - (BOOL)isOnPrimaryScreen
482501
return selfScreenNum == primaryScreenNum;
483502
}
484503

504+
/// Returns true when this screen has a dock and menu shown.
505+
///
506+
/// @note
507+
/// This does not reliably detect whether the dock is on the current screen or
508+
/// not as there is no API to reliably detect this. We are mostly guessing here
509+
/// but if the user sets the dock to display on left/right on a horizontal
510+
/// layout, it may be on the other screen.
511+
/// Also, technically when not using separate spaces, it's possible for the
512+
/// menu to be on one screen and dock on the other.
513+
/// This should be revisited in the future.
485514
- (BOOL)screenHasDockAndMenu
486515
{
487516
return NSScreen.screensHaveSeparateSpaces || [self isOnPrimaryScreen];

src/MacVim/MMWindowController.m

+11-1
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,17 @@ - (void)windowDidResize:(id)sender
12781278
// Calling setFrameSizeKeepGUISize: instead of setFrameSize: prevents a
12791279
// degenerate case where frameSizeMayHaveChanged: ends up resizing the window
12801280
// *again* causing windowDidResize: to be called.
1281-
[vimView setFrameSizeKeepGUISize:[self contentSize]];
1281+
if (fullScreenWindow == nil) {
1282+
[vimView setFrameSizeKeepGUISize:[self contentSize]];
1283+
} else {
1284+
// Non-native full screen mode is more complicated and needs to
1285+
// re-layout the Vim view to properly account for the menu bar / notch,
1286+
// and misc fuopt configuration.
1287+
// This code is similar to what's done in processInputQueueDidFinish.
1288+
NSRect desiredFrame = [fullScreenWindow getDesiredFrame];
1289+
[vimView setFrameOrigin:desiredFrame.origin];
1290+
[vimView setFrameSizeKeepGUISize:desiredFrame.size];
1291+
}
12821292
}
12831293

12841294
- (void)windowDidChangeBackingProperties:(NSNotification *)notification

0 commit comments

Comments
 (0)