#import "SideBarItem.h"
#import <math.h>
#import <vlc_playlist.h>
-#import <vlc_aout_intf.h>
#import <vlc_url.h>
#import <vlc_strings.h>
#import <vlc_services_discovery.h>
-#import <vlc_aout_intf.h>
#import "ControlsBar.h"
#import "VideoView.h"
#import "VLCVoutWindowController.h"
-@interface VLCMainWindow ()
+@interface VLCMainWindow (Internal)
- (void)resizePlaylistAfterCollapse;
- (void)makeSplitViewVisible;
- (void)makeSplitViewHidden;
-
+- (void)showPodcastControls;
+- (void)hidePodcastControls;
@end
@implementation VLCMainWindow
+@synthesize fullscreen=b_fullscreen;
+@synthesize nativeFullscreenMode=b_nativeFullscreenMode;
+@synthesize nonembedded=b_nonembedded;
+@synthesize fsPanel=o_fspanel;
+
static VLCMainWindow *_o_sharedInstance = nil;
+ (VLCMainWindow *)sharedInstance
[self setTitle: _NS("VLC media player")];
b_dropzone_active = YES;
- o_temp_view = [[NSView alloc] init];
- [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
[o_dropzone_view setFrame: [o_playlist_table frame]];
[o_left_split_view setFrame: [o_sidebar_view frame]];
nativeVideoSize = screenSize;
[self resizeWindow];
}
+
+ // update fs button to reflect state for next startup
+ if (var_InheritBool(pl_Get(VLCIntf), "fullscreen")) {
+ [o_controls_bar setFullscreenState:YES];
+ }
}
#pragma mark -
} else {
[o_split_view setHidden: NO];
[o_playlist_table setHidden: NO];
- [o_video_view setHidden: !b_activeVideo];
- if (b_activeVideo && [[o_video_view subviews] count] > 0)
- [[o_video_view window] makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
+ [o_video_view setHidden: YES];
}
}
}
aString = [o_url absoluteString];
}
- [self setTitle: aString];
- [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
- [o_window setTitle:aString];
- }];
+ if ([aString length] > 0) {
+ [self setTitle: aString];
+ [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
+ [o_window setTitle:aString];
+ }];
+
+ [o_fspanel setStreamTitle: aString];
+ } else {
+ [self setTitle: _NS("VLC media player")];
+ [self setRepresentedURL: nil];
+ }
- [o_fspanel setStreamTitle: aString];
vlc_object_release(p_input);
} else {
[self setTitle: _NS("VLC media player")];
#pragma mark -
#pragma mark Video Output handling
-- (VLCVoutView *)setupVout:(vout_window_t *)p_wnd
-{
- BOOL b_video_deco = var_InheritBool(VLCIntf, "video-deco");
- BOOL b_video_wallpaper = var_InheritBool(VLCIntf, "video-wallpaper");
- VLCVoutView *o_vout_view;
- VLCVideoWindowCommon *o_new_video_window;
-
- // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
- if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
- // b_video_wallpaper is priorized over !b_video_deco
-
- msg_Dbg(VLCIntf, "Creating background / blank window");
- NSScreen *screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
- if (!screen)
- screen = [self screen];
-
- NSRect window_rect;
- if (b_video_wallpaper)
- window_rect = [screen frame];
- else
- window_rect = [self frame];
-
- NSUInteger mask = NSBorderlessWindowMask;
- if (!OSX_SNOW_LEOPARD && !b_video_deco)
- mask |= NSResizableWindowMask;
-
- BOOL b_no_video_deco_only = !b_video_wallpaper;
- o_new_video_window = [[VLCVideoWindowCommon alloc] initWithContentRect:window_rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
- [o_new_video_window setDelegate:o_new_video_window];
-
- if (b_video_wallpaper)
- [o_new_video_window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey) + 1];
-
- [o_new_video_window setBackgroundColor: [NSColor blackColor]];
- [o_new_video_window setCanBecomeKeyWindow: !b_video_wallpaper];
- [o_new_video_window setCanBecomeMainWindow: !b_video_wallpaper];
- [o_new_video_window setAcceptsMouseMovedEvents: !b_video_wallpaper];
- [o_new_video_window setMovableByWindowBackground: !b_video_wallpaper];
- [o_new_video_window useOptimizedDrawing: YES];
-
- o_vout_view = [[VLCVoutView alloc] initWithFrame:[[o_new_video_window contentView] bounds]];
- [o_vout_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
- [[o_new_video_window contentView] addSubview:o_vout_view positioned:NSWindowAbove relativeTo:nil];
- [o_new_video_window setVideoView:o_vout_view];
-
-
- if (b_video_wallpaper)
- [o_new_video_window orderBack:nil];
- else {
- [o_new_video_window center];
- [o_new_video_window setFrameAutosaveName:@"extra-videowindow"];
- [o_new_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
- }
-
- b_nonembedded = YES;
- } else {
- if (var_InheritBool(VLCIntf, "embedded-video") || b_nativeFullscreenMode) {
- o_vout_view = [o_video_view retain];
- o_new_video_window = self;
- b_nonembedded = NO;
- } else {
- NSWindowController *o_controller = [[NSWindowController alloc] initWithWindowNibName:@"DetachedVideoWindow"];
- [o_controller loadWindow];
- o_new_video_window = [(VLCDetachedVideoWindow *)[o_controller window] retain];
- [o_controller release];
-
- [o_new_video_window setDelegate: o_new_video_window];
- [o_new_video_window setLevel:NSNormalWindowLevel];
- [o_new_video_window useOptimizedDrawing: YES];
- o_vout_view = [[o_new_video_window videoView] retain];
- b_nonembedded = YES;
- }
- }
-
- if (!b_video_wallpaper) {
- [o_new_video_window makeKeyAndOrderFront: self];
-
- vout_thread_t *p_vout = getVout();
- if (p_vout) {
- if (var_GetBool(p_vout, "video-on-top"))
- [o_new_video_window setLevel: NSStatusWindowLevel];
- else
- [o_new_video_window setLevel: NSNormalWindowLevel];
- vlc_object_release(p_vout);
- }
- }
-
- [o_new_video_window setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
- [[[VLCMain sharedInstance] voutController] addVout:o_new_video_window forDisplay:p_wnd];
-
- if(b_nonembedded) {
- // event occurs before window is created, so call again
- [[VLCMain sharedInstance] playbackStatusUpdated];
- }
-
- return [o_vout_view autorelease];
-}
-
- (void)setVideoplayEnabled
{
BOOL b_videoPlayback = [[VLCMain sharedInstance] activeVideoPlayback];
if (b_videoPlayback) {
- frameBeforePlayback = [self frame];
-
- // look for 'start at fullscreen'
- [[VLCMain sharedInstance] fullscreenChanged];
+ if (!b_fullscreen)
+ frameBeforePlayback = [self frame];
} else {
- if (!b_nonembedded)
+ if (!b_nonembedded && !b_fullscreen && frameBeforePlayback.size.width > 0 && frameBeforePlayback.size.height > 0)
[[self animator] setFrame:frameBeforePlayback display:YES];
+ // update fs button to reflect state for next startup
+ if (var_InheritBool(pl_Get(VLCIntf), "fullscreen")) {
+ [o_controls_bar setFullscreenState:YES];
+ }
+
[self makeFirstResponder: nil];
if ([self level] != NSNormalWindowLevel)
if (!b_videoPlayback)
[o_fspanel setNonActive: nil];
}
-
- if (!b_videoPlayback && b_fullscreen) {
- if (!b_nativeFullscreenMode)
- [[VLCCoreInteraction sharedInstance] toggleFullscreen];
- }
}
-
// Called automatically if window's acceptsMouseMovedEvents property is true
- (void)mouseMoved:(NSEvent *)theEvent
{
[NSCursor setHiddenUntilMouseMoves: YES];
}
+
#pragma mark -
#pragma mark Fullscreen support
+
- (void)showFullscreenController
{
if (b_fullscreen && [[VLCMain sharedInstance] activeVideoPlayback])
[o_fspanel fadeIn];
}
-- (BOOL)fullscreen
-{
- return b_fullscreen;
-}
-
-- (void)lockFullscreenAnimation
-{
- [o_animation_lock lock];
-}
-
-- (void)unlockFullscreenAnimation
-{
- [o_animation_lock unlock];
-}
-
-- (void)enterFullscreen
-{
- NSMutableDictionary *dict1, *dict2;
- NSScreen *screen;
- NSRect screen_rect;
- NSRect rect;
- BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
- o_current_video_window = [o_video_view window];
-
- screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
- [self lockFullscreenAnimation];
-
- if (!screen) {
- msg_Dbg(VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode");
- screen = [o_current_video_window screen];
- }
- if (!screen) {
- msg_Dbg(VLCIntf, "Using deepest screen");
- screen = [NSScreen deepestScreen];
- }
-
- screen_rect = [screen frame];
-
- [o_controls_bar setFullscreenState:YES];
- //if (o_detached_video_window)
- // [[o_detached_video_window controlsBar] setFullscreenState:YES];
-
- [self recreateHideMouseTimer];
-
- if (blackout_other_displays)
- [screen blackoutOtherScreens];
-
- /* Make sure we don't see the window flashes in float-on-top mode */
- i_originalLevel = [o_current_video_window level];
- [o_current_video_window setLevel:NSNormalWindowLevel];
-
- /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
- if (!o_fullscreen_window) {
- /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
-
- rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
- rect.origin.x += [o_current_video_window frame].origin.x;
- rect.origin.y += [o_current_video_window frame].origin.y;
- o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
- [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
- [o_fullscreen_window setCanBecomeKeyWindow: YES];
- [o_fullscreen_window setCanBecomeMainWindow: YES];
-
- if (![o_current_video_window isVisible] || [o_current_video_window alphaValue] == 0.0) {
- /* We don't animate if we are not visible, instead we
- * simply fade the display */
- CGDisplayFadeReservationToken token;
-
- if (blackout_other_displays) {
- CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
- CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
- }
-
- if ([screen mainScreen])
- [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
-
- [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
- [o_temp_view setFrame:[o_video_view frame]];
- [o_fullscreen_window setContentView:o_video_view];
-
- [o_fullscreen_window makeKeyAndOrderFront:self];
- [o_fullscreen_window orderFront:self animate:YES];
-
- [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
- [o_fullscreen_window setLevel:NSNormalWindowLevel];
-
- if (blackout_other_displays) {
- CGDisplayFade(token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
- CGReleaseDisplayFadeReservation(token);
- }
-
- /* Will release the lock */
- [self hasBecomeFullscreen];
-
- return;
- }
-
- /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
- NSDisableScreenUpdates();
- [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
- [o_temp_view setFrame:[o_video_view frame]];
- [o_fullscreen_window setContentView:o_video_view];
- [o_fullscreen_window makeKeyAndOrderFront:self];
- NSEnableScreenUpdates();
- }
-
- /* We are in fullscreen (and no animation is running) */
- if (b_fullscreen) {
- /* Make sure we are hidden */
- [o_current_video_window orderOut: self];
-
- [self unlockFullscreenAnimation];
- return;
- }
-
- if (o_fullscreen_anim1) {
- [o_fullscreen_anim1 stopAnimation];
- [o_fullscreen_anim1 release];
- }
- if (o_fullscreen_anim2) {
- [o_fullscreen_anim2 stopAnimation];
- [o_fullscreen_anim2 release];
- }
-
- if ([screen mainScreen])
- [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
-
- dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
- dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
-
- [dict1 setObject:o_current_video_window forKey:NSViewAnimationTargetKey];
- [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
-
- [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
- [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
- [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
-
- /* Strategy with NSAnimation allocation:
- - Keep at most 2 animation at a time
- - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
- */
- o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
- o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
-
- [dict1 release];
- [dict2 release];
-
- [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
- [o_fullscreen_anim1 setDuration: 0.3];
- [o_fullscreen_anim1 setFrameRate: 30];
- [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
- [o_fullscreen_anim2 setDuration: 0.2];
- [o_fullscreen_anim2 setFrameRate: 30];
-
- [o_fullscreen_anim2 setDelegate: self];
- [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
-
- [o_fullscreen_anim1 startAnimation];
- /* fullscreenAnimation will be unlocked when animation ends */
-}
-
-- (void)hasBecomeFullscreen
-{
- if ([[o_video_view subviews] count] > 0)
- [o_fullscreen_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
-
- [o_fullscreen_window makeKeyWindow];
- [o_fullscreen_window setAcceptsMouseMovedEvents: YES];
-
- /* tell the fspanel to move itself to front next time it's triggered */
- [o_fspanel setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
- [o_fspanel setActive: nil];
-
- if ([o_current_video_window isVisible])
- [o_current_video_window orderOut: self];
-
- b_fullscreen = YES;
- [self unlockFullscreenAnimation];
-}
-
-- (void)leaveFullscreen
-{
- [self leaveFullscreenAndFadeOut: NO];
-}
-
-- (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
-{
- NSMutableDictionary *dict1, *dict2;
- NSRect frame;
- BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
-
- if (!o_current_video_window)
- return;
-
- [self lockFullscreenAnimation];
-
- [o_controls_bar setFullscreenState:NO];
- //if (o_detached_video_window)
- // [[o_detached_video_window controlsBar] setFullscreenState:NO];
-
- /* We always try to do so */
- [NSScreen unblackoutScreens];
-
- vout_thread_t *p_vout = getVout();
- if (p_vout) {
- if (var_GetBool(p_vout, "video-on-top"))
- [[o_video_view window] setLevel: NSStatusWindowLevel];
- else
- [[o_video_view window] setLevel: NSNormalWindowLevel];
- vlc_object_release(p_vout);
- }
- [[o_video_view window] makeKeyAndOrderFront: nil];
-
- /* Don't do anything if o_fullscreen_window is already closed */
- if (!o_fullscreen_window) {
- [self unlockFullscreenAnimation];
- return;
- }
-
- if (fadeout) {
- /* We don't animate if we are not visible, instead we
- * simply fade the display */
- CGDisplayFadeReservationToken token;
-
- if (blackout_other_displays) {
- CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
- CGDisplayFade(token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
- }
-
- [o_fspanel setNonActive: nil];
- [NSApp setPresentationOptions: NSApplicationPresentationDefault];
-
- /* Will release the lock */
- [self hasEndedFullscreen];
-
- /* Our window is hidden, and might be faded. We need to workaround that, so note it
- * here */
- b_window_is_invisible = YES;
-
- if (blackout_other_displays) {
- CGDisplayFade(token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
- CGReleaseDisplayFadeReservation(token);
- }
-
- return;
- }
-
- [o_current_video_window setAlphaValue: 0.0];
- [o_current_video_window orderFront: self];
- [[o_video_view window] orderFront: self];
-
- [o_fspanel setNonActive: nil];
- [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
-
- if (o_fullscreen_anim1) {
- [o_fullscreen_anim1 stopAnimation];
- [o_fullscreen_anim1 release];
- }
- if (o_fullscreen_anim2) {
- [o_fullscreen_anim2 stopAnimation];
- [o_fullscreen_anim2 release];
- }
-
- frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
- frame.origin.x += [o_current_video_window frame].origin.x;
- frame.origin.y += [o_current_video_window frame].origin.y;
-
- dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
- [dict2 setObject:o_current_video_window forKey:NSViewAnimationTargetKey];
- [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
-
- o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
- [dict2 release];
-
- [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
- [o_fullscreen_anim2 setDuration: 0.3];
- [o_fullscreen_anim2 setFrameRate: 30];
-
- [o_fullscreen_anim2 setDelegate: self];
-
- dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
-
- [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
- [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
- [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
-
- o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
- [dict1 release];
-
- [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
- [o_fullscreen_anim1 setDuration: 0.2];
- [o_fullscreen_anim1 setFrameRate: 30];
- [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
-
- /* Make sure o_fullscreen_window is the frontmost window */
- [o_fullscreen_window orderFront: self];
-
- [o_fullscreen_anim1 startAnimation];
- /* fullscreenAnimation will be unlocked when animation ends */
-}
-
-- (void)hasEndedFullscreen
-{
- b_fullscreen = NO;
-
- /* This function is private and should be only triggered at the end of the fullscreen change animation */
- /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
- NSDisableScreenUpdates();
- [o_video_view retain];
- [o_video_view removeFromSuperviewWithoutNeedingDisplay];
- [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
- [o_video_view release];
- [o_video_view setFrame:[o_temp_view frame]];
- if ([[o_video_view subviews] count] > 0)
- [[o_video_view window] makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
- if (!b_nonembedded)
- [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
- else
- [[o_video_view window] makeKeyAndOrderFront: self];
- [o_fullscreen_window orderOut: self];
- NSEnableScreenUpdates();
-
- [o_fullscreen_window release];
- o_fullscreen_window = nil;
- [[o_video_view window] setLevel:i_originalLevel];
- [[o_video_view window] setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
-
- // if we quit fullscreen because there is no video anymore, make sure non-embedded window is not visible
- if (![[VLCMain sharedInstance] activeVideoPlayback] && b_nonembedded)
- [o_current_video_window orderOut: self];
-
- o_current_video_window = nil;
- [self unlockFullscreenAnimation];
-}
-
-- (void)animationDidEnd:(NSAnimation*)animation
-{
- NSArray *viewAnimations;
- if (o_makekey_anim == animation) {
- [o_makekey_anim release];
- return;
- }
- if ([animation currentValue] < 1.0)
- return;
-
- /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
- viewAnimations = [o_fullscreen_anim2 viewAnimations];
- if ([viewAnimations count] >=1 &&
- [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
- /* Fullscreen ended */
- [self hasEndedFullscreen];
- } else
- /* Fullscreen started */
- [self hasBecomeFullscreen];
-}
-
- (void)makeKeyAndOrderFront: (id)sender
{
/* Hack
// But this creates some problems when leaving fs over remote intfs, so activate app here.
[NSApp activateIgnoringOtherApps:YES];
- [o_fspanel setVoutWasUpdated: (int)[[self screen] displayID]];
+ [o_fspanel setVoutWasUpdated: self];
[o_fspanel setActive: nil];
}