1212const CGFloat MinimumTabWidth = 100 ;
1313const CGFloat TabOverlap = 6 ;
1414
15- MMHoverButton* MakeHoverButton (MMTabline *tabline, NSString *imageName, NSString *tooltip, SEL action, BOOL continuous) {
15+ static MMHoverButton* MakeHoverButton (MMTabline *tabline, NSString *imageName, NSString *tooltip, SEL action, BOOL continuous) {
1616 MMHoverButton *button = [MMHoverButton new ];
1717 button.image = [MMHoverButton imageNamed: imageName];
1818 button.translatesAutoresizingMaskIntoConstraints = NO ;
2525 return button;
2626}
2727
28+ static BOOL isDarkMode (NSAppearance *appearance) {
29+ int flags = getCurrentAppearance (appearance);
30+ return (flags == 1 || flags == 3 );
31+ }
32+
2833@implementation MMTabline
2934{
3035 NSView *_tabsContainer;
@@ -185,7 +190,7 @@ - (void)setShowsTabScrollButtons:(BOOL)showsTabScrollButtons
185190
186191- (NSColor *)tablineBgColor
187192{
188- return _tablineBgColor ?: getCurrentAppearance (self.effectiveAppearance )
193+ return _tablineBgColor ?: isDarkMode (self.effectiveAppearance )
189194 ? [NSColor colorWithWhite: 0.2 alpha: 1 ]
190195 : [NSColor colorWithWhite: 0.8 alpha: 1 ];
191196}
@@ -209,7 +214,7 @@ - (void)setTablineFgColor:(NSColor *)color
209214
210215- (NSColor *)tablineSelBgColor
211216{
212- return _tablineSelBgColor ?: getCurrentAppearance (self.effectiveAppearance )
217+ return _tablineSelBgColor ?: isDarkMode (self.effectiveAppearance )
213218 ? [NSColor colorWithWhite: 0.4 alpha: 1 ]
214219 : NSColor .whiteColor ;
215220}
@@ -236,7 +241,7 @@ - (void)setTablineSelFgColor:(NSColor *)color
236241
237242- (NSColor *)tablineFillFgColor
238243{
239- return _tablineFillFgColor ?: getCurrentAppearance (self.effectiveAppearance )
244+ return _tablineFillFgColor ?: isDarkMode (self.effectiveAppearance )
240245 ? [NSColor colorWithWhite: 0.2 alpha: 1 ]
241246 : [NSColor colorWithWhite: 0.8 alpha: 1 ];
242247}
@@ -427,7 +432,7 @@ - (void)fixupTabZOrder
427432- (void )fixupLayoutWithAnimation : (BOOL )shouldAnimate
428433{
429434 if (_tabs.count == 0 ) return ;
430-
435+
431436 TabWidth t = [self tabWidthForTabs: _tabs.count];
432437 for (NSInteger i = 0 ; i < _tabs.count ; i++) {
433438 MMTab *tab = _tabs[i];
@@ -440,8 +445,10 @@ - (void)fixupLayoutWithAnimation:(BOOL)shouldAnimate
440445 context.allowsImplicitAnimation = YES ;
441446 tab.animator .frame = frame;
442447 [tab layout ];
443- }];
444- } else tab.frame = frame;
448+ } completionHandler: nil ];
449+ } else {
450+ tab.frame = frame;
451+ }
445452 }
446453 // _tabsContainer expands to fit tabs, is at least as wide as _scrollView.
447454 NSRect frame = _tabsContainer.frame ;
@@ -597,19 +604,25 @@ - (void)updateTabScrollButtonsEnabledState
597604- (void )scrollTabToVisibleAtIndex : (NSInteger )index
598605{
599606 if (_tabs.count == 0 ) return ;
600-
607+
601608 // Get the amount of time elapsed between the previous invocation
602609 // of this method and now. Use this elapsed time to set the animation
603610 // duration such that rapid invocations of this method result in
604611 // faster animations. For example, the user might hold down the tab
605612 // scrolling buttons (causing them to repeatedly fire) or they might
606613 // rapidly click them.
614+ #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
607615 static NSTimeInterval lastTime = 0 ;
608616 struct timespec t;
609617 clock_gettime (CLOCK_MONOTONIC, &t);
610618 NSTimeInterval currentTime = t.tv_sec + t.tv_nsec * 1 .e -9 ;
611619 NSTimeInterval elapsedTime = currentTime - lastTime;
612620 lastTime = currentTime;
621+ #else
622+ // clock_gettime was only added to macOS 10.12. Just use a fixed value. No
623+ // need to find an alternative API for legacy macOS versions.
624+ NSTimeInterval elapsedTime = 0.1 ;
625+ #endif
613626
614627 NSRect tabFrame = _tabs[index].frame ;
615628 NSRect clipBounds = _scrollView.contentView .bounds ;
0 commit comments