diff --git a/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h b/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h index cb8fa39164..899d197220 100644 --- a/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h +++ b/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h @@ -45,8 +45,6 @@ @property (readwrite, strong) IBOutlet NSButton *playButton; @property (readwrite, strong) IBOutlet NSButton *backwardButton; @property (readwrite, strong) IBOutlet NSButton *forwardButton; -@property (readwrite, strong) IBOutlet NSButton *repeatButton; -@property (readwrite, strong) IBOutlet NSButton *shuffleButton; @property (readwrite, strong) IBOutlet VLCSlider *timeSlider; @property (readwrite, strong) IBOutlet VLCVolumeSlider *volumeSlider; diff --git a/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m b/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m index 7ac56b68e9..e759a739a2 100644 --- a/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m +++ b/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m @@ -24,7 +24,6 @@ #import "VLCControlsBarCommon.h" #import "extensions/NSString+Helpers.h" -#import "extensions/NSColor+VLCAdditions.h" #import "main/VLCMain.h" #import "playlist/VLCPlaylistController.h" #import "playlist/VLCPlayerController.h" @@ -51,11 +50,6 @@ NSImage *_pressedPauseImage; NSImage *_playImage; NSImage *_pressedPlayImage; - NSImage *_repeatOffImage; - NSImage *_repeatAllImage; - NSImage *_repeatOneImage; - NSImage *_shuffleOffImage; - NSImage *_shuffleOnImage; NSTimeInterval last_fwd_event; NSTimeInterval last_bwd_event; @@ -100,14 +94,6 @@ selector:@selector(fullscreenStateUpdated:) name:VLCPlayerFullscreenChanged object:nil]; - [notificationCenter addObserver:self - selector:@selector(shuffleStateUpdated:) - name:VLCPlaybackOrderChanged - object:nil]; - [notificationCenter addObserver:self - selector:@selector(repeatStateUpdated:) - name:VLCPlaybackRepeatChanged - object:nil]; _nativeFullscreenMode = var_InheritBool(getIntf(), "macosx-nativefullscreenmode"); @@ -191,23 +177,11 @@ [self.forwardButton setAction:@selector(fwd:)]; [self.backwardButton setAction:@selector(bwd:)]; - self.repeatButton.action = @selector(repeatAction:); - self.shuffleButton.action = @selector(shuffleAction:); - [self playerStateUpdated:nil]; - [self repeatStateUpdated:nil]; - [self shuffleStateUpdated:nil]; [_artworkImageView setCropsImagesToRoundedCorners:YES]; [_artworkImageView setImage:[NSImage imageNamed:@"noart"]]; [_artworkImageView setContentGravity:VLCImageViewContentGravityResize]; - - _repeatAllImage = [NSImage imageNamed:@"repeatAll"]; - _repeatOffImage = [NSImage imageNamed:@"repeatOff"]; - _repeatOneImage = [NSImage imageNamed:@"repeatOne"]; - - _shuffleOffImage = [NSImage imageNamed:@"shuffleOff"]; - _shuffleOnImage = [NSImage imageNamed:@"shuffleOn"]; } - (void)dealloc @@ -344,32 +318,6 @@ [_playerController toggleFullscreen]; } -- (IBAction)shuffleAction:(id)sender -{ - if (_playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL) { - _playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM; - } else { - _playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL; - } -} - -- (IBAction)repeatAction:(id)sender -{ - enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat; - switch (currentRepeatState) { - case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL: - _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_NONE; - break; - case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT: - _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_ALL; - break; - - default: - _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT; - break; - } -} - #pragma mark - #pragma mark Updaters @@ -451,40 +399,6 @@ } } -- (void)repeatStateUpdated:(NSNotification *)aNotification -{ - enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat; - - switch (currentRepeatState) { - case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT: - self.repeatButton.image = _repeatOneImage; - break; - case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL: - self.repeatButton.image = _repeatAllImage; - break; - case VLC_PLAYLIST_PLAYBACK_REPEAT_NONE: - default: - self.repeatButton.image = _repeatOffImage; - break; - } - - if (@available(macOS 11.0, *)) { - self.repeatButton.contentTintColor = currentRepeatState == VLC_PLAYLIST_PLAYBACK_REPEAT_NONE ? - nil : [NSColor VLCAccentColor]; - } -} - -- (void)shuffleStateUpdated:(NSNotification *)aNotification -{ - self.shuffleButton.image = _playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL ? - _shuffleOffImage : _shuffleOnImage; - - if (@available(macOS 11.0, *)) { - self.shuffleButton.contentTintColor = _playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL ? - nil : [NSColor VLCAccentColor]; - } -} - - (void)updatePlaybackControls:(NSNotification *)aNotification { bool b_seekable = _playerController.seekable; diff --git a/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.h b/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.h index 1f2cee0a4a..edc9fc942d 100644 --- a/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.h +++ b/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.h @@ -40,6 +40,9 @@ @property (readwrite, strong) IBOutlet NSButton *prevButton; @property (readwrite, strong) IBOutlet NSButton *nextButton; +@property (readwrite, strong) IBOutlet NSButton *repeatButton; +@property (readwrite, strong) IBOutlet NSButton *shuffleButton; + @property (readwrite, strong) IBOutlet NSLayoutConstraint *artistNameTextFieldWidthConstraint; @property (readwrite, strong) IBOutlet NSTextField *songArtistSeparatorTextField; diff --git a/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m b/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m index f6d8825907..6efbfd1e09 100644 --- a/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m +++ b/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m @@ -24,6 +24,7 @@ #import "VLCMainWindowControlsBar.h" #import "VLCControlsBarCommon.h" +#import "extensions/NSColor+VLCAdditions.h" #import "extensions/NSString+Helpers.h" #import "library/VLCInputItem.h" @@ -46,6 +47,12 @@ @interface VLCMainWindowControlsBar() { + NSImage *_repeatOffImage; + NSImage *_repeatAllImage; + NSImage *_repeatOneImage; + NSImage *_shuffleOffImage; + NSImage *_shuffleOnImage; + VLCPlaylistController *_playlistController; VLCPlayerController *_playerController; } @@ -60,8 +67,35 @@ _playerController = _playlistController.playerController; NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; - [notificationCenter addObserver:self selector:@selector(updatePlaybackControls:) name:VLCPlaylistCurrentItemChanged object:nil]; - [notificationCenter addObserver:self selector:@selector(playbackStateChanged:) name:VLCPlayerStateChanged object:nil]; + [notificationCenter addObserver:self + selector:@selector(updatePlaybackControls:) + name:VLCPlaylistCurrentItemChanged + object:nil]; + [notificationCenter addObserver:self + selector:@selector(playbackStateChanged:) + name:VLCPlayerStateChanged + object:nil]; + [notificationCenter addObserver:self + selector:@selector(shuffleStateUpdated:) + name:VLCPlaybackOrderChanged + object:nil]; + [notificationCenter addObserver:self + selector:@selector(repeatStateUpdated:) + name:VLCPlaybackRepeatChanged + object:nil]; + + _repeatAllImage = [NSImage imageNamed:@"repeatAll"]; + _repeatOffImage = [NSImage imageNamed:@"repeatOff"]; + _repeatOneImage = [NSImage imageNamed:@"repeatOne"]; + + _shuffleOffImage = [NSImage imageNamed:@"shuffleOff"]; + _shuffleOnImage = [NSImage imageNamed:@"shuffleOn"]; + + self.repeatButton.action = @selector(repeatAction:); + self.shuffleButton.action = @selector(shuffleAction:); + + [self repeatStateUpdated:nil]; + [self shuffleStateUpdated:nil]; [self.stopButton setToolTip: _NS("Stop")]; self.stopButton.accessibilityLabel = self.stopButton.toolTip; @@ -122,6 +156,32 @@ [[VLCMain sharedInstance].libraryWindow reopenVideoView]; } +- (IBAction)shuffleAction:(id)sender +{ + if (_playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL) { + _playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM; + } else { + _playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL; + } +} + +- (IBAction)repeatAction:(id)sender +{ + enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat; + switch (currentRepeatState) { + case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL: + _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_NONE; + break; + case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT: + _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_ALL; + break; + + default: + _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT; + break; + } +} + #pragma mark - #pragma mark Extra updaters @@ -146,6 +206,40 @@ } } +- (void)repeatStateUpdated:(NSNotification *)aNotification +{ + enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat; + + switch (currentRepeatState) { + case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT: + self.repeatButton.image = _repeatOneImage; + break; + case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL: + self.repeatButton.image = _repeatAllImage; + break; + case VLC_PLAYLIST_PLAYBACK_REPEAT_NONE: + default: + self.repeatButton.image = _repeatOffImage; + break; + } + + if (@available(macOS 11.0, *)) { + self.repeatButton.contentTintColor = currentRepeatState == VLC_PLAYLIST_PLAYBACK_REPEAT_NONE ? + nil : [NSColor VLCAccentColor]; + } +} + +- (void)shuffleStateUpdated:(NSNotification *)aNotification +{ + self.shuffleButton.image = _playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL ? + _shuffleOffImage : _shuffleOnImage; + + if (@available(macOS 11.0, *)) { + self.shuffleButton.contentTintColor = _playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL ? + nil : [NSColor VLCAccentColor]; + } +} + - (void)updatePlaybackControls:(NSNotification *)aNotification { bool b_seekable = _playerController.seekable;