Skip to content

Fix scrollbars in Mojave dark mode not rendering properly #793

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
Dec 2, 2018
Merged
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
51 changes: 47 additions & 4 deletions src/MacVim/MMVimView.m
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,23 @@ - (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident
- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore
{
[textView setDefaultColorsBackground:back foreground:fore];

CALayer *backedLayer = [self layer];
if (backedLayer) {
// This would only trigger in 10.14 where all views are layer-backed.
//
// Note: This doesn't do much now. Should fix this class to use
// updateLayer: instead of drawRect: at a later time, which would draw
// the background color automatically. When we do that we can remove the
// hack at drawKnobSlotInRect: since it would overlay properly without
// needing to manually draw the background color itself.
[backedLayer setBackgroundColor:[back CGColor]];
}

for (NSUInteger i = 0, count = [scrollbars count]; i < count; ++i) {
MMScroller *sb = [scrollbars objectAtIndex:i];
[sb setNeedsDisplay:YES];
}
}


Expand Down Expand Up @@ -801,10 +818,15 @@ - (void)placeScrollbars
}
}

// HACK: If there is no bottom or right scrollbar the resize indicator will
// cover the bottom-right corner of the text view so tell NSWindow not to
// draw it in this situation.
[[self window] setShowsResizeIndicator:(rightSbVisible||botSbVisible)];
if (NSAppKitVersionNumber < NSAppKitVersionNumber10_7) {
// HACK: If there is no bottom or right scrollbar the resize indicator will
// cover the bottom-right corner of the text view so tell NSWindow not to
// draw it in this situation.
//
// Note: This API is ignored from 10.7 onward and is now deprecated. This
// should be removed if we want to drop support for 10.6.
[[self window] setShowsResizeIndicator:(rightSbVisible||botSbVisible)];
}
}

- (NSUInteger)representedIndexOfTabViewItem:(NSTabViewItem *)tvi
Expand Down Expand Up @@ -973,6 +995,27 @@ - (id)initWithIdentifier:(int32_t)ident type:(int)theType
return self;
}

- (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag
{
// Dark mode scrollbars draw a translucent knob slot overlaid on top of
// whatever background the view has, even when we are using legacy
// scrollbars with a dedicated space. This means we need to draw the
// background with some colors first, or else it would look really black, or
// show through rendering artifacts (e.g. if guioption 'k' is on, and you
// turn off the bar bar, the artiacts will show through in the overlay).
//
// Note: This should ideally be done on MMVimView itself by setting a background
// color. This would be fixed at a later time by telling the view to just
// use the background color form the backed CALayer (mandated since Mojave
// 10.14).
MMVimView *vimView = [self target];
NSColor *defaultBackgroundColor = [[vimView textView] defaultBackgroundColor];
[defaultBackgroundColor setFill];
NSRectFill(slotRect);

[super drawKnobSlotInRect:slotRect highlight:flag];
}

- (int32_t)scrollerId
{
return identifier;
Expand Down