Skip to content

Commit

Permalink
Fix borderless (MMNoTitleBarWindow) mode in pre-Mojave renderers
Browse files Browse the repository at this point in the history
In the legacy renderer, the view gets invalidated frequently in both
non-native fullscreen and no-titlebar modes. Fix no-titlebar mode to
auto-set CGLayer similar to non-native fullscreen so it would work
properly.

This doesn't affect 10.14 Mojave or above as it uses a newer renderer
that doesn't have this issue.

Fix #490
  • Loading branch information
ychin committed Dec 27, 2018
1 parent ff5cec6 commit 559a247
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/MacVim/MMCoreTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
- (NSRect)rectForRow:(int)row column:(int)column numRows:(int)nr
numColumns:(int)nc;
- (void)setCGLayerEnabled:(BOOL)enabled;
- (BOOL)getCGLayerEnabled;

//
// NSTextView methods
Expand Down
5 changes: 5 additions & 0 deletions src/MacVim/MMCoreTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,11 @@ - (void)setCGLayerEnabled:(BOOL)enabled
[self releaseCGLayer];
}

- (BOOL)getCGLayerEnabled
{
return cgLayerEnabled;
}

- (void)releaseCGLayer
{
if (cgLayer) {
Expand Down
3 changes: 3 additions & 0 deletions src/MacVim/MMFullScreenWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
// Controls the speed of the fade in and out.
double fadeTime;
double fadeReservationTime;

// For pre-10.14 we manually sets CGLayer mode, so need to remember the original state
BOOL origCGLayerEnabled;
}

- (MMFullScreenWindow *)initWithWindow:(NSWindow *)t view:(MMVimView *)v
Expand Down
9 changes: 7 additions & 2 deletions src/MacVim/MMFullScreenWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ - (MMFullScreenWindow *)initWithWindow:(NSWindow *)t view:(MMVimView *)v
fadeTime = MIN(fadeTime, 0.5 * (kCGMaxDisplayReservationInterval - 1));
fadeReservationTime = 2.0 * fadeTime + 1;

origCGLayerEnabled = NO;

return self;
}

Expand Down Expand Up @@ -172,8 +174,11 @@ - (void)enterFullScreen
oldPosition = [view frame].origin;

[view removeFromSuperviewWithoutNeedingDisplay];
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12)
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12) {
// This shouldn't do much in 10.14+.
origCGLayerEnabled = [[view textView] getCGLayerEnabled];
[[view textView] setCGLayerEnabled:YES];
}
[[self contentView] addSubview:view];
[self setInitialFirstResponder:[view textView]];

Expand Down Expand Up @@ -289,7 +294,7 @@ - (void)leaveFullScreen
[self close];

if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12)
[[view textView] setCGLayerEnabled:NO];
[[view textView] setCGLayerEnabled:origCGLayerEnabled];

// Set the text view to initial first responder, otherwise the 'plus'
// button on the tabline steals the first responder status.
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
- (void)deleteSign:(NSString *)signName;
- (void)setToolTipAtMousePoint:(NSString *)string;
- (void)setCGLayerEnabled:(BOOL)enabled;
- (BOOL)getCGLayerEnabled;
@end
5 changes: 5 additions & 0 deletions src/MacVim/MMTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ - (void)setCGLayerEnabled:(BOOL)enabled
// ONLY in Core Text!
}

- (BOOL)getCGLayerEnabled
{
return NO;
}

- (BOOL)isOpaque
{
return NO;
Expand Down
9 changes: 9 additions & 0 deletions src/MacVim/MMWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ - (id)initWithVimController:(MMVimController *)controller
// Make us safe on pre-tiger OSX
if ([win respondsToSelector:@selector(_setContentHasShadow:)])
[win _setContentHasShadow:NO];

if (!(styleMask & NSWindowStyleMaskTitled)) {
// In the no titlebar mode (aka borderless), we need to set CGLayer
// mode since otherwise the legacy renderer would not render properly.
// For more reference see MMFullscreenWindow's enterFullscreen:
// This shouldn't do much in 10.14+.
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12)
[[vimView textView] setCGLayerEnabled:YES];
}

#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
// Building on Mac OS X 10.7 or greater.
Expand Down

0 comments on commit 559a247

Please sign in to comment.