[vlc-commits] [Git][videolan/vlc][master] 4 commits: macosx: Remove unnecessary if statement in NSView extension shouldShowDarkAppearance
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Jan 31 12:31:58 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
5cec39a1 by Claudio Cambra at 2023-01-31T12:14:35+00:00
macosx: Remove unnecessary if statement in NSView extension shouldShowDarkAppearance
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
442e98e4 by Claudio Cambra at 2023-01-31T12:14:35+00:00
macosx: Use effectiveAppearance received from KVO in VLCLibraryCollectionViewItem, fixing bad label text colour update
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
54858910 by Claudio Cambra at 2023-01-31T12:14:35+00:00
macosx: Use effectiveAppearance received from KVO in VLCMediaSourceCollectionViewItem, fixing bad label text colour update
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
5a7b134d by Claudio Cambra at 2023-01-31T12:14:35+00:00
macosx: Check value returned from KVO for effectiveAppearance change in VLCLibraryWindow, rather than checking NSUserDefaults
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
4 changed files:
- modules/gui/macosx/extensions/NSView+VLCAdditions.m
- modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
- modules/gui/macosx/library/VLCLibraryWindow.m
- modules/gui/macosx/library/media-source/VLCMediaSourceCollectionViewItem.m
Changes:
=====================================
modules/gui/macosx/extensions/NSView+VLCAdditions.m
=====================================
@@ -50,10 +50,8 @@
- (BOOL)shouldShowDarkAppearance
{
if (@available(macOS 10.14, *)) {
- if ([self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua] ||
- [self.effectiveAppearance.name isEqualToString:NSAppearanceNameVibrantDark]) {
- return YES;
- }
+ return [self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua] ||
+ [self.effectiveAppearance.name isEqualToString:NSAppearanceNameVibrantDark];
}
return NO;
=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
=====================================
@@ -136,11 +136,11 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
if (@available(macOS 10.14, *)) {
[[NSApplication sharedApplication] addObserver:self
forKeyPath:@"effectiveAppearance"
- options:0
+ options:NSKeyValueObservingOptionNew
context:nil];
}
- [self updateColoredAppearance];
+ [self updateColoredAppearance:self.view.effectiveAppearance];
[self updateFontBasedOnSetting:nil];
[self prepareForReuse];
}
@@ -152,12 +152,21 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
change:(NSDictionary<NSKeyValueChangeKey,id> *)change
context:(void *)context
{
- [self updateColoredAppearance];
+ if ([keyPath isEqualToString:@"effectiveAppearance"]) {
+ NSAppearance *effectiveAppearance = change[NSKeyValueChangeNewKey];
+ [self updateColoredAppearance:effectiveAppearance];
+ }
}
-- (void)updateColoredAppearance
+- (void)updateColoredAppearance:(NSAppearance*)appearance
{
- self.mediaTitleTextField.textColor = self.view.shouldShowDarkAppearance ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor];
+ NSParameterAssert(appearance);
+ BOOL isDark = NO;
+ if (@available(macOS 10.14, *)) {
+ isDark = [appearance.name isEqualToString:NSAppearanceNameDarkAqua] || [appearance.name isEqualToString:NSAppearanceNameVibrantDark];
+ }
+
+ self.mediaTitleTextField.textColor = isDark ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor];
}
- (void)updateFontBasedOnSetting:(NSNotification *)aNotification
=====================================
modules/gui/macosx/library/VLCLibraryWindow.m
=====================================
@@ -188,7 +188,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
if (@available(macOS 10.14, *)) {
[[NSApplication sharedApplication] addObserver:self
forKeyPath:@"effectiveAppearance"
- options:0
+ options:NSKeyValueObservingOptionNew
context:nil];
_mediaToolBar.centeredItemIdentifier = _segmentedTitleControlToolbarItem.itemIdentifier;
@@ -239,10 +239,11 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
self.upNextLabel.font = [NSFont VLClibrarySectionHeaderFont];
self.upNextLabel.stringValue = _NS("Playlist");
- [self updateColorsBasedOnAppearance];
self.openMediaButton.title = _NS("Open media...");
self.dragDropImageBackgroundBox.fillColor = [NSColor VLClibrarySeparatorLightColor];
+ [self updateColorsBasedOnAppearance:self.effectiveAppearance];
+
_mainSplitView.delegate = self;
_lastPlaylistWidthBeforeCollaps = VLCLibraryWindowDefaultPlaylistWidth;
@@ -379,15 +380,24 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
change:(NSDictionary<NSKeyValueChangeKey,id> *)change
context:(void *)context
{
- [self updateColorsBasedOnAppearance];
+ if ([keyPath isEqualToString:@"effectiveAppearance"]) {
+ NSAppearance *effectiveAppearance = change[NSKeyValueChangeNewKey];
+ [self updateColorsBasedOnAppearance:effectiveAppearance];
+ }
}
-- (void)updateColorsBasedOnAppearance
+- (void)updateColorsBasedOnAppearance:(NSAppearance*)appearance
{
+ NSParameterAssert(appearance);
+ BOOL isDark = NO;
+ if (@available(macOS 10.14, *)) {
+ isDark = [appearance.name isEqualToString:NSAppearanceNameDarkAqua] || [appearance.name isEqualToString:NSAppearanceNameVibrantDark];
+ }
+
// If we try to pull the view's effectiveAppearance we are going to get the previous appearance's name despite
// responding to the effectiveAppearance change (???) so it is a better idea to pull from the general system
// theme preference, which is always up-to-date
- if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"] isEqualToString:@"Dark"]) {
+ if (isDark) {
self.upNextLabel.textColor = [NSColor VLClibraryDarkTitleColor];
self.upNextSeparator.borderColor = [NSColor VLClibrarySeparatorDarkColor];
self.clearPlaylistSeparator.borderColor = [NSColor VLClibrarySeparatorDarkColor];
=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceCollectionViewItem.m
=====================================
@@ -81,11 +81,11 @@ NSString *VLCMediaSourceCellIdentifier = @"VLCLibraryCellIdentifier";
if (@available(macOS 10.14, *)) {
[[NSApplication sharedApplication] addObserver:self
forKeyPath:@"effectiveAppearance"
- options:0
+ options:NSKeyValueObservingOptionNew
context:nil];
}
- [self updateColoredAppearance];
+ [self updateColoredAppearance:self.view.effectiveAppearance];
[self updateFontBasedOnSetting:nil];
[self prepareForReuse];
}
@@ -97,12 +97,21 @@ NSString *VLCMediaSourceCellIdentifier = @"VLCLibraryCellIdentifier";
change:(NSDictionary<NSKeyValueChangeKey,id> *)change
context:(void *)context
{
- [self updateColoredAppearance];
+ if ([keyPath isEqualToString:@"effectiveAppearance"]) {
+ NSAppearance *effectiveAppearance = change[NSKeyValueChangeNewKey];
+ [self updateColoredAppearance:effectiveAppearance];
+ }
}
-- (void)updateColoredAppearance
+- (void)updateColoredAppearance:(NSAppearance*)appearance
{
- self.mediaTitleTextField.textColor = self.view.shouldShowDarkAppearance ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor];
+ NSParameterAssert(appearance);
+ BOOL isDark = NO;
+ if (@available(macOS 10.14, *)) {
+ isDark = [appearance.name isEqualToString:NSAppearanceNameDarkAqua] || [appearance.name isEqualToString:NSAppearanceNameVibrantDark];
+ }
+
+ self.mediaTitleTextField.textColor = isDark ? [NSColor VLClibraryDarkTitleColor] : [NSColor VLClibraryLightTitleColor];
}
- (void)updateFontBasedOnSetting:(NSNotification *)aNotification
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0eaa299187c9710a65cf57f7b5a572c323c5dd9e...5a7b134df429e4e079d5d29ac6fa5a97dd14aa62
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0eaa299187c9710a65cf57f7b5a572c323c5dd9e...5a7b134df429e4e079d5d29ac6fa5a97dd14aa62
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list