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
38 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
39 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
41 self = [super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag];
43 /* we don't want this window to be restored on relaunch */
44 if (!OSX_SNOW_LEOPARD)
45 [self setRestorable:NO];
50 - (void)setCanBecomeKeyWindow: (BOOL)canBecomeKey
52 b_isset_canBecomeKeyWindow = YES;
53 b_canBecomeKeyWindow = canBecomeKey;
56 - (BOOL)canBecomeKeyWindow
58 if (b_isset_canBecomeKeyWindow)
59 return b_canBecomeKeyWindow;
61 return [super canBecomeKeyWindow];
64 - (void)setCanBecomeMainWindow: (BOOL)canBecomeMain
66 b_isset_canBecomeMainWindow = YES;
67 b_canBecomeMainWindow = canBecomeMain;
70 - (BOOL)canBecomeMainWindow
72 if (b_isset_canBecomeMainWindow)
73 return b_canBecomeMainWindow;
75 return [super canBecomeMainWindow];
78 - (void)closeAndAnimate: (BOOL)animate
87 invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(close)]];
88 [invoc setTarget: self];
90 if (![self isVisible] || [self alphaValue] == 0.0) {
95 [self orderOut: self animate: YES callback: invoc];
98 - (void)orderOut: (id)sender animate: (BOOL)animate
100 NSInvocation *invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(orderOut:)]];
101 [invoc setTarget: self];
102 [invoc setArgument: sender atIndex: 0];
103 [self orderOut: sender animate: animate callback: invoc];
106 - (void)orderOut: (id)sender animate: (BOOL)animate callback:(NSInvocation *)callback
108 NSViewAnimation *anim;
109 NSViewAnimation *current_anim;
110 NSMutableDictionary *dict;
113 [self orderOut: sender];
117 dict = [[NSMutableDictionary alloc] initWithCapacity:2];
119 [dict setObject:self forKey:NSViewAnimationTargetKey];
121 [dict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
122 anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
125 [anim setAnimationBlockingMode:NSAnimationNonblocking];
126 [anim setDuration:0.9];
127 [anim setFrameRate:30];
128 [anim setUserInfo: callback];
130 @synchronized(self) {
131 current_anim = self->o_current_animation;
133 if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeOutEffect && [current_anim isAnimating]) {
137 [current_anim stopAnimation];
138 [anim setCurrentProgress:1.0 - [current_anim currentProgress]];
139 [current_anim release];
142 [anim setCurrentProgress:1.0 - [self alphaValue]];
143 self->o_current_animation = anim;
144 [anim startAnimation];
149 - (void)orderFront: (id)sender animate: (BOOL)animate
151 NSViewAnimation *anim;
152 NSViewAnimation *current_anim;
153 NSMutableDictionary *dict;
156 [super orderFront: sender];
157 [self setAlphaValue: 1.0];
161 if (![self isVisible]) {
162 [self setAlphaValue: 0.0];
163 [super orderFront: sender];
165 else if ([self alphaValue] == 1.0) {
166 [super orderFront: self];
170 dict = [[NSMutableDictionary alloc] initWithCapacity:2];
172 [dict setObject:self forKey:NSViewAnimationTargetKey];
174 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
175 anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
178 [anim setAnimationBlockingMode:NSAnimationNonblocking];
179 [anim setDuration:0.5];
180 [anim setFrameRate:30];
182 @synchronized(self) {
183 current_anim = self->o_current_animation;
185 if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeInEffect && [current_anim isAnimating]) {
189 [current_anim stopAnimation];
190 [anim setCurrentProgress:1.0 - [current_anim currentProgress]];
191 [current_anim release];
194 [anim setCurrentProgress:[self alphaValue]];
195 self->o_current_animation = anim;
196 [self orderFront: sender];
197 [anim startAnimation];
202 - (void)animationDidEnd:(NSAnimation*)anim
204 if ([self alphaValue] <= 0.0) {
205 NSInvocation * invoc;
206 [super orderOut: nil];
207 [self setAlphaValue: 1.0];
208 if ((invoc = [anim userInfo]))
213 - (VLCVoutView *)videoView
215 if ([[self contentView] class] == [VLCVoutView class])
216 return (VLCVoutView *)[self contentView];
225 /*****************************************************************************
226 * VLCVideoWindowCommon
228 * Common code for main window, detached window and extra video window
229 *****************************************************************************/
231 @interface VLCVideoWindowCommon (Internal)
232 - (void)customZoom:(id)sender;
233 - (void)hasBecomeFullscreen;
234 - (void)leaveFullscreenAndFadeOut:(BOOL)fadeout;
235 - (void)hasEndedFullscreen;
238 @implementation VLCVideoWindowCommon
240 @synthesize videoView=o_video_view;
241 @synthesize controlsBar=o_controls_bar;
242 @synthesize hasActiveVideo=b_has_active_video;
247 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
248 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
250 b_dark_interface = config_GetInt(VLCIntf, "macosx-interfacestyle");
252 if (b_dark_interface) {
253 styleMask = NSBorderlessWindowMask;
254 #ifdef MAC_OS_X_VERSION_10_7
255 if (!OSX_SNOW_LEOPARD)
256 styleMask |= NSResizableWindowMask;
260 self = [super initWithContentRect:contentRect styleMask:styleMask
261 backing:backingType defer:flag];
263 /* we want to be moveable regardless of our style */
264 [self setMovableByWindowBackground: YES];
265 [self setCanBecomeKeyWindow:YES];
267 o_temp_view = [[NSView alloc] init];
268 [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
275 [o_temp_view release];
281 BOOL b_nativeFullscreenMode = NO;
282 #ifdef MAC_OS_X_VERSION_10_7
283 if (!OSX_SNOW_LEOPARD)
284 b_nativeFullscreenMode = var_InheritBool(VLCIntf, "macosx-nativefullscreenmode");
287 if (b_nativeFullscreenMode) {
288 [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
290 [o_titlebar_view setFullscreenButtonHidden: YES];
293 [super awakeFromNib];
296 - (void)setTitle:(NSString *)title
298 if (!title || [title length] < 1)
301 if (b_dark_interface && o_titlebar_view)
302 [o_titlebar_view setWindowTitle: title];
304 [super setTitle: title];
308 #pragma mark zoom / minimize / close
310 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
312 SEL s_menuAction = [menuItem action];
314 if ((s_menuAction == @selector(performClose:)) || (s_menuAction == @selector(performMiniaturize:)) || (s_menuAction == @selector(performZoom:)))
317 return [super validateMenuItem:menuItem];
320 - (BOOL)windowShouldClose:(id)sender
325 - (void)performClose:(id)sender
327 if (!([self styleMask] & NSTitledWindowMask)) {
328 [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowWillCloseNotification object:self];
330 [self orderOut: sender];
332 [super performClose: sender];
335 - (void)performMiniaturize:(id)sender
337 if (!([self styleMask] & NSTitledWindowMask))
338 [self miniaturize: sender];
340 [super performMiniaturize: sender];
343 - (void)performZoom:(id)sender
345 if (!([self styleMask] & NSTitledWindowMask))
346 [self customZoom: sender];
348 [super performZoom: sender];
351 - (void)zoom:(id)sender
353 if (!([self styleMask] & NSTitledWindowMask))
354 [self customZoom: sender];
356 [super zoom: sender];
360 * Given a proposed frame rectangle, return a modified version
361 * which will fit inside the screen.
363 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
364 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
365 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
366 * Copyright (C) 1996 Free Software Foundation, Inc.
368 - (NSRect) customConstrainFrameRect: (NSRect)frameRect toScreen: (NSScreen*)screen
370 NSRect screenRect = [screen visibleFrame];
373 /* Move top edge of the window inside the screen */
374 difference = NSMaxY (frameRect) - NSMaxY (screenRect);
375 if (difference > 0) {
376 frameRect.origin.y -= difference;
379 /* If the window is resizable, resize it (if needed) so that the
380 bottom edge is on the screen or can be on the screen when the user moves
382 difference = NSMaxY (screenRect) - NSMaxY (frameRect);
383 if (_styleMask & NSResizableWindowMask) {
386 difference2 = screenRect.origin.y - frameRect.origin.y;
387 difference2 -= difference;
388 // Take in account the space between the top of window and the top of the
389 // screen which can be used to move the bottom of the window on the screen
390 if (difference2 > 0) {
391 frameRect.size.height -= difference2;
392 frameRect.origin.y += difference2;
395 /* Ensure that resizing doesn't makewindow smaller than minimum */
396 difference2 = [self minSize].height - frameRect.size.height;
397 if (difference2 > 0) {
398 frameRect.size.height += difference2;
399 frameRect.origin.y -= difference2;
409 Zooms the receiver. This method calls the delegate method
410 windowShouldZoom:toFrame: to determine if the window should
411 be allowed to zoom to full screen.
413 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
414 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
415 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
416 * Copyright (C) 1996 Free Software Foundation, Inc.
418 - (void) customZoom: (id)sender
420 NSRect maxRect = [[self screen] visibleFrame];
421 NSRect currentFrame = [self frame];
423 if ([[self delegate] respondsToSelector: @selector(windowWillUseStandardFrame:defaultFrame:)]) {
424 maxRect = [[self delegate] windowWillUseStandardFrame: self defaultFrame: maxRect];
427 maxRect = [self customConstrainFrameRect: maxRect toScreen: [self screen]];
429 // Compare the new frame with the current one
430 if ((abs(NSMaxX(maxRect) - NSMaxX(currentFrame)) < DIST)
431 && (abs(NSMaxY(maxRect) - NSMaxY(currentFrame)) < DIST)
432 && (abs(NSMinX(maxRect) - NSMinX(currentFrame)) < DIST)
433 && (abs(NSMinY(maxRect) - NSMinY(currentFrame)) < DIST)) {
434 // Already in zoomed mode, reset user frame, if stored
435 if ([self frameAutosaveName] != nil) {
436 [self setFrame: previousSavedFrame display: YES animate: YES];
437 [self saveFrameUsingName: [self frameAutosaveName]];
442 if ([self frameAutosaveName] != nil) {
443 [self saveFrameUsingName: [self frameAutosaveName]];
444 previousSavedFrame = [self frame];
447 [self setFrame: maxRect display: YES animate: YES];
451 #pragma mark Video window resizing logic
453 - (void)setWindowLevel:(NSInteger)i_state
455 if (var_InheritBool(VLCIntf, "video-wallpaper") || [self level] < NSNormalWindowLevel)
458 [self setLevel: i_state];
462 - (NSRect)getWindowRectForProposedVideoViewSize:(NSSize)size
464 NSSize windowMinSize = [self minSize];
465 NSRect screenFrame = [[self screen] visibleFrame];
467 NSPoint topleftbase = NSMakePoint(0, [self frame].size.height);
468 NSPoint topleftscreen = [self convertBaseToScreen: topleftbase];
470 unsigned int i_width = size.width;
471 unsigned int i_height = size.height;
472 if (i_width < windowMinSize.width)
473 i_width = windowMinSize.width;
474 if (i_height < f_min_video_height)
475 i_height = f_min_video_height;
477 /* Calculate the window's new size */
479 new_frame.size.width = [self frame].size.width - [o_video_view frame].size.width + i_width;
480 new_frame.size.height = [self frame].size.height - [o_video_view frame].size.height + i_height;
481 new_frame.origin.x = topleftscreen.x;
482 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
484 /* make sure the window doesn't exceed the screen size the window is on */
485 if (new_frame.size.width > screenFrame.size.width) {
486 new_frame.size.width = screenFrame.size.width;
487 new_frame.origin.x = screenFrame.origin.x;
489 if (new_frame.size.height > screenFrame.size.height) {
490 new_frame.size.height = screenFrame.size.height;
491 new_frame.origin.y = screenFrame.origin.y;
493 if (new_frame.origin.y < screenFrame.origin.y)
494 new_frame.origin.y = screenFrame.origin.y;
496 CGFloat right_screen_point = screenFrame.origin.x + screenFrame.size.width;
497 CGFloat right_window_point = new_frame.origin.x + new_frame.size.width;
498 if (right_window_point > right_screen_point)
499 new_frame.origin.x -= (right_window_point - right_screen_point);
506 if ([[VLCMainWindow sharedInstance] fullscreen])
509 NSRect window_rect = [self getWindowRectForProposedVideoViewSize:nativeVideoSize];
510 [[self animator] setFrame:window_rect display:YES];
513 - (void)setNativeVideoSize:(NSSize)size
515 nativeVideoSize = size;
517 if (var_InheritBool(VLCIntf, "macosx-video-autoresize") && !var_InheritBool(VLCIntf, "video-wallpaper"))
521 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
523 if (![[VLCMain sharedInstance] activeVideoPlayback] || nativeVideoSize.width == 0. || nativeVideoSize.height == 0. || window != self)
524 return proposedFrameSize;
526 // needed when entering lion fullscreen mode
527 if ([[VLCMainWindow sharedInstance] fullscreen])
528 return proposedFrameSize;
530 if ([[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]) {
531 NSRect videoWindowFrame = [self frame];
532 NSRect viewRect = [o_video_view convertRect:[o_video_view bounds] toView: nil];
533 NSRect contentRect = [self contentRectForFrameRect:videoWindowFrame];
534 float marginy = viewRect.origin.y + videoWindowFrame.size.height - contentRect.size.height;
535 float marginx = contentRect.size.width - viewRect.size.width;
536 if (o_titlebar_view && b_dark_interface)
537 marginy += [o_titlebar_view frame].size.height;
539 proposedFrameSize.height = (proposedFrameSize.width - marginx) * nativeVideoSize.height / nativeVideoSize.width + marginy;
542 return proposedFrameSize;
547 #pragma mark Lion native fullscreen handling
548 - (void)windowWillEnterFullScreen:(NSNotification *)notification
550 // workaround, see #6668
551 [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
553 var_SetBool(pl_Get(VLCIntf), "fullscreen", true);
555 if ([self hasActiveVideo]) {
556 vout_thread_t *p_vout = getVoutForActiveWindow();
558 var_SetBool(p_vout, "fullscreen", true);
559 vlc_object_release(p_vout);
563 [o_video_view setFrame: [[self contentView] frame]];
564 [[VLCMainWindow sharedInstance] setFullscreen: YES];
566 [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
567 i_originalLevel = [self level];
568 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
569 [self setLevel:NSNormalWindowLevel];
571 if (b_dark_interface) {
572 [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
575 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
576 winrect = [self frame];
578 winrect.size.height = winrect.size.height - f_titleBarHeight;
579 [self setFrame: winrect display:NO animate:NO];
582 // TODO fix bottom bar status when vout just not visible, but there
583 if (![o_video_view isHidden])
584 [[o_controls_bar bottomBarView] setHidden: YES];
586 [self setMovableByWindowBackground: NO];
589 - (void)windowDidEnterFullScreen:(NSNotification *)notification
591 // Indeed, we somehow can have an "inactive" fullscreen (but a visible window!).
592 // But this creates some problems when leaving fs over remote intfs, so activate app here.
593 [NSApp activateIgnoringOtherApps:YES];
595 if ([self hasActiveVideo]) {
596 [[[VLCMainWindow sharedInstance] fsPanel] setVoutWasUpdated: self];
597 [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
600 NSArray *subviews = [[self videoView] subviews];
601 NSUInteger count = [subviews count];
603 for (NSUInteger x = 0; x < count; x++) {
604 if ([[subviews objectAtIndex:x] respondsToSelector:@selector(reshape)])
605 [[subviews objectAtIndex:x] reshape];
610 - (void)windowWillExitFullScreen:(NSNotification *)notification
612 var_SetBool(pl_Get(VLCIntf), "fullscreen", false);
614 if ([self hasActiveVideo]) {
615 vout_thread_t *p_vout = getVoutForActiveWindow();
617 var_SetBool(p_vout, "fullscreen", false);
618 vlc_object_release(p_vout);
622 [NSCursor setHiddenUntilMouseMoves: NO];
623 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
624 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
625 [self setLevel:i_originalLevel];
627 [[VLCMainWindow sharedInstance] setFullscreen: NO];
629 if (b_dark_interface) {
631 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
632 winrect = [self frame];
634 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
635 winrect.size.width, f_titleBarHeight)];
636 [[self contentView] addSubview: o_titlebar_view];
638 winrect.size.height = winrect.size.height + f_titleBarHeight;
639 [self setFrame: winrect display:NO animate:NO];
640 winrect = [o_video_view frame];
641 winrect.size.height -= f_titleBarHeight;
642 [o_video_view setFrame: winrect];
645 NSRect videoViewFrame = [o_video_view frame];
646 videoViewFrame.origin.y = [[o_controls_bar bottomBarView] frame].size.height;
647 videoViewFrame.size.height -= [[o_controls_bar bottomBarView] frame].size.height;
648 [o_video_view setFrame: videoViewFrame];
649 [[o_controls_bar bottomBarView] setHidden: NO];
651 [self setMovableByWindowBackground: YES];
655 #pragma mark Fullscreen Logic
657 - (void)lockFullscreenAnimation
659 [o_animation_lock lock];
662 - (void)unlockFullscreenAnimation
664 [o_animation_lock unlock];
667 - (void)enterFullscreen
669 NSMutableDictionary *dict1, *dict2;
673 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
675 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
676 [self lockFullscreenAnimation];
679 msg_Dbg(VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode");
680 screen = [self screen];
683 msg_Dbg(VLCIntf, "Using deepest screen");
684 screen = [NSScreen deepestScreen];
687 screen_rect = [screen frame];
690 [o_controls_bar setFullscreenState:YES];
691 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:YES];
693 [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
695 if (blackout_other_displays)
696 [screen blackoutOtherScreens];
698 /* Make sure we don't see the window flashes in float-on-top mode */
699 i_originalLevel = [self level];
700 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
701 [self setLevel:NSNormalWindowLevel];
704 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
705 if (!o_fullscreen_window) {
706 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
708 rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
709 rect.origin.x += [self frame].origin.x;
710 rect.origin.y += [self frame].origin.y;
711 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
712 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
713 [o_fullscreen_window setCanBecomeKeyWindow: YES];
714 [o_fullscreen_window setCanBecomeMainWindow: YES];
716 if (![self isVisible] || [self alphaValue] == 0.0) {
717 /* We don't animate if we are not visible, instead we
718 * simply fade the display */
719 CGDisplayFadeReservationToken token;
721 if (blackout_other_displays) {
722 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
723 CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
726 NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
727 if ([screen hasMenuBar])
728 presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
729 if ([screen hasMenuBar] || [screen hasDock])
730 presentationOpts |= NSApplicationPresentationAutoHideDock;
731 [NSApp setPresentationOptions:presentationOpts];
733 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
734 [o_temp_view setFrame:[o_video_view frame]];
735 [o_fullscreen_window setContentView:o_video_view];
737 [o_fullscreen_window makeKeyAndOrderFront:self];
738 [o_fullscreen_window orderFront:self animate:YES];
740 [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
741 [o_fullscreen_window setLevel:NSNormalWindowLevel];
743 if (blackout_other_displays) {
744 CGDisplayFade(token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
745 CGReleaseDisplayFadeReservation(token);
748 /* Will release the lock */
749 [self hasBecomeFullscreen];
754 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
755 NSDisableScreenUpdates();
756 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
757 [o_temp_view setFrame:[o_video_view frame]];
758 [o_fullscreen_window setContentView:o_video_view];
759 [o_fullscreen_window makeKeyAndOrderFront:self];
760 NSEnableScreenUpdates();
763 /* We are in fullscreen (and no animation is running) */
764 if ([[VLCMainWindow sharedInstance] fullscreen]) {
765 /* Make sure we are hidden */
766 [self orderOut: self];
768 [self unlockFullscreenAnimation];
772 if (o_fullscreen_anim1) {
773 [o_fullscreen_anim1 stopAnimation];
774 [o_fullscreen_anim1 release];
776 if (o_fullscreen_anim2) {
777 [o_fullscreen_anim2 stopAnimation];
778 [o_fullscreen_anim2 release];
781 NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
782 if ([screen hasMenuBar])
783 presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
784 if ([screen hasMenuBar] || [screen hasDock])
785 presentationOpts |= NSApplicationPresentationAutoHideDock;
786 [NSApp setPresentationOptions:presentationOpts];
788 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
789 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
791 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
792 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
794 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
795 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
796 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
798 /* Strategy with NSAnimation allocation:
799 - Keep at most 2 animation at a time
800 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
802 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
803 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
808 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
809 [o_fullscreen_anim1 setDuration: 0.3];
810 [o_fullscreen_anim1 setFrameRate: 30];
811 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
812 [o_fullscreen_anim2 setDuration: 0.2];
813 [o_fullscreen_anim2 setFrameRate: 30];
815 [o_fullscreen_anim2 setDelegate: self];
816 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
818 [o_fullscreen_anim1 startAnimation];
819 /* fullscreenAnimation will be unlocked when animation ends */
822 - (void)hasBecomeFullscreen
824 if ([[o_video_view subviews] count] > 0)
825 [o_fullscreen_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
827 [o_fullscreen_window makeKeyWindow];
828 [o_fullscreen_window setAcceptsMouseMovedEvents: YES];
830 /* tell the fspanel to move itself to front next time it's triggered */
831 [[[VLCMainWindow sharedInstance] fsPanel] setVoutWasUpdated: o_fullscreen_window];
832 [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
834 if ([self isVisible])
835 [self orderOut: self];
837 [[VLCMainWindow sharedInstance] setFullscreen:YES];
838 [self unlockFullscreenAnimation];
841 - (void)leaveFullscreen
843 [self leaveFullscreenAndFadeOut: NO];
846 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
848 NSMutableDictionary *dict1, *dict2;
850 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
852 [self lockFullscreenAnimation];
855 [o_controls_bar setFullscreenState:NO];
856 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:NO];
858 /* We always try to do so */
859 [NSScreen unblackoutScreens];
861 [[o_video_view window] makeKeyAndOrderFront: nil];
863 /* Don't do anything if o_fullscreen_window is already closed */
864 if (!o_fullscreen_window) {
865 [self unlockFullscreenAnimation];
870 /* We don't animate if we are not visible, instead we
871 * simply fade the display */
872 CGDisplayFadeReservationToken token;
874 if (blackout_other_displays) {
875 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
876 CGDisplayFade(token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
879 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
880 [NSApp setPresentationOptions: NSApplicationPresentationDefault];
882 /* Will release the lock */
883 [self hasEndedFullscreen];
885 /* Our window is hidden, and might be faded. We need to workaround that, so note it
887 b_window_is_invisible = YES;
889 if (blackout_other_displays) {
890 CGDisplayFade(token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
891 CGReleaseDisplayFadeReservation(token);
897 [self setAlphaValue: 0.0];
898 [self orderFront: self];
899 [[o_video_view window] orderFront: self];
901 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
902 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
904 if (o_fullscreen_anim1) {
905 [o_fullscreen_anim1 stopAnimation];
906 [o_fullscreen_anim1 release];
908 if (o_fullscreen_anim2) {
909 [o_fullscreen_anim2 stopAnimation];
910 [o_fullscreen_anim2 release];
913 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
914 frame.origin.x += [self frame].origin.x;
915 frame.origin.y += [self frame].origin.y;
917 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
918 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
919 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
921 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
924 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
925 [o_fullscreen_anim2 setDuration: 0.3];
926 [o_fullscreen_anim2 setFrameRate: 30];
928 [o_fullscreen_anim2 setDelegate: self];
930 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
932 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
933 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
934 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
936 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
939 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
940 [o_fullscreen_anim1 setDuration: 0.2];
941 [o_fullscreen_anim1 setFrameRate: 30];
942 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
944 /* Make sure o_fullscreen_window is the frontmost window */
945 [o_fullscreen_window orderFront: self];
947 [o_fullscreen_anim1 startAnimation];
948 /* fullscreenAnimation will be unlocked when animation ends */
951 - (void)hasEndedFullscreen
953 [[VLCMainWindow sharedInstance] setFullscreen:NO];
955 /* This function is private and should be only triggered at the end of the fullscreen change animation */
956 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
957 NSDisableScreenUpdates();
958 [o_video_view retain];
959 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
960 [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
961 [o_video_view release];
962 [o_video_view setFrame:[o_temp_view frame]];
963 if ([[o_video_view subviews] count] > 0)
964 [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
966 [super makeKeyAndOrderFront:self]; /* our version (in main window) contains a workaround */
968 [o_fullscreen_window orderOut: self];
969 NSEnableScreenUpdates();
971 [o_fullscreen_window release];
972 o_fullscreen_window = nil;
974 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
975 [self setLevel:i_originalLevel];
976 [self setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
978 // if we quit fullscreen because there is no video anymore, make sure non-embedded window is not visible
979 if (![[VLCMain sharedInstance] activeVideoPlayback] && [self class] != [VLCMainWindow class])
980 [self orderOut: self];
982 [self unlockFullscreenAnimation];
985 - (void)animationDidEnd:(NSAnimation*)animation
987 NSArray *viewAnimations;
988 if (o_makekey_anim == animation) {
989 [o_makekey_anim release];
992 if ([animation currentValue] < 1.0)
995 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
996 viewAnimations = [o_fullscreen_anim2 viewAnimations];
997 if ([viewAnimations count] >=1 &&
998 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
999 /* Fullscreen ended */
1000 [self hasEndedFullscreen];
1002 /* Fullscreen started */
1003 [self hasBecomeFullscreen];
1007 #pragma mark Accessibility stuff
1009 - (NSArray *)accessibilityAttributeNames
1011 if (!b_dark_interface || !o_titlebar_view)
1012 return [super accessibilityAttributeNames];
1014 static NSMutableArray *attributes = nil;
1015 if (attributes == nil) {
1016 attributes = [[super accessibilityAttributeNames] mutableCopy];
1017 NSArray *appendAttributes = [NSArray arrayWithObjects: NSAccessibilitySubroleAttribute,
1018 NSAccessibilityCloseButtonAttribute,
1019 NSAccessibilityMinimizeButtonAttribute,
1020 NSAccessibilityZoomButtonAttribute,
1023 for(NSString *attribute in appendAttributes) {
1024 if (![attributes containsObject:attribute])
1025 [attributes addObject:attribute];
1031 - (id)accessibilityAttributeValue: (NSString*)o_attribute_name
1033 if (b_dark_interface && o_titlebar_view) {
1034 VLCMainWindowTitleView *o_tbv = o_titlebar_view;
1036 if ([o_attribute_name isEqualTo: NSAccessibilitySubroleAttribute])
1037 return NSAccessibilityStandardWindowSubrole;
1039 if ([o_attribute_name isEqualTo: NSAccessibilityCloseButtonAttribute])
1040 return [[o_tbv closeButton] cell];
1042 if ([o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute])
1043 return [[o_tbv minimizeButton] cell];
1045 if ([o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute])
1046 return [[o_tbv zoomButton] cell];
1049 return [super accessibilityAttributeValue: o_attribute_name];