From 7f84f44dd8666cb700ff778a9b88f1021036f810 Mon Sep 17 00:00:00 2001 From: David Fuhrmann Date: Fri, 15 Feb 2013 20:19:08 +0100 Subject: [PATCH] macosx: move fullscreen logic to VLCVoutController and remove now unneeded helper methods --- modules/gui/macosx/CoreInteraction.m | 2 +- modules/gui/macosx/VLCVoutWindowController.h | 9 +- modules/gui/macosx/VLCVoutWindowController.m | 116 +++++++++++++------ modules/gui/macosx/intf.h | 2 - modules/gui/macosx/intf.m | 56 +-------- 5 files changed, 87 insertions(+), 98 deletions(-) diff --git a/modules/gui/macosx/CoreInteraction.m b/modules/gui/macosx/CoreInteraction.m index d5d9abbf8d..9dc4c79ce1 100644 --- a/modules/gui/macosx/CoreInteraction.m +++ b/modules/gui/macosx/CoreInteraction.m @@ -622,7 +622,7 @@ static VLCCoreInteraction *_o_sharedInstance = nil; vlc_object_release(p_vout); } else { // e.g. lion fullscreen toggle BOOL b_fs = var_ToggleBool(pl_Get(p_intf), "fullscreen"); - [[VLCMain sharedInstance] setFullscreen:b_fs forWindow:nil]; + [[[VLCMain sharedInstance] voutController] setFullscreen:b_fs forWindow:nil]; } } diff --git a/modules/gui/macosx/VLCVoutWindowController.h b/modules/gui/macosx/VLCVoutWindowController.h index 3071028d5a..c2caab9105 100644 --- a/modules/gui/macosx/VLCVoutWindowController.h +++ b/modules/gui/macosx/VLCVoutWindowController.h @@ -45,16 +45,13 @@ - (VLCVoutView *)setupVoutForWindow:(vout_window_t *)p_wnd withProposedVideoViewPosition:(NSRect)videoViewPosition; - (void)removeVoutforDisplay:(NSValue *)o_key; +- (void)setNativeVideoSize:(NSSize)size forWindow:(vout_window_t *)p_wnd; +- (void)setWindowLevel:(NSInteger)i_level forWindow:(vout_window_t *)p_wnd; +- (void)setFullscreen:(int)i_full forWindow:(vout_window_t *)p_wnd; - (void)updateWindowsControlsBarWithSelector:(SEL)aSel; -- (VLCVideoWindowCommon *)getWindow:(vout_window_t *)p_wnd; - (void)updateWindowsUsingBlock:(void (^)(VLCVideoWindowCommon *o_window))windowUpdater; -- (void)updateWindow:(vout_window_t *)p_wnd withSelector:(SEL)aSel; - -- (void)setNativeVideoSize:(NSSize)size forWindow:(vout_window_t *)p_wnd; -- (void)setWindowLevel:(NSInteger)i_level forWindow:(vout_window_t *)p_wnd; - - (void)updateWindowLevelForHelperWindows:(NSInteger)i_level; @end diff --git a/modules/gui/macosx/VLCVoutWindowController.m b/modules/gui/macosx/VLCVoutWindowController.m index 713b309246..b3e33bb044 100644 --- a/modules/gui/macosx/VLCVoutWindowController.m +++ b/modules/gui/macosx/VLCVoutWindowController.m @@ -53,6 +53,8 @@ [super dealloc]; } +#pragma mark - +#pragma mark Methods for vout provider - (VLCVoutView *)setupVoutForWindow:(vout_window_t *)p_wnd withProposedVideoViewPosition:(NSRect)videoViewPosition { @@ -217,43 +219,6 @@ [[VLCMain sharedInstance] setActiveVideoPlayback:NO]; } -- (void)updateWindowsControlsBarWithSelector:(SEL)aSel -{ - [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - if ([obj respondsToSelector:@selector(controlsBar)]) { - id o_controlsBar = [obj controlsBar]; - if (o_controlsBar) - [o_controlsBar performSelector:aSel]; - } - }]; -} - -- (void)updateWindow:(vout_window_t *)p_wnd withSelector:(SEL)aSel; -{ - VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]]; - if (!o_window) { - msg_Err(VLCIntf, "Cannot call selector for nonexisting window"); - return; - } - - [o_window performSelector:aSel]; -} - -- (VLCVideoWindowCommon *)getWindow:(vout_window_t *)p_wnd -{ - VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]]; - assert(o_window); - return o_window; - -} - -- (void)updateWindowsUsingBlock:(void (^)(VLCVideoWindowCommon *o_window))windowUpdater -{ - [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - if ([obj isKindOfClass: [NSWindow class]]) - windowUpdater(obj); - }]; -} - (void)setNativeVideoSize:(NSSize)size forWindow:(vout_window_t *)p_wnd { @@ -288,6 +253,83 @@ [o_window setWindowLevel:i_level]; } + +- (void)setFullscreen:(int)i_full forWindow:(vout_window_t *)p_wnd +{ + intf_thread_t *p_intf = VLCIntf; + BOOL b_nativeFullscreenMode = [[VLCMain sharedInstance] nativeFullscreenMode]; + + if (!p_intf || (!b_nativeFullscreenMode && !p_wnd)) + return; + playlist_t *p_playlist = pl_Get(p_intf); + BOOL b_fullscreen = i_full; + + if (!var_GetBool(p_playlist, "fullscreen") != !b_fullscreen) + var_SetBool(p_playlist, "fullscreen", b_fullscreen); + + VLCVideoWindowCommon *o_current_window = nil; + if(p_wnd) + o_current_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]]; + + if (b_nativeFullscreenMode) { + if(!o_current_window) + o_current_window = [VLCMainWindow sharedInstance]; + assert(o_current_window); + + // fullscreen might be triggered twice (vout event) + // so ignore duplicate events here + if((b_fullscreen && !([o_current_window fullscreen] || [o_current_window enteringFullscreenTransition])) || + (!b_fullscreen && [o_current_window fullscreen])) { + + [o_current_window toggleFullScreen:self]; + } + + if (b_fullscreen) + [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)]; + else + [NSApp setPresentationOptions:(NSApplicationPresentationDefault)]; + } else { + assert(o_current_window); + + if (b_fullscreen) { + input_thread_t * p_input = pl_CurrentInput(p_intf); + if (p_input != NULL && [[VLCMain sharedInstance] activeVideoPlayback]) { + // activate app, as method can also be triggered from outside the app (prevents nasty window layout) + [NSApp activateIgnoringOtherApps:YES]; + [o_current_window enterFullscreen]; + + } + if (p_input) + vlc_object_release(p_input); + } else { + // leaving fullscreen is always allowed + [o_current_window leaveFullscreen]; + } + } +} + +#pragma mark - +#pragma mark Misc methods + +- (void)updateWindowsControlsBarWithSelector:(SEL)aSel +{ + [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + if ([obj respondsToSelector:@selector(controlsBar)]) { + id o_controlsBar = [obj controlsBar]; + if (o_controlsBar) + [o_controlsBar performSelector:aSel]; + } + }]; +} + +- (void)updateWindowsUsingBlock:(void (^)(VLCVideoWindowCommon *o_window))windowUpdater +{ + [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + if ([obj isKindOfClass: [NSWindow class]]) + windowUpdater(obj); + }]; +} + - (void)updateWindowLevelForHelperWindows:(NSInteger)i_level { if (var_InheritBool(VLCIntf, "video-wallpaper")) diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h index 2551cf65a6..f264d20c1e 100644 --- a/modules/gui/macosx/intf.h +++ b/modules/gui/macosx/intf.h @@ -177,8 +177,6 @@ struct intf_sys_t - (void)updateCurrentlyUsedHotkeys; - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event force:(BOOL)b_force; -- (void)setFullscreen:(int)i_full forWindow:(vout_window_t *)p_wnd; - - (void)PlaylistItemChanged; - (void)playbackStatusUpdated; - (void)sendDistributedNotificationWithUpdatedPlaybackStatus; diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m index 8da95b962f..fcb005ccc4 100644 --- a/modules/gui/macosx/intf.m +++ b/modules/gui/macosx/intf.m @@ -172,8 +172,8 @@ int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg) int i_full = 1; SEL sel = @selector(setFullscreen:forWindow:); - NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[VLCMain sharedInstance] methodSignatureForSelector:sel]]; - [inv setTarget:[VLCMain sharedInstance]]; + NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[[VLCMain sharedInstance] voutController] methodSignatureForSelector:sel]]; + [inv setTarget:[[VLCMain sharedInstance] voutController]]; [inv setSelector:sel]; [inv setArgument:&i_full atIndex:2]; [inv setArgument:&p_wnd atIndex:3]; @@ -236,8 +236,8 @@ static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args) int i_full = va_arg(args, int); SEL sel = @selector(setFullscreen:forWindow:); - NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[VLCMain sharedInstance] methodSignatureForSelector:sel]]; - [inv setTarget:[VLCMain sharedInstance]]; + NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[[VLCMain sharedInstance] voutController] methodSignatureForSelector:sel]]; + [inv setTarget:[[VLCMain sharedInstance] voutController]]; [inv setSelector:sel]; [inv setArgument:&i_full atIndex:2]; // starting at 2! [inv setArgument:&p_wnd atIndex:3]; @@ -1253,54 +1253,6 @@ static VLCMain *_o_sharedMainInstance = nil; #pragma mark - #pragma mark Interface updaters -- (void)setFullscreen:(int)i_full forWindow:(vout_window_t *)p_wnd -{ - if (!p_intf || (!b_nativeFullscreenMode && !p_wnd)) - return; - playlist_t * p_playlist = pl_Get(p_intf); - BOOL b_fullscreen = i_full; - - if (!var_GetBool(p_playlist, "fullscreen") != !b_fullscreen) - var_SetBool(p_playlist, "fullscreen", b_fullscreen); - - if (b_nativeFullscreenMode) { - VLCVideoWindowCommon *o_active_window = nil; - if(p_wnd) - o_active_window = [o_vout_controller getWindow: p_wnd]; - else - o_active_window = o_mainwindow; - - // fullscreen might be triggered twice (vout event) - // so ignore duplicate events here - if((b_fullscreen && !([o_active_window fullscreen] || [o_active_window enteringFullscreenTransition])) || - (!b_fullscreen && [o_active_window fullscreen])) { - - [o_active_window toggleFullScreen:self]; - } - - if (b_fullscreen) - [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)]; - else - [NSApp setPresentationOptions:(NSApplicationPresentationDefault)]; - } else { - assert(p_wnd); - - if (b_fullscreen) { - input_thread_t * p_input = pl_CurrentInput(p_intf); - if (p_input != NULL && [self activeVideoPlayback]) { - // activate app, as method can also be triggered from outside the app (prevents nasty window layout) - [NSApp activateIgnoringOtherApps:YES]; - [o_vout_controller updateWindow:p_wnd withSelector:@selector(enterFullscreen)]; - - } - if (p_input) - vlc_object_release(p_input); - } else { - // leaving fullscreen is always allowed - [o_vout_controller updateWindow:p_wnd withSelector:@selector(leaveFullscreen)]; - } - } -} - (void)PlaylistItemChanged { -- 2.39.2