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 Mouse cursor handling
552 // NSTimer selectors require this function signature as per Apple's docs
553 - (void)hideMouseCursor:(NSTimer *)timer
555 [NSCursor setHiddenUntilMouseMoves: YES];
558 - (void)recreateHideMouseTimer
560 if (t_hide_mouse_timer != nil) {
561 [t_hide_mouse_timer invalidate];
562 [t_hide_mouse_timer release];
565 t_hide_mouse_timer = [NSTimer scheduledTimerWithTimeInterval:2
567 selector:@selector(hideMouseCursor:)
570 [t_hide_mouse_timer retain];
573 // Called automatically if window's acceptsMouseMovedEvents property is true
574 - (void)mouseMoved:(NSEvent *)theEvent
577 [self recreateHideMouseTimer];
579 [super mouseMoved: theEvent];
583 #pragma mark Lion native fullscreen handling
585 - (void)becomeKeyWindow
587 [super becomeKeyWindow];
589 // change fspanel state for the case when multiple windows are in fullscreen
590 if ([self hasActiveVideo] && [self fullscreen])
591 [[[VLCMainWindow sharedInstance] fsPanel] setActive:nil];
593 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive:nil];
596 - (void)windowWillEnterFullScreen:(NSNotification *)notification
598 // workaround, see #6668
599 [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
601 [self setFullscreen: YES];
603 var_SetBool(pl_Get(VLCIntf), "fullscreen", true);
605 if ([self hasActiveVideo]) {
606 vout_thread_t *p_vout = getVoutForActiveWindow();
608 var_SetBool(p_vout, "fullscreen", true);
609 vlc_object_release(p_vout);
613 [o_video_view setFrame: [[self contentView] frame]];
615 [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
616 i_originalLevel = [self level];
617 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
618 [self setLevel:NSNormalWindowLevel];
620 if (b_dark_interface) {
621 [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
624 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
625 winrect = [self frame];
627 winrect.size.height = winrect.size.height - f_titleBarHeight;
628 [self setFrame: winrect display:NO animate:NO];
631 // TODO fix bottom bar status when vout just not visible, but there
632 if (![o_video_view isHidden])
633 [[o_controls_bar bottomBarView] setHidden: YES];
635 [self setMovableByWindowBackground: NO];
638 - (void)windowDidEnterFullScreen:(NSNotification *)notification
640 // Indeed, we somehow can have an "inactive" fullscreen (but a visible window!).
641 // But this creates some problems when leaving fs over remote intfs, so activate app here.
642 [NSApp activateIgnoringOtherApps:YES];
644 if ([self hasActiveVideo]) {
645 [[[VLCMainWindow sharedInstance] fsPanel] setVoutWasUpdated: self];
646 [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
649 NSArray *subviews = [[self videoView] subviews];
650 NSUInteger count = [subviews count];
652 for (NSUInteger x = 0; x < count; x++) {
653 if ([[subviews objectAtIndex:x] respondsToSelector:@selector(reshape)])
654 [[subviews objectAtIndex:x] reshape];
659 - (void)windowWillExitFullScreen:(NSNotification *)notification
661 [self setFullscreen: NO];
663 var_SetBool(pl_Get(VLCIntf), "fullscreen", false);
665 if ([self hasActiveVideo]) {
666 vout_thread_t *p_vout = getVoutForActiveWindow();
668 var_SetBool(p_vout, "fullscreen", false);
669 vlc_object_release(p_vout);
673 [NSCursor setHiddenUntilMouseMoves: NO];
674 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
676 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
677 [self setLevel:i_originalLevel];
679 if (b_dark_interface) {
681 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
682 winrect = [self frame];
684 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
685 winrect.size.width, f_titleBarHeight)];
686 [[self contentView] addSubview: o_titlebar_view];
688 winrect.size.height = winrect.size.height + f_titleBarHeight;
689 [self setFrame: winrect display:NO animate:NO];
690 winrect = [o_video_view frame];
691 winrect.size.height -= f_titleBarHeight;
692 [o_video_view setFrame: winrect];
695 NSRect videoViewFrame = [o_video_view frame];
696 videoViewFrame.origin.y = [[o_controls_bar bottomBarView] frame].size.height;
697 videoViewFrame.size.height -= [[o_controls_bar bottomBarView] frame].size.height;
698 [o_video_view setFrame: videoViewFrame];
699 [[o_controls_bar bottomBarView] setHidden: NO];
701 [self setMovableByWindowBackground: YES];
705 #pragma mark Fullscreen Logic
707 - (void)lockFullscreenAnimation
709 [o_animation_lock lock];
712 - (void)unlockFullscreenAnimation
714 [o_animation_lock unlock];
717 - (void)enterFullscreen
719 NSMutableDictionary *dict1, *dict2;
723 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
725 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
726 [self lockFullscreenAnimation];
729 msg_Dbg(VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode");
730 screen = [self screen];
733 msg_Dbg(VLCIntf, "Using deepest screen");
734 screen = [NSScreen deepestScreen];
737 screen_rect = [screen frame];
740 [o_controls_bar setFullscreenState:YES];
741 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:YES];
743 [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
745 if (blackout_other_displays)
746 [screen blackoutOtherScreens];
748 /* Make sure we don't see the window flashes in float-on-top mode */
749 i_originalLevel = [self level];
750 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
751 [self setLevel:NSNormalWindowLevel];
754 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
755 if (!o_fullscreen_window) {
756 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
758 rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
759 rect.origin.x += [self frame].origin.x;
760 rect.origin.y += [self frame].origin.y;
761 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
762 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
763 [o_fullscreen_window setCanBecomeKeyWindow: YES];
764 [o_fullscreen_window setCanBecomeMainWindow: YES];
765 [o_fullscreen_window setHasActiveVideo: YES];
766 [o_fullscreen_window setFullscreen: YES];
768 if (![self isVisible] || [self alphaValue] == 0.0) {
769 /* We don't animate if we are not visible, instead we
770 * simply fade the display */
771 CGDisplayFadeReservationToken token;
773 if (blackout_other_displays) {
774 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
775 CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
778 NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
779 if ([screen hasMenuBar])
780 presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
781 if ([screen hasMenuBar] || [screen hasDock])
782 presentationOpts |= NSApplicationPresentationAutoHideDock;
783 [NSApp setPresentationOptions:presentationOpts];
785 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
786 [o_temp_view setFrame:[o_video_view frame]];
787 [o_fullscreen_window setContentView:o_video_view];
789 [o_fullscreen_window makeKeyAndOrderFront:self];
790 [o_fullscreen_window orderFront:self animate:YES];
792 [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
793 [o_fullscreen_window setLevel:NSNormalWindowLevel];
795 if (blackout_other_displays) {
796 CGDisplayFade(token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
797 CGReleaseDisplayFadeReservation(token);
800 /* Will release the lock */
801 [self hasBecomeFullscreen];
806 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
807 NSDisableScreenUpdates();
808 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
809 [o_temp_view setFrame:[o_video_view frame]];
810 [o_fullscreen_window setContentView:o_video_view];
811 [o_fullscreen_window makeKeyAndOrderFront:self];
812 NSEnableScreenUpdates();
815 /* We are in fullscreen (and no animation is running) */
816 if ([self fullscreen]) {
817 /* Make sure we are hidden */
818 [self orderOut: self];
820 [self unlockFullscreenAnimation];
824 if (o_fullscreen_anim1) {
825 [o_fullscreen_anim1 stopAnimation];
826 [o_fullscreen_anim1 release];
828 if (o_fullscreen_anim2) {
829 [o_fullscreen_anim2 stopAnimation];
830 [o_fullscreen_anim2 release];
833 NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
834 if ([screen hasMenuBar])
835 presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
836 if ([screen hasMenuBar] || [screen hasDock])
837 presentationOpts |= NSApplicationPresentationAutoHideDock;
838 [NSApp setPresentationOptions:presentationOpts];
840 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
841 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
843 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
844 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
846 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
847 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
848 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
850 /* Strategy with NSAnimation allocation:
851 - Keep at most 2 animation at a time
852 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
854 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
855 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
860 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
861 [o_fullscreen_anim1 setDuration: 0.3];
862 [o_fullscreen_anim1 setFrameRate: 30];
863 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
864 [o_fullscreen_anim2 setDuration: 0.2];
865 [o_fullscreen_anim2 setFrameRate: 30];
867 [o_fullscreen_anim2 setDelegate: self];
868 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
870 [o_fullscreen_anim1 startAnimation];
871 /* fullscreenAnimation will be unlocked when animation ends */
874 - (void)hasBecomeFullscreen
876 if ([[o_video_view subviews] count] > 0)
877 [o_fullscreen_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
879 [o_fullscreen_window makeKeyWindow];
880 [o_fullscreen_window setAcceptsMouseMovedEvents: YES];
882 /* tell the fspanel to move itself to front next time it's triggered */
883 [[[VLCMainWindow sharedInstance] fsPanel] setVoutWasUpdated: o_fullscreen_window];
884 [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
886 if ([self isVisible])
887 [self orderOut: self];
889 [self setFullscreen:YES];
890 [self unlockFullscreenAnimation];
893 - (void)leaveFullscreen
895 [self leaveFullscreenAndFadeOut: NO];
898 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
900 NSMutableDictionary *dict1, *dict2;
902 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
904 [self lockFullscreenAnimation];
907 [o_controls_bar setFullscreenState:NO];
908 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:NO];
910 /* We always try to do so */
911 [NSScreen unblackoutScreens];
913 [[o_video_view window] makeKeyAndOrderFront: nil];
915 /* Don't do anything if o_fullscreen_window is already closed */
916 if (!o_fullscreen_window) {
917 [self unlockFullscreenAnimation];
922 /* We don't animate if we are not visible, instead we
923 * simply fade the display */
924 CGDisplayFadeReservationToken token;
926 if (blackout_other_displays) {
927 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
928 CGDisplayFade(token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
931 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
932 [NSApp setPresentationOptions: NSApplicationPresentationDefault];
934 /* Will release the lock */
935 [self hasEndedFullscreen];
937 /* Our window is hidden, and might be faded. We need to workaround that, so note it
939 b_window_is_invisible = YES;
941 if (blackout_other_displays) {
942 CGDisplayFade(token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
943 CGReleaseDisplayFadeReservation(token);
949 [self setAlphaValue: 0.0];
950 [self orderFront: self];
951 [[o_video_view window] orderFront: self];
953 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
954 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
956 if (o_fullscreen_anim1) {
957 [o_fullscreen_anim1 stopAnimation];
958 [o_fullscreen_anim1 release];
960 if (o_fullscreen_anim2) {
961 [o_fullscreen_anim2 stopAnimation];
962 [o_fullscreen_anim2 release];
965 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
966 frame.origin.x += [self frame].origin.x;
967 frame.origin.y += [self frame].origin.y;
969 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
970 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
971 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
973 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
976 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
977 [o_fullscreen_anim2 setDuration: 0.3];
978 [o_fullscreen_anim2 setFrameRate: 30];
980 [o_fullscreen_anim2 setDelegate: self];
982 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
984 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
985 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
986 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
988 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
991 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
992 [o_fullscreen_anim1 setDuration: 0.2];
993 [o_fullscreen_anim1 setFrameRate: 30];
994 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
996 /* Make sure o_fullscreen_window is the frontmost window */
997 [o_fullscreen_window orderFront: self];
999 [o_fullscreen_anim1 startAnimation];
1000 /* fullscreenAnimation will be unlocked when animation ends */
1003 - (void)hasEndedFullscreen
1005 [self setFullscreen:NO];
1007 /* This function is private and should be only triggered at the end of the fullscreen change animation */
1008 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
1009 NSDisableScreenUpdates();
1010 [o_video_view retain];
1011 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1012 [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
1013 [o_video_view release];
1014 [o_video_view setFrame:[o_temp_view frame]];
1015 if ([[o_video_view subviews] count] > 0)
1016 [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
1018 [super makeKeyAndOrderFront:self]; /* our version (in main window) contains a workaround */
1020 [o_fullscreen_window orderOut: self];
1021 NSEnableScreenUpdates();
1023 [o_fullscreen_window release];
1024 o_fullscreen_window = nil;
1026 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
1027 [self setLevel:i_originalLevel];
1028 [self setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
1030 // if we quit fullscreen because there is no video anymore, make sure non-embedded window is not visible
1031 if (![[VLCMain sharedInstance] activeVideoPlayback] && [self class] != [VLCMainWindow class])
1032 [self orderOut: self];
1034 [self unlockFullscreenAnimation];
1037 - (void)animationDidEnd:(NSAnimation*)animation
1039 NSArray *viewAnimations;
1040 if (o_makekey_anim == animation) {
1041 [o_makekey_anim release];
1044 if ([animation currentValue] < 1.0)
1047 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
1048 viewAnimations = [o_fullscreen_anim2 viewAnimations];
1049 if ([viewAnimations count] >=1 &&
1050 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
1051 /* Fullscreen ended */
1052 [self hasEndedFullscreen];
1054 /* Fullscreen started */
1055 [self hasBecomeFullscreen];
1059 #pragma mark Accessibility stuff
1061 - (NSArray *)accessibilityAttributeNames
1063 if (!b_dark_interface || !o_titlebar_view)
1064 return [super accessibilityAttributeNames];
1066 static NSMutableArray *attributes = nil;
1067 if (attributes == nil) {
1068 attributes = [[super accessibilityAttributeNames] mutableCopy];
1069 NSArray *appendAttributes = [NSArray arrayWithObjects: NSAccessibilitySubroleAttribute,
1070 NSAccessibilityCloseButtonAttribute,
1071 NSAccessibilityMinimizeButtonAttribute,
1072 NSAccessibilityZoomButtonAttribute,
1075 for(NSString *attribute in appendAttributes) {
1076 if (![attributes containsObject:attribute])
1077 [attributes addObject:attribute];
1083 - (id)accessibilityAttributeValue: (NSString*)o_attribute_name
1085 if (b_dark_interface && o_titlebar_view) {
1086 VLCMainWindowTitleView *o_tbv = o_titlebar_view;
1088 if ([o_attribute_name isEqualTo: NSAccessibilitySubroleAttribute])
1089 return NSAccessibilityStandardWindowSubrole;
1091 if ([o_attribute_name isEqualTo: NSAccessibilityCloseButtonAttribute])
1092 return [[o_tbv closeButton] cell];
1094 if ([o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute])
1095 return [[o_tbv minimizeButton] cell];
1097 if ([o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute])
1098 return [[o_tbv zoomButton] cell];
1101 return [super accessibilityAttributeValue: o_attribute_name];