Skip to content

Commit 67754cb

Browse files
authored
Merge pull request #805 from ychin/fix-sierra-transparent-titlebar
Fix 10.12 transparent title bar, and 10.14 'transparency' issues
2 parents f7ff60b + 55197bd commit 67754cb

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed

src/MacVim/MMBackend.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ - (void)enterFullScreen:(int)fuoptions background:(int)bg
11871187
{
11881188
NSMutableData *data = [NSMutableData data];
11891189
[data appendBytes:&fuoptions length:sizeof(int)];
1190-
bg = MM_COLOR(bg);
1190+
bg = MM_COLOR_WITH_TRANSP(bg,p_transp);
11911191
[data appendBytes:&bg length:sizeof(int)];
11921192
[self queueMessage:EnterFullScreenMsgID data:data];
11931193
}

src/MacVim/MMCoreTextView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ - (BOOL)_wantsKeyDownForEvent:(id)event
452452

453453
- (void)setFrameSize:(NSSize)newSize {
454454
if (!NSEqualSizes(newSize, self.bounds.size)) {
455-
if (!drawPending && !cgBufferDrawEnabled) {
455+
if (!drawPending && !cgBufferDrawEnabled && drawData.count == 0) {
456456
// When resizing a window, it will invalidate the buffer and cause
457457
// MacVim to draw black until we get the draw commands from Vim and
458458
// we draw them out in drawRect. Use beginGrouping to stop the

src/MacVim/MMVimView.m

+10-12
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,12 @@ - (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore
497497

498498
CALayer *backedLayer = [self layer];
499499
if (backedLayer) {
500-
// This would only trigger in 10.14 where all views are layer-backed.
501-
//
502-
// Note: This doesn't do much now. Should fix this class to use
503-
// updateLayer: instead of drawRect: at a later time, which would draw
504-
// the background color automatically. When we do that we can remove the
505-
// hack at drawKnobSlotInRect: since it would overlay properly without
506-
// needing to manually draw the background color itself.
507-
[backedLayer setBackgroundColor:[back CGColor]];
500+
// This only happens in 10.14+, where everything is layer-backed by
501+
// default. Since textView draws itself as a separate layer, we don't
502+
// want this layer to draw anything. This is especially important with
503+
// 'transparency' where there's alpha blending and we don't want this
504+
// layer to be in the way and double-blending things.
505+
[backedLayer setBackgroundColor:CGColorGetConstantColor(kCGColorClear)];
508506
}
509507

510508
for (NSUInteger i = 0, count = [scrollbars count]; i < count; ++i) {
@@ -1005,10 +1003,10 @@ - (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag
10051003
// show through rendering artifacts (e.g. if guioption 'k' is on, and you
10061004
// turn off the bar bar, the artiacts will show through in the overlay).
10071005
//
1008-
// Note: This should ideally be done on MMVimView itself by setting a background
1009-
// color. This would be fixed at a later time by telling the view to just
1010-
// use the background color form the backed CALayer (mandated since Mojave
1011-
// 10.14).
1006+
// Note: Another way to fix this is to make sure to draw the underlying
1007+
// MMVimView or the window with the proper color so the scrollbar would just
1008+
// draw on top, but this doesn't work properly right now, and it's difficult
1009+
// to get that to work with the 'transparency' setting as well.
10121010
MMVimView *vimView = [self target];
10131011
NSColor *defaultBackgroundColor = [[vimView textView] defaultBackgroundColor];
10141012
[defaultBackgroundColor setFill];

src/MacVim/MMWindowController.m

+43-3
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,39 @@ - (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore
543543
[decoratedWindow setOpaque:isOpaque];
544544
if (fullScreenWindow)
545545
[fullScreenWindow setOpaque:isOpaque];
546-
[decoratedWindow setBackgroundColor:back];
546+
547+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
548+
if (@available(macos 10.14, *)) {
549+
// We usually don't really need to change the background color of the
550+
// window, but in 10.14+ we switched to using layer-backed drawing.
551+
// That's fine except when we set 'transparency' to non-zero. The alpha
552+
// is set on the text view, but it won't work if drawn on top of a solid
553+
// window, so we need to set a transparency color here to make the
554+
// transparency show through.
555+
if ([back alphaComponent] == 1) {
556+
// Here, any solid color would do, but setting it with "back" has an
557+
// interesting effect where the title bar gets subtly tinted by it
558+
// as well, so do that. (Note that this won't play well in <=10.12
559+
// since we are using the deprecated
560+
// NSWindowStyleMaskTexturedBackground which makes the titlebars
561+
// transparent in those. Consider not using textured background.)
562+
[decoratedWindow setBackgroundColor:back];
563+
if (fullScreenWindow) {
564+
[fullScreenWindow setBackgroundColor:back];
565+
}
566+
} else {
567+
// HACK! We really want a transparent background color to avoid
568+
// double blending the transparency, but setting alpha=0 leads to
569+
// the window border disappearing and also drag-to-resize becomes a
570+
// lot slower. So hack around it by making it virtually transparent.
571+
NSColor *clearColor = [back colorWithAlphaComponent:0.001];
572+
[decoratedWindow setBackgroundColor:clearColor];
573+
if (fullScreenWindow) {
574+
[fullScreenWindow setBackgroundColor:clearColor];
575+
}
576+
}
577+
}
578+
#endif
547579

548580
[vimView setDefaultColorsBackground:back foreground:fore];
549581
}
@@ -758,8 +790,16 @@ - (void)enterFullScreen:(int)fuoptions backgroundColor:(NSColor *)back
758790
// times during startup.
759791
[fullScreenWindow release];
760792

793+
NSColor *fullscreenBg = back;
794+
795+
// See setDefaultColorsBackground: for why set a transparent
796+
// background color, and why 0.001 instead of 0.
797+
if ([fullscreenBg alphaComponent] != 1) {
798+
fullscreenBg = [fullscreenBg colorWithAlphaComponent:0.001];
799+
}
800+
761801
fullScreenWindow = [[MMFullScreenWindow alloc]
762-
initWithWindow:decoratedWindow view:vimView backgroundColor:back];
802+
initWithWindow:decoratedWindow view:vimView backgroundColor:fullscreenBg];
763803
[fullScreenWindow setOptions:fuoptions];
764804
[fullScreenWindow setRepresentedFilename:
765805
[decoratedWindow representedFilename]];
@@ -1544,7 +1584,7 @@ - (void)updateTablineSeparator
15441584
BOOL windowTextured = ([decoratedWindow styleMask] &
15451585
NSWindowStyleMaskTexturedBackground) != 0;
15461586
BOOL hideSeparator = NO;
1547-
1587+
15481588
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_10) {
15491589
// The tabline separator is mostly an old feature and not necessary
15501590
// modern macOS versions.

0 commit comments

Comments
 (0)