1 /*****************************************************************************
2 * Windows.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2012-2013 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 arrayWithObject:dict]];
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 arrayWithObject:dict]];
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;
246 @synthesize enteringFullscreenTransition=b_entering_fullscreen_transition;
251 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
252 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
254 b_dark_interface = config_GetInt(VLCIntf, "macosx-interfacestyle");
256 if (b_dark_interface) {
257 styleMask = NSBorderlessWindowMask;
258 #ifdef MAC_OS_X_VERSION_10_7
259 if (!OSX_SNOW_LEOPARD)
260 styleMask |= NSResizableWindowMask;
264 self = [super initWithContentRect:contentRect styleMask:styleMask
265 backing:backingType defer:flag];
267 /* we want to be moveable regardless of our style */
268 [self setMovableByWindowBackground: YES];
269 [self setCanBecomeKeyWindow:YES];
271 o_temp_view = [[NSView alloc] init];
272 [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
279 [o_temp_view release];
285 BOOL b_nativeFullscreenMode = NO;
286 #ifdef MAC_OS_X_VERSION_10_7
287 if (!OSX_SNOW_LEOPARD)
288 b_nativeFullscreenMode = var_InheritBool(VLCIntf, "macosx-nativefullscreenmode");
291 if (b_nativeFullscreenMode) {
292 [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
294 [o_titlebar_view setFullscreenButtonHidden: YES];
297 [super awakeFromNib];
300 - (void)setTitle:(NSString *)title
302 if (!title || [title length] < 1)
305 if (b_dark_interface && o_titlebar_view)
306 [o_titlebar_view setWindowTitle: title];
308 [super setTitle: title];
312 #pragma mark zoom / minimize / close
314 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
316 SEL s_menuAction = [menuItem action];
318 if ((s_menuAction == @selector(performClose:)) || (s_menuAction == @selector(performMiniaturize:)) || (s_menuAction == @selector(performZoom:)))
321 return [super validateMenuItem:menuItem];
324 - (BOOL)windowShouldClose:(id)sender
329 - (void)performClose:(id)sender
331 if (!([self styleMask] & NSTitledWindowMask)) {
332 [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowWillCloseNotification object:self];
334 [self orderOut: sender];
336 [super performClose: sender];
339 - (void)performMiniaturize:(id)sender
341 if (!([self styleMask] & NSTitledWindowMask))
342 [self miniaturize: sender];
344 [super performMiniaturize: sender];
347 - (void)performZoom:(id)sender
349 if (!([self styleMask] & NSTitledWindowMask))
350 [self customZoom: sender];
352 [super performZoom: sender];
355 - (void)zoom:(id)sender
357 if (!([self styleMask] & NSTitledWindowMask))
358 [self customZoom: sender];
360 [super zoom: sender];
364 * Given a proposed frame rectangle, return a modified version
365 * which will fit inside the screen.
367 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
368 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
369 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
370 * Copyright (C) 1996 Free Software Foundation, Inc.
372 - (NSRect) customConstrainFrameRect: (NSRect)frameRect toScreen: (NSScreen*)screen
374 NSRect screenRect = [screen visibleFrame];
377 /* Move top edge of the window inside the screen */
378 difference = NSMaxY (frameRect) - NSMaxY (screenRect);
379 if (difference > 0) {
380 frameRect.origin.y -= difference;
383 /* If the window is resizable, resize it (if needed) so that the
384 bottom edge is on the screen or can be on the screen when the user moves
386 difference = NSMaxY (screenRect) - NSMaxY (frameRect);
387 if (_styleMask & NSResizableWindowMask) {
390 difference2 = screenRect.origin.y - frameRect.origin.y;
391 difference2 -= difference;
392 // Take in account the space between the top of window and the top of the
393 // screen which can be used to move the bottom of the window on the screen
394 if (difference2 > 0) {
395 frameRect.size.height -= difference2;
396 frameRect.origin.y += difference2;
399 /* Ensure that resizing doesn't makewindow smaller than minimum */
400 difference2 = [self minSize].height - frameRect.size.height;
401 if (difference2 > 0) {
402 frameRect.size.height += difference2;
403 frameRect.origin.y -= difference2;
413 Zooms the receiver. This method calls the delegate method
414 windowShouldZoom:toFrame: to determine if the window should
415 be allowed to zoom to full screen.
417 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
418 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
419 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
420 * Copyright (C) 1996 Free Software Foundation, Inc.
422 - (void) customZoom: (id)sender
424 NSRect maxRect = [[self screen] visibleFrame];
425 NSRect currentFrame = [self frame];
427 if ([[self delegate] respondsToSelector: @selector(windowWillUseStandardFrame:defaultFrame:)]) {
428 maxRect = [[self delegate] windowWillUseStandardFrame: self defaultFrame: maxRect];
431 maxRect = [self customConstrainFrameRect: maxRect toScreen: [self screen]];
433 // Compare the new frame with the current one
434 if ((abs(NSMaxX(maxRect) - NSMaxX(currentFrame)) < DIST)
435 && (abs(NSMaxY(maxRect) - NSMaxY(currentFrame)) < DIST)
436 && (abs(NSMinX(maxRect) - NSMinX(currentFrame)) < DIST)
437 && (abs(NSMinY(maxRect) - NSMinY(currentFrame)) < DIST)) {
438 // Already in zoomed mode, reset user frame, if stored
439 if ([self frameAutosaveName] != nil) {
440 [self setFrame: previousSavedFrame display: YES animate: YES];
441 [self saveFrameUsingName: [self frameAutosaveName]];
446 if ([self frameAutosaveName] != nil) {
447 [self saveFrameUsingName: [self frameAutosaveName]];
448 previousSavedFrame = [self frame];
451 [self setFrame: maxRect display: YES animate: YES];
455 #pragma mark Video window resizing logic
457 - (void)setWindowLevel:(NSInteger)i_state
459 if (var_InheritBool(VLCIntf, "video-wallpaper") || [self level] < NSNormalWindowLevel)
462 [self setLevel: i_state];
466 - (NSRect)getWindowRectForProposedVideoViewSize:(NSSize)size
468 NSSize windowMinSize = [self minSize];
469 NSRect screenFrame = [[self screen] visibleFrame];
471 NSPoint topleftbase = NSMakePoint(0, [self frame].size.height);
472 NSPoint topleftscreen = [self convertBaseToScreen: topleftbase];
474 unsigned int i_width = size.width;
475 unsigned int i_height = size.height;
476 if (i_width < windowMinSize.width)
477 i_width = windowMinSize.width;
478 if (i_height < f_min_video_height)
479 i_height = f_min_video_height;
481 /* Calculate the window's new size */
483 new_frame.size.width = [self frame].size.width - [o_video_view frame].size.width + i_width;
484 new_frame.size.height = [self frame].size.height - [o_video_view frame].size.height + i_height;
485 new_frame.origin.x = topleftscreen.x;
486 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
488 /* make sure the window doesn't exceed the screen size the window is on */
489 if (new_frame.size.width > screenFrame.size.width) {
490 new_frame.size.width = screenFrame.size.width;
491 new_frame.origin.x = screenFrame.origin.x;
493 if (new_frame.size.height > screenFrame.size.height) {
494 new_frame.size.height = screenFrame.size.height;
495 new_frame.origin.y = screenFrame.origin.y;
497 if (new_frame.origin.y < screenFrame.origin.y)
498 new_frame.origin.y = screenFrame.origin.y;
500 CGFloat right_screen_point = screenFrame.origin.x + screenFrame.size.width;
501 CGFloat right_window_point = new_frame.origin.x + new_frame.size.width;
502 if (right_window_point > right_screen_point)
503 new_frame.origin.x -= (right_window_point - right_screen_point);
510 if ([self fullscreen])
513 NSRect window_rect = [self getWindowRectForProposedVideoViewSize:nativeVideoSize];
514 [[self animator] setFrame:window_rect display:YES];
517 - (void)setNativeVideoSize:(NSSize)size
519 nativeVideoSize = size;
521 if (var_InheritBool(VLCIntf, "macosx-video-autoresize") && !var_InheritBool(VLCIntf, "video-wallpaper"))
525 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
527 if (![[VLCMain sharedInstance] activeVideoPlayback] || nativeVideoSize.width == 0. || nativeVideoSize.height == 0. || window != self)
528 return proposedFrameSize;
530 // needed when entering lion fullscreen mode
531 if (b_entering_fullscreen_transition || [self fullscreen])
532 return proposedFrameSize;
534 if ([[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]) {
535 NSRect videoWindowFrame = [self frame];
536 NSRect viewRect = [o_video_view convertRect:[o_video_view bounds] toView: nil];
537 NSRect contentRect = [self contentRectForFrameRect:videoWindowFrame];
538 float marginy = viewRect.origin.y + videoWindowFrame.size.height - contentRect.size.height;
539 float marginx = contentRect.size.width - viewRect.size.width;
540 if (o_titlebar_view && b_dark_interface)
541 marginy += [o_titlebar_view frame].size.height;
543 proposedFrameSize.height = (proposedFrameSize.width - marginx) * nativeVideoSize.height / nativeVideoSize.width + marginy;
546 return proposedFrameSize;
551 #pragma mark Mouse cursor handling
553 // NSTimer selectors require this function signature as per Apple's docs
554 - (void)hideMouseCursor:(NSTimer *)timer
556 [NSCursor setHiddenUntilMouseMoves: YES];
559 - (void)recreateHideMouseTimer
561 if (t_hide_mouse_timer != nil) {
562 [t_hide_mouse_timer invalidate];
563 [t_hide_mouse_timer release];
566 t_hide_mouse_timer = [NSTimer scheduledTimerWithTimeInterval:2
568 selector:@selector(hideMouseCursor:)
571 [t_hide_mouse_timer retain];
574 // Called automatically if window's acceptsMouseMovedEvents property is true
575 - (void)mouseMoved:(NSEvent *)theEvent
578 [self recreateHideMouseTimer];
580 [super mouseMoved: theEvent];
584 #pragma mark Lion native fullscreen handling
586 - (void)becomeKeyWindow
588 [super becomeKeyWindow];
590 // change fspanel state for the case when multiple windows are in fullscreen
591 if ([self hasActiveVideo] && [self fullscreen])
592 [[[VLCMainWindow sharedInstance] fsPanel] setActive:nil];
594 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive:nil];
597 - (void)resignKeyWindow
599 [super resignKeyWindow];
601 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive:nil];
604 - (void)windowWillEnterFullScreen:(NSNotification *)notification
606 // workaround, see #6668
607 [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
609 b_entering_fullscreen_transition = YES;
611 var_SetBool(pl_Get(VLCIntf), "fullscreen", true);
613 if ([self hasActiveVideo]) {
614 vout_thread_t *p_vout = getVoutForActiveWindow();
616 var_SetBool(p_vout, "fullscreen", true);
617 vlc_object_release(p_vout);
621 if ([self hasActiveVideo])
622 [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
624 i_originalLevel = [self level];
625 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
626 [self setLevel:NSNormalWindowLevel];
628 if (b_dark_interface) {
629 [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
632 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
633 winrect = [self frame];
635 winrect.size.height = winrect.size.height - f_titleBarHeight;
636 [self setFrame: winrect display:NO animate:NO];
639 [o_video_view setFrame: [[self contentView] frame]];
640 if (![o_video_view isHidden]) {
641 [[o_controls_bar bottomBarView] setHidden: YES];
645 [self setMovableByWindowBackground: NO];
648 - (void)windowDidEnterFullScreen:(NSNotification *)notification
650 // Indeed, we somehow can have an "inactive" fullscreen (but a visible window!).
651 // But this creates some problems when leaving fs over remote intfs, so activate app here.
652 [NSApp activateIgnoringOtherApps:YES];
654 [self setFullscreen: YES];
655 b_entering_fullscreen_transition = NO;
657 if ([self hasActiveVideo]) {
658 [[[VLCMainWindow sharedInstance] fsPanel] setVoutWasUpdated: self];
659 if (![o_video_view isHidden])
660 [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
663 NSArray *subviews = [[self videoView] subviews];
664 NSUInteger count = [subviews count];
666 for (NSUInteger x = 0; x < count; x++) {
667 if ([[subviews objectAtIndex:x] respondsToSelector:@selector(reshape)])
668 [[subviews objectAtIndex:x] reshape];
673 - (void)windowWillExitFullScreen:(NSNotification *)notification
675 [self setFullscreen: NO];
677 var_SetBool(pl_Get(VLCIntf), "fullscreen", false);
679 if ([self hasActiveVideo]) {
680 vout_thread_t *p_vout = getVoutForActiveWindow();
682 var_SetBool(p_vout, "fullscreen", false);
683 vlc_object_release(p_vout);
687 [NSCursor setHiddenUntilMouseMoves: NO];
688 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
690 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
691 [self setLevel:i_originalLevel];
693 if (b_dark_interface) {
695 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
697 winrect = [o_video_view frame];
698 winrect.size.height -= f_titleBarHeight;
699 [o_video_view setFrame: winrect];
701 winrect = [self frame];
702 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
703 winrect.size.width, f_titleBarHeight)];
704 [[self contentView] addSubview: o_titlebar_view];
706 winrect.size.height = winrect.size.height + f_titleBarHeight;
707 [self setFrame: winrect display:NO animate:NO];
710 NSRect videoViewFrame = [o_video_view frame];
711 videoViewFrame.origin.y += [o_controls_bar height];
712 videoViewFrame.size.height -= [o_controls_bar height];
713 [o_video_view setFrame: videoViewFrame];
715 if (![o_video_view isHidden]) {
716 [[o_controls_bar bottomBarView] setHidden: NO];
719 [self setMovableByWindowBackground: YES];
723 #pragma mark Fullscreen Logic
725 - (void)enterFullscreen
727 NSMutableDictionary *dict1, *dict2;
731 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
733 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
736 msg_Dbg(VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode");
737 screen = [self screen];
740 msg_Dbg(VLCIntf, "Using deepest screen");
741 screen = [NSScreen deepestScreen];
744 screen_rect = [screen frame];
747 [o_controls_bar setFullscreenState:YES];
748 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:YES];
750 [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
752 if (blackout_other_displays)
753 [screen blackoutOtherScreens];
755 /* Make sure we don't see the window flashes in float-on-top mode */
756 i_originalLevel = [self level];
757 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
758 [self setLevel:NSNormalWindowLevel];
761 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
762 if (!o_fullscreen_window) {
763 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
765 rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
766 rect.origin.x += [self frame].origin.x;
767 rect.origin.y += [self frame].origin.y;
768 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
769 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
770 [o_fullscreen_window setCanBecomeKeyWindow: YES];
771 [o_fullscreen_window setCanBecomeMainWindow: YES];
772 [o_fullscreen_window setHasActiveVideo: YES];
773 [o_fullscreen_window setFullscreen: YES];
775 if (![self isVisible] || [self alphaValue] == 0.0) {
776 /* We don't animate if we are not visible, instead we
777 * simply fade the display */
778 CGDisplayFadeReservationToken token;
780 if (blackout_other_displays) {
781 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
782 CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
785 [screen setFullscreenPresentationOptions];
787 [o_video_view retain];
788 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
789 [o_temp_view setFrame:[o_video_view frame]];
790 [o_fullscreen_window setContentView:o_video_view];
791 [o_video_view release];
793 [o_fullscreen_window makeKeyAndOrderFront:self];
794 [o_fullscreen_window orderFront:self animate:YES];
796 [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
797 [o_fullscreen_window setLevel:NSNormalWindowLevel];
799 if (blackout_other_displays) {
800 CGDisplayFade(token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
801 CGReleaseDisplayFadeReservation(token);
804 /* Will release the lock */
805 [self hasBecomeFullscreen];
810 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
811 NSDisableScreenUpdates();
812 [o_video_view retain];
813 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
814 [o_temp_view setFrame:[o_video_view frame]];
815 [o_fullscreen_window setContentView:o_video_view];
816 [o_video_view release];
817 [o_fullscreen_window makeKeyAndOrderFront:self];
818 NSEnableScreenUpdates();
821 /* We are in fullscreen (and no animation is running) */
822 if ([self fullscreen]) {
823 /* Make sure we are hidden */
824 [self orderOut: self];
829 if (o_fullscreen_anim1) {
830 [o_fullscreen_anim1 stopAnimation];
831 [o_fullscreen_anim1 release];
833 if (o_fullscreen_anim2) {
834 [o_fullscreen_anim2 stopAnimation];
835 [o_fullscreen_anim2 release];
838 [screen setFullscreenPresentationOptions];
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];
892 - (void)leaveFullscreen
894 [self leaveFullscreenAndFadeOut: NO];
897 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
899 NSMutableDictionary *dict1, *dict2;
901 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
904 [o_controls_bar setFullscreenState:NO];
905 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:NO];
907 /* We always try to do so */
908 [NSScreen unblackoutScreens];
910 [[o_video_view window] makeKeyAndOrderFront: nil];
912 /* Don't do anything if o_fullscreen_window is already closed */
913 if (!o_fullscreen_window) {
918 /* We don't animate if we are not visible, instead we
919 * simply fade the display */
920 CGDisplayFadeReservationToken token;
922 if (blackout_other_displays) {
923 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
924 CGDisplayFade(token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
927 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
928 [[o_fullscreen_window screen] setNonFullscreenPresentationOptions];
930 /* Will release the lock */
931 [self hasEndedFullscreen];
933 /* Our window is hidden, and might be faded. We need to workaround that, so note it
935 b_window_is_invisible = YES;
937 if (blackout_other_displays) {
938 CGDisplayFade(token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
939 CGReleaseDisplayFadeReservation(token);
945 [self setAlphaValue: 0.0];
946 [self orderFront: self];
947 [[o_video_view window] orderFront: self];
949 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
950 [[o_fullscreen_window screen] setNonFullscreenPresentationOptions];
952 if (o_fullscreen_anim1) {
953 [o_fullscreen_anim1 stopAnimation];
954 [o_fullscreen_anim1 release];
956 if (o_fullscreen_anim2) {
957 [o_fullscreen_anim2 stopAnimation];
958 [o_fullscreen_anim2 release];
961 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
962 frame.origin.x += [self frame].origin.x;
963 frame.origin.y += [self frame].origin.y;
965 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
966 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
967 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
969 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
972 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
973 [o_fullscreen_anim2 setDuration: 0.3];
974 [o_fullscreen_anim2 setFrameRate: 30];
976 [o_fullscreen_anim2 setDelegate: self];
978 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
980 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
981 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
982 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
984 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
987 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
988 [o_fullscreen_anim1 setDuration: 0.2];
989 [o_fullscreen_anim1 setFrameRate: 30];
990 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
992 /* Make sure o_fullscreen_window is the frontmost window */
993 [o_fullscreen_window orderFront: self];
995 [o_fullscreen_anim1 startAnimation];
996 /* fullscreenAnimation will be unlocked when animation ends */
999 - (void)hasEndedFullscreen
1001 [self setFullscreen:NO];
1003 /* This function is private and should be only triggered at the end of the fullscreen change animation */
1004 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
1005 NSDisableScreenUpdates();
1006 [o_video_view retain];
1007 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1008 [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
1009 [o_video_view release];
1010 [o_video_view setFrame:[o_temp_view frame]];
1011 if ([[o_video_view subviews] count] > 0)
1012 [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
1014 [super makeKeyAndOrderFront:self]; /* our version (in main window) contains a workaround */
1016 [o_fullscreen_window orderOut: self];
1017 NSEnableScreenUpdates();
1019 [o_fullscreen_window release];
1020 o_fullscreen_window = nil;
1022 [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
1023 [self setLevel:i_originalLevel];
1024 [self setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
1026 // if we quit fullscreen because there is no video anymore, make sure non-embedded window is not visible
1027 if (![[VLCMain sharedInstance] activeVideoPlayback] && [self class] != [VLCMainWindow class])
1028 [self orderOut: self];
1031 - (void)animationDidEnd:(NSAnimation*)animation
1033 NSArray *viewAnimations;
1034 if (o_makekey_anim == animation) {
1035 [o_makekey_anim release];
1038 if ([animation currentValue] < 1.0)
1041 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
1042 viewAnimations = [o_fullscreen_anim2 viewAnimations];
1043 if ([viewAnimations count] >=1 &&
1044 [[[viewAnimations objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
1045 /* Fullscreen ended */
1046 [self hasEndedFullscreen];
1048 /* Fullscreen started */
1049 [self hasBecomeFullscreen];
1052 - (void)orderOut:(id)sender
1054 [super orderOut:sender];
1057 * TODO reimplement leaveFullscreenAndFadeOut:YES, or remove code
1058 * and the hack below
1060 if (![NSStringFromClass([self class]) isEqualToString:@"VLCMainWindow"]) {
1061 [self leaveFullscreenAndFadeOut:YES];
1066 - (void)makeKeyAndOrderFront: (id)sender
1069 * when we exit fullscreen and fade out, we may endup in
1070 * having a window that is faded. We can't have it fade in unless we
1073 if (!b_window_is_invisible) {
1074 /* Make sure we don't do it too much */
1075 [super makeKeyAndOrderFront: sender];
1079 [super setAlphaValue:0.0f];
1080 [super makeKeyAndOrderFront: sender];
1082 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
1083 [dict setObject:self forKey:NSViewAnimationTargetKey];
1084 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
1086 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
1089 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
1090 [o_makekey_anim setDuration: 0.1];
1091 [o_makekey_anim setFrameRate: 30];
1092 [o_makekey_anim setDelegate: self];
1094 [o_makekey_anim startAnimation];
1095 b_window_is_invisible = NO;
1097 /* fullscreenAnimation will be unlocked when animation ends */
1102 #pragma mark Accessibility stuff
1104 - (NSArray *)accessibilityAttributeNames
1106 if (!b_dark_interface || !o_titlebar_view)
1107 return [super accessibilityAttributeNames];
1109 static NSMutableArray *attributes = nil;
1110 if (attributes == nil) {
1111 attributes = [[super accessibilityAttributeNames] mutableCopy];
1112 NSArray *appendAttributes = [NSArray arrayWithObjects:NSAccessibilitySubroleAttribute,
1113 NSAccessibilityCloseButtonAttribute,
1114 NSAccessibilityMinimizeButtonAttribute,
1115 NSAccessibilityZoomButtonAttribute, nil];
1117 for(NSString *attribute in appendAttributes) {
1118 if (![attributes containsObject:attribute])
1119 [attributes addObject:attribute];
1125 - (id)accessibilityAttributeValue: (NSString*)o_attribute_name
1127 if (b_dark_interface && o_titlebar_view) {
1128 VLCMainWindowTitleView *o_tbv = o_titlebar_view;
1130 if ([o_attribute_name isEqualTo: NSAccessibilitySubroleAttribute])
1131 return NSAccessibilityStandardWindowSubrole;
1133 if ([o_attribute_name isEqualTo: NSAccessibilityCloseButtonAttribute])
1134 return [[o_tbv closeButton] cell];
1136 if ([o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute])
1137 return [[o_tbv minimizeButton] cell];
1139 if ([o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute])
1140 return [[o_tbv zoomButton] cell];
1143 return [super accessibilityAttributeValue: o_attribute_name];