vlc | branch: master | Felix Paul Kühne <[email protected]> | Mon Apr 15 19:45:57 2019 +0200| [a3f831632a920220d0625c13467d6dcf81538877] | committer: Felix Paul Kühne
macosx: rework communication between vout provider, library window and fspanel This prevents frequent calls across multiple hierarchy levels and internalizes state knowledge. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a3f831632a920220d0625c13467d6dcf81538877 --- modules/gui/macosx/library/VLCLibraryWindow.h | 9 ++---- modules/gui/macosx/library/VLCLibraryWindow.m | 33 ++++++++++++++-------- modules/gui/macosx/main/VLCMain.h | 2 -- modules/gui/macosx/main/VLCMain.m | 20 +++++-------- .../windows/mainwindow/VLCMainWindowControlsBar.m | 1 - .../macosx/windows/video/VLCFSPanelController.h | 8 ++++-- .../macosx/windows/video/VLCFSPanelController.m | 16 +++++++---- .../macosx/windows/video/VLCVideoOutputProvider.m | 9 +----- .../macosx/windows/video/VLCVideoWindowCommon.h | 3 ++ .../macosx/windows/video/VLCVideoWindowCommon.m | 31 ++++++++++++-------- modules/gui/macosx/windows/video/VLCVoutView.m | 6 ++-- 11 files changed, 73 insertions(+), 65 deletions(-) diff --git a/modules/gui/macosx/library/VLCLibraryWindow.h b/modules/gui/macosx/library/VLCLibraryWindow.h index 6667a6fa06..52e30edbb3 100644 --- a/modules/gui/macosx/library/VLCLibraryWindow.h +++ b/modules/gui/macosx/library/VLCLibraryWindow.h @@ -24,8 +24,6 @@ NS_ASSUME_NONNULL_BEGIN -@class VLCFSPanelController; - @interface VLCLibraryWindowController : NSWindowController - (instancetype)initWithLibraryWindow; @@ -40,12 +38,9 @@ NS_ASSUME_NONNULL_BEGIN @property (readonly) BOOL nativeFullscreenMode; @property (readwrite) BOOL nonembedded; -@property (readonly) VLCFSPanelController* fspanel; -- (void)showFullscreenController; -- (void)changePlaylistState:(int)event; -- (void)videoplayWillBeStarted; -- (void)setVideoplayEnabled; +- (void)videoPlaybackWillBeStarted; +- (void)toggleVideoPlaybackAppearance; - (IBAction)playlistDoubleClickAction:(id)sender; diff --git a/modules/gui/macosx/library/VLCLibraryWindow.m b/modules/gui/macosx/library/VLCLibraryWindow.m index 9ad5953fec..3fadea55a3 100644 --- a/modules/gui/macosx/library/VLCLibraryWindow.m +++ b/modules/gui/macosx/library/VLCLibraryWindow.m @@ -45,6 +45,8 @@ static NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier"; VLCLibraryDataSource *_libraryDataSource; NSRect _windowFrameBeforePlayback; + + VLCFSPanelController *_fspanel; } @end @@ -52,6 +54,12 @@ static NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier"; - (void)awakeFromNib { + NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; + [notificationCenter addObserver:self + selector:@selector(shouldShowFullscreenController:) + name:VLCVideoWindowShouldShowFullscreenController + object:nil]; + _fspanel = [[VLCFSPanelController alloc] init]; [_fspanel showWindow:self]; @@ -81,6 +89,11 @@ static NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier"; [_libraryCollectionView reloadData]; } +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + - (void)segmentedControlAction { } @@ -94,17 +107,13 @@ static NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier"; [[[VLCMain sharedInstance] playlistController] playItemAtIndex:selectedRow]; } -- (void)changePlaylistState:(int)event -{ -} - -- (void)videoplayWillBeStarted +- (void)videoPlaybackWillBeStarted { if (!self.fullscreen) _windowFrameBeforePlayback = [self frame]; } -- (void)setVideoplayEnabled +- (void)toggleVideoPlaybackAppearance { BOOL b_videoPlayback = [[VLCMain sharedInstance] activeVideoPlayback]; @@ -137,10 +146,10 @@ static NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier"; if (self.nativeFullscreenMode) { if ([self hasActiveVideo] && [self fullscreen] && b_videoPlayback) { [self hideControlsBar]; - [self.fspanel setActive]; + [_fspanel shouldBecomeActive:nil]; } else { [self showControlsBar]; - [self.fspanel setNonActive]; + [_fspanel shouldBecomeInactive:nil]; } } } @@ -148,14 +157,14 @@ static NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier"; #pragma mark - #pragma mark Fullscreen support -- (void)showFullscreenController +- (void)shouldShowFullscreenController:(NSNotification *)aNotification { id currentWindow = [NSApp keyWindow]; if ([currentWindow respondsToSelector:@selector(hasActiveVideo)] && [currentWindow hasActiveVideo]) { if ([currentWindow respondsToSelector:@selector(fullscreen)] && [currentWindow fullscreen] && ![[currentWindow videoView] isHidden]) { - - if ([[VLCMain sharedInstance] activeVideoPlayback]) - [self.fspanel fadeIn]; + if ([[VLCMain sharedInstance] activeVideoPlayback]) { + [_fspanel fadeIn]; + } } } diff --git a/modules/gui/macosx/main/VLCMain.h b/modules/gui/macosx/main/VLCMain.h index 5f96f94444..5a51b6ffb1 100644 --- a/modules/gui/macosx/main/VLCMain.h +++ b/modules/gui/macosx/main/VLCMain.h @@ -114,8 +114,6 @@ static NSString * VLCAppleRemoteSettingChangedNotification = @"VLCAppleRemoteSet - (BOOL)activeVideoPlayback; - (void)applicationWillTerminate:(NSNotification *)notification; -- (void)showFullscreenController; - - (BOOL)isTerminating; @end diff --git a/modules/gui/macosx/main/VLCMain.m b/modules/gui/macosx/main/VLCMain.m index 1c65db0f30..5191baf799 100644 --- a/modules/gui/macosx/main/VLCMain.m +++ b/modules/gui/macosx/main/VLCMain.m @@ -143,14 +143,15 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable, @autoreleasepool { dispatch_async(dispatch_get_main_queue(), ^{ - intf_thread_t * p_intf = getIntf(); + intf_thread_t *p_intf = getIntf(); if (p_intf) { VLCMain *mainInstance = [VLCMain sharedInstance]; - if ([[[mainInstance playlistController] playerController] fullscreen]) - [mainInstance showFullscreenController]; - - else if (!strcmp(psz_variable, "intf-show")) + if ([[[mainInstance playlistController] playerController] fullscreen]) { + [[NSNotificationCenter defaultCenter] postNotificationName:VLCVideoWindowShouldShowFullscreenController + object:mainInstance]; + } else if (!strcmp(psz_variable, "intf-show")) { [[mainInstance libraryWindow] makeKeyAndOrderFront:nil]; + } } }); @@ -444,20 +445,13 @@ static VLCMain *sharedInstance = nil; return YES; } -- (void)showFullscreenController -{ - // defer selector here (possibly another time) to ensure that keyWindow is set properly - // (needed for NSApplicationDidBecomeActiveNotification) - [[self libraryWindow] performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO]; -} - - (void)setActiveVideoPlayback:(BOOL)b_value { assert([NSThread isMainThread]); b_active_videoplayback = b_value; if ([self libraryWindow]) { - [[self libraryWindow] setVideoplayEnabled]; + [[self libraryWindow] toggleVideoPlaybackAppearance]; } } diff --git a/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m b/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m index 22e39b5aa3..f2b508e12e 100644 --- a/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m +++ b/modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m @@ -385,7 +385,6 @@ - (IBAction)togglePlaylist:(id)sender { // FIXME: this is a NO-OP - [[[VLCMain sharedInstance] libraryWindow] changePlaylistState: 0]; } - (IBAction)volumeAction:(id)sender diff --git a/modules/gui/macosx/windows/video/VLCFSPanelController.h b/modules/gui/macosx/windows/video/VLCFSPanelController.h index b705f2ef2f..88e65ff9c0 100644 --- a/modules/gui/macosx/windows/video/VLCFSPanelController.h +++ b/modules/gui/macosx/windows/video/VLCFSPanelController.h @@ -30,6 +30,9 @@ #import "views/VLCTimeField.h" #import "views/VLCSlider.h" +extern NSString *VLCFSPanelShouldBecomeActive; +extern NSString *VLCFSPanelShouldBecomeInactive; + @interface VLCFSPanelController : NSWindowController @property (readwrite, weak) NSTimer *hideTimer; @@ -58,11 +61,10 @@ - (IBAction)timeSliderUpdate:(id)sender; - (IBAction)volumeSliderUpdate:(id)sender; +- (void)shouldBecomeInactive:(NSNotification *)aNotification; +- (void)shouldBecomeActive:(NSNotification *)aNotification; - (void)fadeIn; - (void)fadeOut; -- (void)setActive; -- (void)setNonActive; -- (void)setVoutWasUpdated:(VLCWindow *)voutWindow; // Constrain frame to window. Used by VLCFSPanelDraggableView. - (NSRect)contrainFrameToAssociatedVoutWindow:(NSRect)frame; diff --git a/modules/gui/macosx/windows/video/VLCFSPanelController.m b/modules/gui/macosx/windows/video/VLCFSPanelController.m index 0581f1b479..e34f82c56a 100644 --- a/modules/gui/macosx/windows/video/VLCFSPanelController.m +++ b/modules/gui/macosx/windows/video/VLCFSPanelController.m @@ -30,6 +30,10 @@ #import "main/VLCMain.h" #import "playlist/VLCPlaylistController.h" #import "playlist/VLCPlayerController.h" +#import "windows/video/VLCVideoWindowCommon.h" + +NSString *VLCFSPanelShouldBecomeActive = @"VLCFSPanelShouldBecomeActive"; +NSString *VLCFSPanelShouldBecomeInactive = @"VLCFSPanelShouldBecomeInactive"; @interface VLCFSPanelController () { BOOL _isCounting; @@ -56,7 +60,6 @@ static NSString *kAssociatedFullscreenRect = @"VLCFullscreenAssociatedWindowRect [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults]; } - #pragma mark - #pragma mark Initialization @@ -107,6 +110,9 @@ static NSString *kAssociatedFullscreenRect = @"VLCFullscreenAssociatedWindowRect [notificationCenter addObserver:self selector:@selector(hasNextChanged:) name:VLCPlaybackHasNextChanged object:nil]; [notificationCenter addObserver:self selector:@selector(volumeChanged:) name:VLCPlayerVolumeChanged object:nil]; [notificationCenter addObserver:self selector:@selector(inputItemChanged:) name:VLCPlayerCurrentMediaItemChanged object:nil]; + [notificationCenter addObserver:self selector:@selector(shouldBecomeActive:) name:VLCFSPanelShouldBecomeActive object:nil]; + [notificationCenter addObserver:self selector:@selector(shouldBecomeInactive:) name:VLCFSPanelShouldBecomeInactive object:nil]; + [notificationCenter addObserver:self selector:@selector(voutWasUpdated:) name:VLCVideoWindowDidEnterFullscreen object:nil]; } #define setupButton(target, title, desc) \ @@ -440,12 +446,12 @@ static NSString *kAssociatedFullscreenRect = @"VLCFullscreenAssociatedWindowRect return frame; } -- (void)setNonActive +- (void)shouldBecomeInactive:(NSNotification *)aNotification { [self.window orderOut:self]; } -- (void)setActive +- (void)shouldBecomeActive:(NSNotification *)aNotification { [self.window orderFront:self]; [self fadeIn]; @@ -459,8 +465,9 @@ static NSString *kAssociatedFullscreenRect = @"VLCFullscreenAssociatedWindowRect [NSCursor setHiddenUntilMouseMoves:YES]; } -- (void)setVoutWasUpdated:(VLCWindow *)voutWindow +- (void)voutWasUpdated:(NSNotification *)aNotification { + VLCWindow *voutWindow = aNotification.object; _associatedVoutWindow = voutWindow; NSRect voutRect = voutWindow.frame; @@ -470,7 +477,6 @@ static NSString *kAssociatedFullscreenRect = @"VLCFullscreenAssociatedWindowRect [self centerPanel]; } - } #pragma mark - diff --git a/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m b/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m index a31489b7c4..64df32e579 100644 --- a/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m +++ b/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m @@ -227,7 +227,7 @@ int WindowOpen(vout_window_t *p_wnd) // should be called before any window resizing occurs if (!multipleVoutWindows) - [[mainInstance libraryWindow] videoplayWillBeStarted]; + [[mainInstance libraryWindow] videoPlaybackWillBeStarted]; if (multipleVoutWindows && videoWallpaper) videoWallpaper = false; @@ -353,10 +353,6 @@ int WindowOpen(vout_window_t *p_wnd) [mainInstance setActiveVideoPlayback: YES]; [[mainInstance libraryWindow] setNonembedded:!b_mainWindowHasVideo]; - // beware of order, setActiveVideoPlayback:, setHasActiveVideo: and setNonembedded: must be called before - if ([newVideoWindow class] == [VLCLibraryWindow class]) - [[mainInstance libraryWindow] changePlaylistState: 0]; // FIXME: this is a NO-OP - // TODO: find a cleaner way for "start in fullscreen" // Start in fs, because either prefs settings, or fullscreen button was pressed before @@ -425,9 +421,6 @@ int WindowOpen(vout_window_t *p_wnd) // video in main window might get stopped while another vout is open if ([_voutWindows count] > 0) [[mainInstance libraryWindow] setNonembedded:YES]; - - // beware of order, setActiveVideoPlayback:, setHasActiveVideo: and setNonembedded: must be called before - [[mainInstance libraryWindow] changePlaylistState: 0]; // FIXME: this is a NO-OP } } diff --git a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.h b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.h index 08259c39a1..b66bc41e25 100644 --- a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.h +++ b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.h @@ -25,6 +25,9 @@ #import "windows/video/VLCWindow.h" +extern NSString *VLCVideoWindowShouldShowFullscreenController; +extern NSString *VLCVideoWindowDidEnterFullscreen; + @class VLCVoutView; @class VLCControlsBarCommon; diff --git a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m index 7cd7a83c69..e886960a4b 100644 --- a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m +++ b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m @@ -33,6 +33,9 @@ #import "playlist/VLCPlayerController.h" #import "library/VLCLibraryWindow.h" +NSString *VLCVideoWindowShouldShowFullscreenController = @"VLCVideoWindowShouldShowFullscreenController"; +NSString *VLCVideoWindowDidEnterFullscreen = @"VLCVideoWindowDidEnterFullscreen"; + /***************************************************************************** * VLCVideoWindowCommon * @@ -436,17 +439,18 @@ [super becomeKeyWindow]; // change fspanel state for the case when multiple windows are in fullscreen - if ([self hasActiveVideo] && [self fullscreen]) - [[[[VLCMain sharedInstance] libraryWindow] fspanel] setActive]; - else - [[[[VLCMain sharedInstance] libraryWindow] fspanel] setNonActive]; + if ([self hasActiveVideo] && [self fullscreen]) { + [[NSNotificationCenter defaultCenter] postNotificationName:VLCFSPanelShouldBecomeActive object:self]; + } else { + [[NSNotificationCenter defaultCenter] postNotificationName:VLCFSPanelShouldBecomeInactive object:self]; + } } - (void)resignKeyWindow { [super resignKeyWindow]; - [[[[VLCMain sharedInstance] libraryWindow] fspanel] setNonActive]; + [[NSNotificationCenter defaultCenter] postNotificationName:VLCFSPanelShouldBecomeInactive object:self]; } -(NSArray*)customWindowsToEnterFullScreenForWindow:(NSWindow *)window @@ -533,9 +537,11 @@ _inFullscreenTransition = NO; if ([self hasActiveVideo]) { - [[[[VLCMain sharedInstance] libraryWindow] fspanel] setVoutWasUpdated:self]; - if (![_videoView isHidden]) - [[[[VLCMain sharedInstance] libraryWindow] fspanel] setActive]; + NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; + [notificationCenter postNotificationName:VLCVideoWindowDidEnterFullscreen object:self]; + if (![_videoView isHidden]) { + [notificationCenter postNotificationName:VLCFSPanelShouldBecomeActive object:self]; + } } NSArray *subviews = [[self videoView] subviews]; @@ -564,7 +570,7 @@ } [NSCursor setHiddenUntilMouseMoves: NO]; - [[[[VLCMain sharedInstance] libraryWindow] fspanel] setNonActive]; + [[NSNotificationCenter defaultCenter] postNotificationName:VLCFSPanelShouldBecomeInactive object:self]; if (![_videoView isHidden]) { [self showControlsBar]; @@ -742,8 +748,9 @@ [o_fullscreen_window setAcceptsMouseMovedEvents: YES]; /* tell the fspanel to move itself to front next time it's triggered */ - [[[[VLCMain sharedInstance] libraryWindow] fspanel] setVoutWasUpdated:o_fullscreen_window]; - [[[[VLCMain sharedInstance] libraryWindow] fspanel] setActive]; + NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; + [notificationCenter postNotificationName:VLCVideoWindowDidEnterFullscreen object:self]; + [notificationCenter postNotificationName:VLCFSPanelShouldBecomeActive object:self]; if ([self isVisible]) [self orderOut: self]; @@ -768,7 +775,7 @@ return; } - [[[[VLCMain sharedInstance] libraryWindow] fspanel] setNonActive]; + [[NSNotificationCenter defaultCenter] postNotificationName:VLCFSPanelShouldBecomeInactive object:self]; [[o_fullscreen_window screen] setNonFullscreenPresentationOptions]; if (o_fullscreen_anim1) { diff --git a/modules/gui/macosx/windows/video/VLCVoutView.m b/modules/gui/macosx/windows/video/VLCVoutView.m index ed7bfc1cee..4005e1fd3c 100644 --- a/modules/gui/macosx/windows/video/VLCVoutView.m +++ b/modules/gui/macosx/windows/video/VLCVoutView.m @@ -196,8 +196,10 @@ - (void)mouseMoved:(NSEvent *)o_event { NSPoint ml = [self convertPoint: [o_event locationInWindow] fromView: nil]; - if ([self mouse: ml inRect: [self bounds]]) - [[VLCMain sharedInstance] showFullscreenController]; + if ([self mouse: ml inRect: [self bounds]]) { + [[NSNotificationCenter defaultCenter] postNotificationName:VLCVideoWindowShouldShowFullscreenController + object:self]; + } [super mouseMoved: o_event]; } _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
