[vlc-commits] macosx: add helper for the Mojave dark mode

Felix Paul Kühne git at videolan.org
Tue May 7 12:58:24 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Tue May  7 12:55:56 2019 +0200| [62186521264a021bfda172db9b679bfb6d14872e] | committer: Felix Paul Kühne

macosx: add helper for the Mojave dark mode

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=62186521264a021bfda172db9b679bfb6d14872e
---

 modules/gui/macosx/extensions/NSView+VLCAdditions.h      |  2 ++
 modules/gui/macosx/extensions/NSView+VLCAdditions.m      | 13 +++++++++++++
 .../gui/macosx/library/VLCLibraryCollectionViewItem.m    | 12 ++----------
 .../VLCLibraryCollectionViewSupplementaryElementView.m   | 12 +++---------
 modules/gui/macosx/library/VLCLibraryWindow.m            | 16 +++++-----------
 modules/gui/macosx/main/CompatibilityFixes.h             |  6 ++++++
 modules/gui/macosx/views/VLCBottomBarView.m              | 12 +++---------
 modules/gui/macosx/views/VLCSlider.m                     | 11 +++++------
 modules/gui/macosx/views/VLCVolumeSlider.m               | 12 +++++-------
 9 files changed, 44 insertions(+), 52 deletions(-)

diff --git a/modules/gui/macosx/extensions/NSView+VLCAdditions.h b/modules/gui/macosx/extensions/NSView+VLCAdditions.h
index a97ad3c76f..2478345d72 100644
--- a/modules/gui/macosx/extensions/NSView+VLCAdditions.h
+++ b/modules/gui/macosx/extensions/NSView+VLCAdditions.h
@@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface NSView (VLCAdditions)
 
+ at property (readonly) BOOL shouldShowDarkAppearance;
+
 - (void)enableSubviews:(BOOL)enabled;
 
 @end
diff --git a/modules/gui/macosx/extensions/NSView+VLCAdditions.m b/modules/gui/macosx/extensions/NSView+VLCAdditions.m
index 2609f0bd4f..702016e154 100644
--- a/modules/gui/macosx/extensions/NSView+VLCAdditions.m
+++ b/modules/gui/macosx/extensions/NSView+VLCAdditions.m
@@ -23,8 +23,21 @@
 
 #import "NSView+VLCAdditions.h"
 
+#import "main/CompatibilityFixes.h"
+
 @implementation NSView (VLCAdditions)
 
+- (BOOL)shouldShowDarkAppearance
+{
+    if (@available(macOS 10_14, *)) {
+        if ([self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua]) {
+            return YES;
+        }
+    }
+
+    return NO;
+}
+
 - (void)enableSubviews:(BOOL)enabled
 {
     for (NSView *view in [self subviews]) {
diff --git a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
index a11560555f..58cf601b96 100644
--- a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
+++ b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
@@ -23,7 +23,6 @@
 #import "VLCLibraryCollectionViewItem.h"
 
 #import "main/VLCMain.h"
-#import "main/CompatibilityFixes.h"
 #import "library/VLCLibraryController.h"
 #import "library/VLCLibraryDataTypes.h"
 #import "library/VLCLibraryModel.h"
@@ -33,6 +32,7 @@
 #import "extensions/NSString+Helpers.h"
 #import "extensions/NSFont+VLCAdditions.h"
 #import "extensions/NSColor+VLCAdditions.h"
+#import "extensions/NSView+VLCAdditions.h"
 
 NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier";
 
@@ -96,15 +96,7 @@ NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier";
 
 - (void)updateColoredAppearance
 {
-    if (@available(macOS 10_14, *)) {
-        if ([self.view.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua]) {
-            self.mediaTitleTextField.textColor = [NSColor VLClibraryDarkTitleColor];
-        } else {
-            self.mediaTitleTextField.textColor = [NSColor VLClibraryLightTitleColor];
-        }
-    } else {
-        self.mediaTitleTextField.textColor = [NSColor VLClibraryLightTitleColor];
-    }
+    self.mediaTitleTextField.textColor = self.view.shouldShowDarkAppearance ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor];
 }
 
 #pragma mark - view representation
diff --git a/modules/gui/macosx/library/VLCLibraryCollectionViewSupplementaryElementView.m b/modules/gui/macosx/library/VLCLibraryCollectionViewSupplementaryElementView.m
index 9ce0a78e78..d651cf2f08 100644
--- a/modules/gui/macosx/library/VLCLibraryCollectionViewSupplementaryElementView.m
+++ b/modules/gui/macosx/library/VLCLibraryCollectionViewSupplementaryElementView.m
@@ -23,7 +23,7 @@
 #import "VLCLibraryCollectionViewSupplementaryElementView.h"
 #import "extensions/NSFont+VLCAdditions.h"
 #import "extensions/NSColor+VLCAdditions.h"
-#import "main/CompatibilityFixes.h"
+#import "extensions/NSView+VLCAdditions.h"
 
 NSString *VLCLibrarySupplementaryElementViewIdentifier = @"VLCLibrarySupplementaryElementViewIdentifier";
 
@@ -39,11 +39,7 @@ NSString *VLCLibrarySupplementaryElementViewIdentifier = @"VLCLibrarySupplementa
     self = [super initWithFrame:frameRect];
     if (self) {
         self.font = [NSFont VLClibrarySectionHeaderFont];
-        if (@available(macOS 10_14, *)) {
-            self.textColor = [self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua] ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor];
-        } else {
-            self.textColor = [NSColor VLClibraryLightTitleColor];
-        }
+        self.textColor = self.shouldShowDarkAppearance ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor];
         self.editable = NO;
         self.selectable = NO;
     }
@@ -52,9 +48,7 @@ NSString *VLCLibrarySupplementaryElementViewIdentifier = @"VLCLibrarySupplementa
 
 - (void)viewDidChangeEffectiveAppearance
 {
-    if (@available(macOS 10_14, *)) {
-        self.textColor = [self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua] ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor];
-    }
+    self.textColor = self.shouldShowDarkAppearance ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor];
 }
 
 @end
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.m b/modules/gui/macosx/library/VLCLibraryWindow.m
index baf282b4d5..479192ef22 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.m
+++ b/modules/gui/macosx/library/VLCLibraryWindow.m
@@ -24,8 +24,8 @@
 #import "extensions/NSString+Helpers.h"
 #import "extensions/NSFont+VLCAdditions.h"
 #import "extensions/NSColor+VLCAdditions.h"
+#import "extensions/NSView+VLCAdditions.h"
 #import "main/VLCMain.h"
-#import "main/CompatibilityFixes.h"
 
 #import "playlist/VLCPlaylistTableCellView.h"
 #import "playlist/VLCPlaylistController.h"
@@ -187,16 +187,10 @@ static const float f_playlist_row_height = 72.;
 
 - (void)updateColorsBasedOnAppearance
 {
-    if (@available(macOS 10_14, *)) {
-        if ([self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua]) {
-            self.upNextLabel.textColor = [NSColor VLClibraryDarkTitleColor];
-            self.upNextSeparator.borderColor = [NSColor VLClibrarySeparatorDarkColor];
-            self.clearPlaylistSeparator.borderColor = [NSColor VLClibrarySeparatorDarkColor];
-        } else {
-            self.upNextLabel.textColor = [NSColor VLClibraryLightTitleColor];
-            self.upNextSeparator.borderColor = [NSColor VLClibrarySeparatorLightColor];
-            self.clearPlaylistSeparator.borderColor = [NSColor VLClibrarySeparatorLightColor];
-        }
+    if (self.contentView.shouldShowDarkAppearance) {
+        self.upNextLabel.textColor = [NSColor VLClibraryDarkTitleColor];
+        self.upNextSeparator.borderColor = [NSColor VLClibrarySeparatorDarkColor];
+        self.clearPlaylistSeparator.borderColor = [NSColor VLClibrarySeparatorDarkColor];
     } else {
         self.upNextLabel.textColor = [NSColor VLClibraryLightTitleColor];
         self.upNextSeparator.borderColor = [NSColor VLClibrarySeparatorLightColor];
diff --git a/modules/gui/macosx/main/CompatibilityFixes.h b/modules/gui/macosx/main/CompatibilityFixes.h
index 85f4bf2c52..e0a2eba8f3 100644
--- a/modules/gui/macosx/main/CompatibilityFixes.h
+++ b/modules/gui/macosx/main/CompatibilityFixes.h
@@ -34,4 +34,10 @@ extern NSString *const NSAppearanceNameDarkAqua;
 
 #endif
 
+#ifndef MAC_OS_X_VERSION_10_13
+
+extern NSString *const NSCollectionViewSupplementaryElementKind;
+
+#endif
+
 NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/views/VLCBottomBarView.m b/modules/gui/macosx/views/VLCBottomBarView.m
index 08c66456d7..6cedad9280 100644
--- a/modules/gui/macosx/views/VLCBottomBarView.m
+++ b/modules/gui/macosx/views/VLCBottomBarView.m
@@ -23,7 +23,7 @@
 
 #import "VLCBottomBarView.h"
 
-#import "main/CompatibilityFixes.h"
+#import "extensions/NSView+VLCAdditions.h"
 
 @interface VLCBottomBarView () {
     NSBezierPath *_rectanglePath;
@@ -141,14 +141,8 @@
 
 - (void)viewDidChangeEffectiveAppearance
 {
-    if (@available(macOS 10_14, *)) {
-        if ([self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua])
-            [self setDark:YES];
-        else
-            [self setDark:NO];
-
-        [self setNeedsDisplay:YES];
-    }
+    [self setDark:self.shouldShowDarkAppearance];
+    [self setNeedsDisplay:YES];
 }
 
 @end
diff --git a/modules/gui/macosx/views/VLCSlider.m b/modules/gui/macosx/views/VLCSlider.m
index 1c44e08c3c..310abe8ffb 100644
--- a/modules/gui/macosx/views/VLCSlider.m
+++ b/modules/gui/macosx/views/VLCSlider.m
@@ -22,7 +22,7 @@
 
 #import "VLCSlider.h"
 
-#import "main/CompatibilityFixes.h"
+#import "extensions/NSView+VLCAdditions.h"
 #import "views/VLCSliderCell.h"
 
 @implementation VLCSlider
@@ -117,11 +117,10 @@
 
 - (void)viewDidChangeEffectiveAppearance
 {
-    if (@available(macOS 10_14, *)) {
-        if ([self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua])
-            [self setSliderStyleDark];
-        else
-            [self setSliderStyleLight];
+    if (self.shouldShowDarkAppearance) {
+        [self setSliderStyleDark];
+    } else {
+        [self setSliderStyleLight];
     }
 }
 
diff --git a/modules/gui/macosx/views/VLCVolumeSlider.m b/modules/gui/macosx/views/VLCVolumeSlider.m
index 1f8ebb7f2f..58162f00aa 100644
--- a/modules/gui/macosx/views/VLCVolumeSlider.m
+++ b/modules/gui/macosx/views/VLCVolumeSlider.m
@@ -22,7 +22,7 @@
 
 #import "VLCVolumeSlider.h"
 
-#import "main/CompatibilityFixes.h"
+#import "extensions/NSView+VLCAdditions.h"
 #import "views/VLCVolumeSliderCell.h"
 
 @implementation VLCVolumeSlider
@@ -56,12 +56,10 @@
 
 - (void)viewDidChangeEffectiveAppearance
 {
-    if (@available(macOS 10_14, *)) {
-        if ([self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua]) {
-            [(VLCVolumeSliderCell*)self.cell setSliderStyleDark];
-        } else {
-            [(VLCVolumeSliderCell*)self.cell setSliderStyleLight];
-        }
+    if (self.shouldShowDarkAppearance) {
+        [(VLCVolumeSliderCell*)self.cell setSliderStyleDark];
+    } else {
+        [(VLCVolumeSliderCell*)self.cell setSliderStyleLight];
     }
 }
 



More information about the vlc-commits mailing list