1 /*****************************************************************************
2 * Windows.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2012 VLC authors and VideoLAN
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8 * David Fuhrmann <david dot fuhrmann at googlemail dot com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
27 #import "CoreInteraction.h"
28 #import "ControlsBar.h"
31 /*****************************************************************************
34 * Missing extension to NSWindow
35 *****************************************************************************/
37 @implementation VLCWindow
39 @synthesize hasActiveVideo=b_has_active_video;
40 @synthesize fullscreen=b_fullscreen;
42 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
43 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
45 self = [super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag];
47 /* we don't want this window to be restored on relaunch */
48 if (!OSX_SNOW_LEOPARD)
49 [self setRestorable:NO];
54 - (void)setCanBecomeKeyWindow: (BOOL)canBecomeKey
56 b_isset_canBecomeKeyWindow = YES;
57 b_canBecomeKeyWindow = canBecomeKey;
60 - (BOOL)canBecomeKeyWindow
62 if (b_isset_canBecomeKeyWindow)
63 return b_canBecomeKeyWindow;
65 return [super canBecomeKeyWindow];
68 - (void)setCanBecomeMainWindow: (BOOL)canBecomeMain
70 b_isset_canBecomeMainWindow = YES;
71 b_canBecomeMainWindow = canBecomeMain;
74 - (BOOL)canBecomeMainWindow
76 if (b_isset_canBecomeMainWindow)
77 return b_canBecomeMainWindow;
79 return [super canBecomeMainWindow];
82 - (void)closeAndAnimate: (BOOL)animate
91 invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(close)]];
92 [invoc setTarget: self];
94 if (![self isVisible] || [self alphaValue] == 0.0) {
99 [self orderOut: self animate: YES callback: invoc];
102 - (void)orderOut: (id)sender animate: (BOOL)animate
104 NSInvocation *invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(orderOut:)]];
105 [invoc setTarget: self];
106 [invoc setArgument: sender atIndex: 0];
107 [self orderOut: sender animate: animate callback: invoc];
110 - (void)orderOut: (id)sender animate: (BOOL)animate callback:(NSInvocation *)callback
112 NSViewAnimation *anim;
113 NSViewAnimation *current_anim;
114 NSMutableDictionary *dict;
117 [self orderOut: sender];
121 dict = [[NSMutableDictionary alloc] initWithCapacity:2];
123 [dict setObject:self forKey:NSViewAnimationTargetKey];
125 [dict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
126 anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
129 [anim setAnimationBlockingMode:NSAnimationNonblocking];
130 [anim setDuration:0.9];
131 [anim setFrameRate:30];
132 [anim setUserInfo: callback];
134 @synchronized(self) {
135 current_anim = self->o_current_animation;
137 if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeOutEffect && [current_anim isAnimating]) {
141 [current_anim stopAnimation];
142 [anim setCurrentProgress:1.0 - [current_anim currentProgress]];
143 [current_anim release];
146 [anim setCurrentProgress:1.0 - [self alphaValue]];
147 self->o_current_animation = anim;
148 [anim startAnimation];
153 - (void)orderFront: (id)sender animate: (BOOL)animate
155 NSViewAnimation *anim;
156 NSViewAnimation *current_anim;
157 NSMutableDictionary *dict;
160 [super orderFront: sender];
161 [self setAlphaValue: 1.0];
165 if (![self isVisible]) {
166 [self setAlphaValue: 0.0];
167 [super orderFront: sender];
169 else if ([self alphaValue] == 1.0) {
170 [super orderFront: self];
174 dict = [[NSMutableDictionary alloc] initWithCapacity:2];
176 [dict setObject:self forKey:NSViewAnimationTargetKey];
178 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
179 anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
182 [anim setAnimationBlockingMode:NSAnimationNonblocking];
183 [anim setDuration:0.5];
184 [anim setFrameRate:30];
186 @synchronized(self) {
187 current_anim = self->o_current_animation;
189 if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeInEffect && [current_anim isAnimating]) {
193 [current_anim stopAnimation];
194 [anim setCurrentProgress:1.0 - [current_anim currentProgress]];
195 [current_anim release];
198 [anim setCurrentProgress:[self alphaValue]];
199 self->o_current_animation = anim;
200 [self orderFront: sender];
201 [anim startAnimation];
206 - (void)animationDidEnd:(NSAnimation*)anim
208 if ([self alphaValue] <= 0.0) {
209 NSInvocation * invoc;
210 [super orderOut: nil];
211 [self setAlphaValue: 1.0];
212 if ((invoc = [anim userInfo]))
217 - (VLCVoutView *)videoView
219 if ([[self contentView] class] == [VLCVoutView class])
220 return (VLCVoutView *)[self contentView];
229 /*****************************************************************************
230 * VLCVideoWindowCommon
232 * Common code for main window, detached window and extra video window
233 *****************************************************************************/
235 @interface VLCVideoWindowCommon (Internal)
236 - (void)customZoom:(id)sender;
237 - (void)hasBecomeFullscreen;
238 - (void)leaveFullscreenAndFadeOut:(BOOL)fadeout;
239 - (void)hasEndedFullscreen;
242 @implementation VLCVideoWindowCommon
244 @synthesize videoView=o_video_view;
245 @synthesize controlsBar=o_controls_bar;
250 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
251 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
253 b_dark_interface = config_GetInt(VLCIntf, "macosx-interfacestyle");
255 if (b_dark_interface) {
256 styleMask = NSBorderlessWindowMask;
257 #ifdef MAC_OS_X_VERSION_10_7
258 if (!OSX_SNOW_LEOPARD)
259 styleMask |= NSResizableWindowMask;
263 self = [super initWithContentRect:contentRect styleMask:styleMask
264 backing:backingType defer:flag];
266 /* we want to be moveable regardless of our style */
267 [self setMovableByWindowBackground: YES];
268 [self setCanBecomeKeyWindow:YES];
270 o_temp_view = [[NSView alloc] init];
271 [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
278 [o_temp_view release];
284 BOOL b_nativeFullscreenMode = NO;
285 #ifdef MAC_OS_X_VERSION_10_7
286 if (!OSX_SNOW_LEOPARD)
287 b_nativeFullscreenMode = var_InheritBool(VLCIntf, "macosx-nativefullscreenmode");
290 if (b_nativeFullscreenMode) {
291 [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
293 [o_titlebar_view setFullscreenButtonHidden: YES];
296 [super awakeFromNib];
299 - (void)setTitle:(NSString *)title
301 if (!title || [title length] < 1)
304 if (b_dark_interface && o_titlebar_view)
305 [o_titlebar_view setWindowTitle: title];
307 [super setTitle: title];
311 #pragma mark zoom / minimize / close
313 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
315 SEL s_menuAction = [menuItem action];
317 if ((s_menuAction == @selector(performClose:)) || (s_menuAction == @selector(performMiniaturize:)) || (s_menuAction == @selector(performZoom:)))
320 return [super validateMenuItem:menuItem];
323 - (BOOL)windowShouldClose:(id)sender
328 - (void)performClose:(id)sender
330 if (!([self styleMask] & NSTitledWindowMask)) {
331 [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowWillCloseNotification object:self];
333 [self orderOut: sender];
335 [super performClose: sender];
338 - (void)performMiniaturize:(id)sender
340 if (!([self styleMask] & NSTitledWindowMask))
341 [self miniaturize: sender];
343 [super performMiniaturize: sender];
346 - (void)performZoom:(id)sender
348 if (!([self styleMask] & NSTitledWindowMask))
349 [self customZoom: sender];
351 [super performZoom: sender];
354 - (void)zoom:(id)sender
356 if (!([self styleMask] & NSTitledWindowMask))
357 [self customZoom: sender];
359 [super zoom: sender];
363 * Given a proposed frame rectangle, return a modified version
364 * which will fit inside the screen.
366 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
367 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
368 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
369 * Copyright (C) 1996 Free Software Foundation, Inc.
371 - (NSRect) customConstrainFrameRect: (NSRect)frameRect toScreen: (NSScreen*)screen
373 NSRect screenRect = [screen visibleFrame];
376 /* Move top edge of the window inside the screen */
377 difference = NSMaxY (frameRect) - NSMaxY (screenRect);
378 if (difference > 0) {
379 frameRect.origin.y -= difference;
382 /* If the window is resizable, resize it (if needed) so that the
383 bottom edge is on the screen or can be on the screen when the user moves
385 difference = NSMaxY (screenRect) - NSMaxY (frameRect);
386 if (_styleMask & NSResizableWindowMask) {
389 difference2 = screenRect.origin.y - frameRect.origin.y;
390 difference2 -= difference;
391 // Take in account the space between the top of window and the top of the
392 // screen which can be used to move the bottom of the window on the screen
393 if (difference2 > 0) {
394 frameRect.size.height -= difference2;
395 frameRect.origin.y += difference2;
398 /* Ensure that resizing doesn't makewindow smaller than minimum */
399 difference2 = [self minSize].height - frameRect.size.height;
400 if (difference2 > 0) {
401 frameRect.size.height += difference2;
402 frameRect.origin.y -= difference2;
412 Zooms the receiver. This method calls the delegate method
413 windowShouldZoom:toFrame: to determine if the window should
414 be allowed to zoom to full screen.
416 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
417 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
418 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
419 * Copyright (C) 1996 Free Software Foundation, Inc.
421 - (void) customZoom: (id)sender
423 NSRect maxRect = [[self screen] visibleFrame];
424 NSRect currentFrame = [self frame];
426 if ([[self delegate] respondsToSelector: @selector(windowWillUseStandardFrame:defaultFrame:)]) {
427 maxRect = [[self delegate] windowWillUseStandardFrame: self defaultFrame: maxRect];
430 maxRect = [self customConstrainFrameRect: maxRect toScreen: [self screen]];
432 // Compare the new frame with the current one
433 if ((abs(NSMaxX(maxRect) - NSMaxX(currentFrame)) < DIST)
434 && (abs(NSMaxY(maxRect) - NSMaxY(currentFrame)) < DIST)
435 && (abs(NSMinX(maxRect) - NSMinX(currentFrame)) < DIST)
436 && (abs(NSMinY(maxRect) - NSMinY(currentFrame)) < DIST)) {
437 // Already in zoomed mode, reset user frame, if stored
438 if ([self frameAutosaveName] != nil) {
439 [self setFrame: previousSavedFrame display: YES animate: YES];
440 [self saveFrameUsingName: [self frameAutosaveName]];
445 if ([self frameAutosaveName] != nil) {
446 [self saveFrameUsingName: [self frameAutosaveName]];
447 previousSavedFrame = [self frame];
450 [self setFrame: maxRect display: YES animate: YES];
454 #pragma mark Video window resizing logic
456 - (void)setWindowLevel:(NSInteger)i_state
458 if (var_InheritBool(VLCIntf, "video-wallpaper") || [self level] < NSNormalWindowLevel)
461 [self setLevel: i_state];
465 - (NSRect)getWindowRectForProposedVideoViewSize:(NSSize)size
467 NSSize windowMinSize = [self minSize];
468 NSRect screenFrame = [[self screen] visibleFrame];
470 NSPoint topleftbase = NSMakePoint(0, [self frame].size.height);
471 NSPoint topleftscreen = [self convertBaseToScreen: topleftbase];
473 unsigned int i_width = size.width;
474 unsigned int i_height = size.height;
475 if (i_width < windowMinSize.width)
476 i_width = windowMinSize.width;
477 if (i_height < f_min_video_height)
478 i_height = f_min_video_height;
480 /* Calculate the window's new size */
482 new_frame.size.width = [self frame].size.width - [o_video_view frame].size.width + i_width;
483 new_frame.size.height = [self frame].size.height - [o_video_view frame].size.height + i_height;
484 new_frame.origin.x = topleftscreen.x;
485 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
487 /* make sure the window doesn't exceed the screen size the window is on */
488 if (new_frame.size.width > screenFrame.size.width) {
489 new_frame.size.width = screenFrame.size.width;
490 new_frame.origin.x = screenFrame.origin.x;
492 if (new_frame.size.height > screenFrame.size.height) {
493 new_frame.size.height = screenFrame.size.height;
494 new_frame.origin.y = screenFrame.origin.y;
496 if (new_frame.origin.y < screenFrame.origin.y)
497 new_frame.origin.y = screenFrame.origin.y;
499 CGFloat right_screen_point = screenFrame.origin.x + screenFrame.size.width;
500 CGFloat right_window_point = new_frame.origin.x + new_frame.size.width;
501 if (right_window_point > right_screen_point)
502 new_frame.origin.x -= (right_window_point - right_screen_point);
509 if ([self fullscreen])
512 NSRect window_rect = [self getWindowRectForProposedVideoViewSize:nativeVideoSize];
513 [[self animator] setFrame:window_rect display:YES];
516 - (void)setNativeVideoSize:(NSSize)size
518 nativeVideoSize = size;
520 if (var_InheritBool(VLCIntf, "macosx-video-autoresize") && !var_InheritBool(VLCIntf, "video-wallpaper"))
524 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
526 if (![[VLCMain sharedInstance] activeVideoPlayback] || nativeVideoSize.width == 0. || nativeVideoSize.height == 0. || window != self)
527 return proposedFrameSize;
529 // needed when entering lion fullscreen mode
530 if ([self fullscreen])
531 return proposedFrameSize;
533 if ([[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]) {
534 NSRect videoWindowFrame = [self frame];
535 NSRect viewRect = [o_video_view convertRect:[o_video_view bounds] toView: nil];
536 NSRect contentRect = [self contentRectForFrameRect:videoWindowFrame];
537 float marginy = viewRect.origin.y + videoWindowFrame.size.height - contentRect.size.height;
538 float marginx = contentRect.size.width - viewRect.size.width;
539 if (o_titlebar_view && b_dark_interface)
540 marginy += [o_titlebar_view frame].size.height;
542 proposedFrameSize.height = (proposedFrameSize.width - marginx) * nativeVideoSize.height / nativeVideoSize.width + marginy;
545 return proposedFrameSize;
550 #pragma mark Lion native fullscreen handling
552 - (void)becomeKeyWindow
554 [super becomeKeyWindow];
556 // change fspanel state for the case when multiple windows are in fullscreen
557 if ([self hasActiveVideo] && [self fullscreen])
558 [[[VLCMainWindow sharedInstance] fsPanel] setActive:nil];
560 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive:nil];
563 - (void)windowWillEnterFullScreen:(NSNotification *)notification
565 // workaround, see #6668
566 [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
568 [self setFullscreen: YES];
570 var_SetBool(pl_Get(VLCIntf), "fullscreen", true);
572 if ([self hasActiveVideo]) {
573 vout_thread_t *p_vout = getVoutForActiveWindow();
575 var_SetBool(p_vout, "fullscreen", true);
576 vlc_object_release(p_vout);
580 [o_video_view setFrame: [[self contentView] frame]];
582 [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
583 i_originalLevel = [self level];
584 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
585 [self setLevel:NSNormalWindowLevel];
587 if (b_dark_interface) {
588 [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
591 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
592 winrect = [self frame];
594 winrect.size.height = winrect.size.height - f_titleBarHeight;
595 [self setFrame: winrect display:NO animate:NO];
598 // TODO fix bottom bar status when vout just not visible, but there
599 if (![o_video_view isHidden])
600 [[o_controls_bar bottomBarView] setHidden: YES];
602 [self setMovableByWindowBackground: NO];
605 - (void)windowDidEnterFullScreen:(NSNotification *)notification
607 // Indeed, we somehow can have an "inactive" fullscreen (but a visible window!).
608 // But this creates some problems when leaving fs over remote intfs, so activate app here.
609 [NSApp activateIgnoringOtherApps:YES];
611 if ([self hasActiveVideo]) {
612 [[[VLCMainWindow sharedInstance] fsPanel] setVoutWasUpdated: self];
613 [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
616 NSArray *subviews = [[self videoView] subviews];
617 NSUInteger count = [subviews count];
619 for (NSUInteger x = 0; x < count; x++) {
620 if ([[subviews objectAtIndex:x] respondsToSelector:@selector(reshape)])
621 [[subviews objectAtIndex:x] reshape];
626 - (void)windowWillExitFullScreen:(NSNotification *)notification
628 [self setFullscreen: NO];
630 var_SetBool(pl_Get(VLCIntf), "fullscreen", false);
632 if ([self hasActiveVideo]) {
633 vout_thread_t *p_vout = getVoutForActiveWindow();
635 var_SetBool(p_vout, "fullscreen", false);
636 vlc_object_release(p_vout);
640 [NSCursor setHiddenUntilMouseMoves: NO];
641 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
643 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
644 [self setLevel:i_originalLevel];
646 if (b_dark_interface) {
648 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
649 winrect = [self frame];
651 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
652 winrect.size.width, f_titleBarHeight)];
653 [[self contentView] addSubview: o_titlebar_view];
655 winrect.size.height = winrect.size.height + f_titleBarHeight;
656 [self setFrame: winrect display:NO animate:NO];
657 winrect = [o_video_view frame];
658 winrect.size.height -= f_titleBarHeight;
659 [o_video_view setFrame: winrect];
662 NSRect videoViewFrame = [o_video_view frame];
663 videoViewFrame.origin.y = [[o_controls_bar bottomBarView] frame].size.height;
664 videoViewFrame.size.height -= [[o_controls_bar bottomBarView] frame].size.height;
665 [o_video_view setFrame: videoViewFrame];
666 [[o_controls_bar bottomBarView] setHidden: NO];
668 [self setMovableByWindowBackground: YES];
672 #pragma mark Fullscreen Logic
674 - (void)lockFullscreenAnimation
676 [o_animation_lock lock];
679 - (void)unlockFullscreenAnimation
681 [o_animation_lock unlock];
684 - (void)enterFullscreen
686 NSMutableDictionary *dict1, *dict2;
690 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
692 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
693 [self lockFullscreenAnimation];
696 msg_Dbg(VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode");
697 screen = [self screen];
700 msg_Dbg(VLCIntf, "Using deepest screen");
701 screen = [NSScreen deepestScreen];
704 screen_rect = [screen frame];
707 [o_controls_bar setFullscreenState:YES];
708 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:YES];
710 [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
712 if (blackout_other_displays)
713 [screen blackoutOtherScreens];
715 /* Make sure we don't see the window flashes in float-on-top mode */
716 i_originalLevel = [self level];
717 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
718 [self setLevel:NSNormalWindowLevel];
721 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
722 if (!o_fullscreen_window) {
723 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
725 rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
726 rect.origin.x += [self frame].origin.x;
727 rect.origin.y += [self frame].origin.y;
728 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
729 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
730 [o_fullscreen_window setCanBecomeKeyWindow: YES];
731 [o_fullscreen_window setCanBecomeMainWindow: YES];
732 [o_fullscreen_window setHasActiveVideo: YES];
733 [o_fullscreen_window setFullscreen: YES];
735 if (![self isVisible] || [self alphaValue] == 0.0) {
736 /* We don't animate if we are not visible, instead we
737 * simply fade the display */
738 CGDisplayFadeReservationToken token;
740 if (blackout_other_displays) {
741 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
742 CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
745 NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
746 if ([screen hasMenuBar])
747 presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
748 if ([screen hasMenuBar] || [screen hasDock])
749 presentationOpts |= NSApplicationPresentationAutoHideDock;
750 [NSApp setPresentationOptions:presentationOpts];
752 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
753 [o_temp_view setFrame:[o_video_view frame]];
754 [o_fullscreen_window setContentView:o_video_view];
756 [o_fullscreen_window makeKeyAndOrderFront:self];
757 [o_fullscreen_window orderFront:self animate:YES];
759 [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
760 [o_fullscreen_window setLevel:NSNormalWindowLevel];
762 if (blackout_other_displays) {
763 CGDisplayFade(token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
764 CGReleaseDisplayFadeReservation(token);
767 /* Will release the lock */
768 [self hasBecomeFullscreen];
773 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
774 NSDisableScreenUpdates();
775 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
776 [o_temp_view setFrame:[o_video_view frame]];
777 [o_fullscreen_window setContentView:o_video_view];
778 [o_fullscreen_window makeKeyAndOrderFront:self];
779 NSEnableScreenUpdates();
782 /* We are in fullscreen (and no animation is running) */
783 if ([self fullscreen]) {
784 /* Make sure we are hidden */
785 [self orderOut: self];
787 [self unlockFullscreenAnimation];
791 if (o_fullscreen_anim1) {
792 [o_fullscreen_anim1 stopAnimation];
793 [o_fullscreen_anim1 release];
795 if (o_fullscreen_anim2) {
796 [o_fullscreen_anim2 stopAnimation];
797 [o_fullscreen_anim2 release];
800 NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
801 if ([screen hasMenuBar])
802 presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
803 if ([screen hasMenuBar] || [screen hasDock])
804 presentationOpts |= NSApplicationPresentationAutoHideDock;
805 [NSApp setPresentationOptions:presentationOpts];
807 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
808 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
810 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
811 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
813 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
814 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
815 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
817 /* Strategy with NSAnimation allocation:
818 - Keep at most 2 animation at a time
819 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
821 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
822 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
827 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
828 [o_fullscreen_anim1 setDuration: 0.3];
829 [o_fullscreen_anim1 setFrameRate: 30];
830 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
831 [o_fullscreen_anim2 setDuration: 0.2];
832 [o_fullscreen_anim2 setFrameRate: 30];
834 [o_fullscreen_anim2 setDelegate: self];
835 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
837 [o_fullscreen_anim1 startAnimation];
838 /* fullscreenAnimation will be unlocked when animation ends */
841 - (void)hasBecomeFullscreen
843 if ([[o_video_view subviews] count] > 0)
844 [o_fullscreen_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
846 [o_fullscreen_window makeKeyWindow];
847 [o_fullscreen_window setAcceptsMouseMovedEvents: YES];
849 /* tell the fspanel to move itself to front next time it's triggered */
850 [[[VLCMainWindow sharedInstance] fsPanel] setVoutWasUpdated: o_fullscreen_window];
851 [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
853 if ([self isVisible])
854 [self orderOut: self];
856 [self setFullscreen:YES];
857 [self unlockFullscreenAnimation];
860 - (void)leaveFullscreen
862 [self leaveFullscreenAndFadeOut: NO];
865 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
867 NSMutableDictionary *dict1, *dict2;
869 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
871 [self lockFullscreenAnimation];
874 [o_controls_bar setFullscreenState:NO];
875 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:NO];
877 /* We always try to do so */
878 [NSScreen unblackoutScreens];
880 [[o_video_view window] makeKeyAndOrderFront: nil];
882 /* Don't do anything if o_fullscreen_window is already closed */
883 if (!o_fullscreen_window) {
884 [self unlockFullscreenAnimation];
889 /* We don't animate if we are not visible, instead we
890 * simply fade the display */
891 CGDisplayFadeReservationToken token;
893 if (blackout_other_displays) {
894 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
895 CGDisplayFade(token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
898 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
899 [NSApp setPresentationOptions: NSApplicationPresentationDefault];
901 /* Will release the lock */
902 [self hasEndedFullscreen];
904 /* Our window is hidden, and might be faded. We need to workaround that, so note it
906 b_window_is_invisible = YES;
908 if (blackout_other_displays) {
909 CGDisplayFade(token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
910 CGReleaseDisplayFadeReservation(token);
916 [self setAlphaValue: 0.0];
917 [self orderFront: self];
918 [[o_video_view window] orderFront: self];
920 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
921 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
923 if (o_fullscreen_anim1) {
924 [o_fullscreen_anim1 stopAnimation];
925 [o_fullscreen_anim1 release];
927 if (o_fullscreen_anim2) {
928 [o_fullscreen_anim2 stopAnimation];
929 [o_fullscreen_anim2 release];
932 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
933 frame.origin.x += [self frame].origin.x;
934 frame.origin.y += [self frame].origin.y;
936 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
937 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
938 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
940 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
943 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
944 [o_fullscreen_anim2 setDuration: 0.3];
945 [o_fullscreen_anim2 setFrameRate: 30];
947 [o_fullscreen_anim2 setDelegate: self];
949 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
951 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
952 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
953 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
955 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
958 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
959 [o_fullscreen_anim1 setDuration: 0.2];
960 [o_fullscreen_anim1 setFrameRate: 30];
961 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
963 /* Make sure o_fullscreen_window is the frontmost window */
964 [o_fullscreen_window orderFront: self];
966 [o_fullscreen_anim1 startAnimation];
967 /* fullscreenAnimation will be unlocked when animation ends */
970 - (void)hasEndedFullscreen
972 [self setFullscreen:NO];
974 /* This function is private and should be only triggered at the end of the fullscreen change animation */
975 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
976 NSDisableScreenUpdates();
977 [o_video_view retain];
978 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
979 [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
980 [o_video_view release];
981 [o_video_view setFrame:[o_temp_view frame]];
982 if ([[o_video_view subviews] count] > 0)
983 [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
985 [super makeKeyAndOrderFront:self]; /* our version (in main window) contains a workaround */
987 [o_fullscreen_window orderOut: self];
988 NSEnableScreenUpdates();
990 [o_fullscreen_window release];
991 o_fullscreen_window = nil;
993 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
994 [self setLevel:i_originalLevel];
995 [self setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
997 // if we quit fullscreen because there is no video anymore, make sure non-embedded window is not visible
998 if (![[VLCMain sharedInstance] activeVideoPlayback] && [self class] != [VLCMainWindow class])
999 [self orderOut: self];
1001 [self unlockFullscreenAnimation];
1004 - (void)animationDidEnd:(NSAnimation*)animation
1006 NSArray *viewAnimations;
1007 if (o_makekey_anim == animation) {
1008 [o_makekey_anim release];
1011 if ([animation currentValue] < 1.0)
1014 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
1015 viewAnimations = [o_fullscreen_anim2 viewAnimations];
1016 if ([viewAnimations count] >=1 &&
1017 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
1018 /* Fullscreen ended */
1019 [self hasEndedFullscreen];
1021 /* Fullscreen started */
1022 [self hasBecomeFullscreen];
1026 #pragma mark Accessibility stuff
1028 - (NSArray *)accessibilityAttributeNames
1030 if (!b_dark_interface || !o_titlebar_view)
1031 return [super accessibilityAttributeNames];
1033 static NSMutableArray *attributes = nil;
1034 if (attributes == nil) {
1035 attributes = [[super accessibilityAttributeNames] mutableCopy];
1036 NSArray *appendAttributes = [NSArray arrayWithObjects: NSAccessibilitySubroleAttribute,
1037 NSAccessibilityCloseButtonAttribute,
1038 NSAccessibilityMinimizeButtonAttribute,
1039 NSAccessibilityZoomButtonAttribute,
1042 for(NSString *attribute in appendAttributes) {
1043 if (![attributes containsObject:attribute])
1044 [attributes addObject:attribute];
1050 - (id)accessibilityAttributeValue: (NSString*)o_attribute_name
1052 if (b_dark_interface && o_titlebar_view) {
1053 VLCMainWindowTitleView *o_tbv = o_titlebar_view;
1055 if ([o_attribute_name isEqualTo: NSAccessibilitySubroleAttribute])
1056 return NSAccessibilityStandardWindowSubrole;
1058 if ([o_attribute_name isEqualTo: NSAccessibilityCloseButtonAttribute])
1059 return [[o_tbv closeButton] cell];
1061 if ([o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute])
1062 return [[o_tbv minimizeButton] cell];
1064 if ([o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute])
1065 return [[o_tbv zoomButton] cell];
1068 return [super accessibilityAttributeValue: o_attribute_name];