Skip to content

Commit 5502bbf

Browse files
committed
Fixed native fullscreen rendering corruption bug
Fix the issue where MacVim would occasionally draws corrupted image in fullscreen (it would draw mostly black). The easiest way to reproduce this is as follows: 1. Make a new MacVim window, enter fullscreen 2. Open a new tab or hit Cmd-= a few times 3. Switch to another fullscreen app or desktop, click around, then switch back 4. Observe most of the screen is black. The reason this happens is that the MacVim resize code always tries to resize the window to fit the content size (calculated from how many lines / columns we have and whether other elements like tab bar are visible). This means the resize code (resizeWindowToFitContentSize:keepOnScreen:) would make the window smaller than the full size of screen. For some reason, when you switch away from the space, macOS decides to resize the window back to screen size again, causing a window resize event to happen. The resize event invalidates the NSView, causing it to draw black. This is also why fullscreen mode has black bars on top / bottom, which is especially jarring when font size is large of `linespace` is high. The fix is to treat guioptions 'k' to be on when in full screen mode, since the option means we will always try to fit the Vim content inside the window, rather than resize the window to fit the Vim content. This way the fullscreen Vim window will take up the whole screen and won't keep getting resized. This is also more similar to how native Gvim works when maximized. Close #496 (black bars) Close #557, close #674 (full screen rendering issues) A related issue is that MacVim (without CGLayer backing) doesn't actually know how to redraw itself properly when invalidated, which is the root cause of this bug. It receives Vim draw calls incrementally and doesn't actually cache the rendered content, so it relies on the fact that MacVim's NSWindow doesn't usually invalidates all the content which allows it to draw incrementally without needing to perform a full redraw. This is why non-native fullscreen requires CGLayer backing mode as macOS's behavior in this mode (basically a borderless window) is that it does clear the NSWindow's content when setWantsDisplay: is called. This is also why Vim live window resizing is limited to cell size instead of allowing smooth resize (to avoid having to trigger redraws). These are issues that should be fixed later.
1 parent 324ff06 commit 5502bbf

1 file changed

Lines changed: 12 additions & 24 deletions

File tree

src/MacVim/MMWindowController.m

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -599,39 +599,27 @@ - (void)processInputQueueDidFinish
599599
if (!didMaximize) {
600600
NSSize originalSize = [vimView frame].size;
601601
int rows = 0, cols = 0;
602-
NSSize contentSize = [vimView constrainRows:&rows columns:&cols
603-
toSize:
604-
fullScreenWindow ? [fullScreenWindow frame].size :
605-
fullScreenEnabled ? desiredWindowSize :
606-
[self constrainContentSizeToScreenSize:[vimView desiredSize]]];
607602

608603
// Setting 'guioptions+=k' will make shouldKeepGUISize true, which
609604
// means avoid resizing the window. Instead, resize the view instead
610605
// to keep the GUI window's size consistent.
611-
bool avoidWindowResize = shouldKeepGUISize && !fullScreenEnabled;
606+
bool avoidWindowResize = shouldKeepGUISize || fullScreenEnabled;
612607

613608
if (!avoidWindowResize) {
609+
NSSize contentSize = [vimView constrainRows:&rows columns:&cols
610+
toSize:
611+
fullScreenWindow ? [fullScreenWindow frame].size :
612+
fullScreenEnabled ? desiredWindowSize :
613+
[self constrainContentSizeToScreenSize:[vimView desiredSize]]];
614+
614615
[vimView setFrameSize:contentSize];
616+
617+
[self resizeWindowToFitContentSize:contentSize
618+
keepOnScreen:keepOnScreen];
615619
}
616620
else {
617-
[vimView setFrameSizeKeepGUISize:originalSize];
618-
}
619-
620-
if (fullScreenWindow) {
621-
// NOTE! Don't mark the full-screen content view as needing an
622-
// update unless absolutely necessary since when it is updated
623-
// the entire screen is cleared. This may cause some parts of
624-
// the Vim view to be cleared but not redrawn since Vim does
625-
// not realize that we've erased part of the view.
626-
if (!NSEqualSizes(originalSize, contentSize)) {
627-
[[fullScreenWindow contentView] setNeedsDisplay:YES];
628-
[fullScreenWindow centerView];
629-
}
630-
} else {
631-
if (!avoidWindowResize) {
632-
[self resizeWindowToFitContentSize:contentSize
633-
keepOnScreen:keepOnScreen];
634-
}
621+
NSSize frameSize = fullScreenWindow ? [fullScreenWindow frame].size : (fullScreenEnabled ? desiredWindowSize : originalSize);
622+
[vimView setFrameSizeKeepGUISize:frameSize];
635623
}
636624
}
637625

0 commit comments

Comments
 (0)