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;
246 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
247 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
249 b_dark_interface = config_GetInt(VLCIntf, "macosx-interfacestyle");
251 if (b_dark_interface) {
252 styleMask = NSBorderlessWindowMask;
253 #ifdef MAC_OS_X_VERSION_10_7
254 if (!OSX_SNOW_LEOPARD)
255 styleMask |= NSResizableWindowMask;
259 self = [super initWithContentRect:contentRect styleMask:styleMask
260 backing:backingType defer:flag];
262 /* we want to be moveable regardless of our style */
263 [self setMovableByWindowBackground: YES];
264 [self setCanBecomeKeyWindow:YES];
266 o_temp_view = [[NSView alloc] init];
267 [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
274 [o_temp_view release];
278 - (void)setTitle:(NSString *)title
280 if (!title || [title length] < 1)
283 if (b_dark_interface && o_titlebar_view)
284 [o_titlebar_view setWindowTitle: title];
286 [super setTitle: title];
290 #pragma mark zoom / minimize / close
292 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
294 SEL s_menuAction = [menuItem action];
296 if ((s_menuAction == @selector(performClose:)) || (s_menuAction == @selector(performMiniaturize:)) || (s_menuAction == @selector(performZoom:)))
299 return [super validateMenuItem:menuItem];
302 - (BOOL)windowShouldClose:(id)sender
307 - (void)performClose:(id)sender
309 if (!([self styleMask] & NSTitledWindowMask)) {
310 [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowWillCloseNotification object:self];
312 [self orderOut: sender];
314 [super performClose: sender];
317 - (void)performMiniaturize:(id)sender
319 if (!([self styleMask] & NSTitledWindowMask))
320 [self miniaturize: sender];
322 [super performMiniaturize: sender];
325 - (void)performZoom:(id)sender
327 if (!([self styleMask] & NSTitledWindowMask))
328 [self customZoom: sender];
330 [super performZoom: sender];
333 - (void)zoom:(id)sender
335 if (!([self styleMask] & NSTitledWindowMask))
336 [self customZoom: sender];
338 [super zoom: sender];
342 * Given a proposed frame rectangle, return a modified version
343 * which will fit inside the screen.
345 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
346 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
347 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
348 * Copyright (C) 1996 Free Software Foundation, Inc.
350 - (NSRect) customConstrainFrameRect: (NSRect)frameRect toScreen: (NSScreen*)screen
352 NSRect screenRect = [screen visibleFrame];
355 /* Move top edge of the window inside the screen */
356 difference = NSMaxY (frameRect) - NSMaxY (screenRect);
357 if (difference > 0) {
358 frameRect.origin.y -= difference;
361 /* If the window is resizable, resize it (if needed) so that the
362 bottom edge is on the screen or can be on the screen when the user moves
364 difference = NSMaxY (screenRect) - NSMaxY (frameRect);
365 if (_styleMask & NSResizableWindowMask) {
368 difference2 = screenRect.origin.y - frameRect.origin.y;
369 difference2 -= difference;
370 // Take in account the space between the top of window and the top of the
371 // screen which can be used to move the bottom of the window on the screen
372 if (difference2 > 0) {
373 frameRect.size.height -= difference2;
374 frameRect.origin.y += difference2;
377 /* Ensure that resizing doesn't makewindow smaller than minimum */
378 difference2 = [self minSize].height - frameRect.size.height;
379 if (difference2 > 0) {
380 frameRect.size.height += difference2;
381 frameRect.origin.y -= difference2;
391 Zooms the receiver. This method calls the delegate method
392 windowShouldZoom:toFrame: to determine if the window should
393 be allowed to zoom to full screen.
395 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
396 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
397 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
398 * Copyright (C) 1996 Free Software Foundation, Inc.
400 - (void) customZoom: (id)sender
402 NSRect maxRect = [[self screen] visibleFrame];
403 NSRect currentFrame = [self frame];
405 if ([[self delegate] respondsToSelector: @selector(windowWillUseStandardFrame:defaultFrame:)]) {
406 maxRect = [[self delegate] windowWillUseStandardFrame: self defaultFrame: maxRect];
409 maxRect = [self customConstrainFrameRect: maxRect toScreen: [self screen]];
411 // Compare the new frame with the current one
412 if ((abs(NSMaxX(maxRect) - NSMaxX(currentFrame)) < DIST)
413 && (abs(NSMaxY(maxRect) - NSMaxY(currentFrame)) < DIST)
414 && (abs(NSMinX(maxRect) - NSMinX(currentFrame)) < DIST)
415 && (abs(NSMinY(maxRect) - NSMinY(currentFrame)) < DIST)) {
416 // Already in zoomed mode, reset user frame, if stored
417 if ([self frameAutosaveName] != nil) {
418 [self setFrame: previousSavedFrame display: YES animate: YES];
419 [self saveFrameUsingName: [self frameAutosaveName]];
424 if ([self frameAutosaveName] != nil) {
425 [self saveFrameUsingName: [self frameAutosaveName]];
426 previousSavedFrame = [self frame];
429 [self setFrame: maxRect display: YES animate: YES];
433 #pragma mark Video window resizing logic
435 - (NSRect)getWindowRectForProposedVideoViewSize:(NSSize)size
437 NSSize windowMinSize = [self minSize];
438 NSRect screenFrame = [[self screen] visibleFrame];
440 NSPoint topleftbase = NSMakePoint(0, [self frame].size.height);
441 NSPoint topleftscreen = [self convertBaseToScreen: topleftbase];
443 unsigned int i_width = size.width;
444 unsigned int i_height = size.height;
445 if (i_width < windowMinSize.width)
446 i_width = windowMinSize.width;
447 if (i_height < f_min_video_height)
448 i_height = f_min_video_height;
450 /* Calculate the window's new size */
452 new_frame.size.width = [self frame].size.width - [o_video_view frame].size.width + i_width;
453 new_frame.size.height = [self frame].size.height - [o_video_view frame].size.height + i_height;
454 new_frame.origin.x = topleftscreen.x;
455 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
457 /* make sure the window doesn't exceed the screen size the window is on */
458 if (new_frame.size.width > screenFrame.size.width) {
459 new_frame.size.width = screenFrame.size.width;
460 new_frame.origin.x = screenFrame.origin.x;
462 if (new_frame.size.height > screenFrame.size.height) {
463 new_frame.size.height = screenFrame.size.height;
464 new_frame.origin.y = screenFrame.origin.y;
466 if (new_frame.origin.y < screenFrame.origin.y)
467 new_frame.origin.y = screenFrame.origin.y;
469 CGFloat right_screen_point = screenFrame.origin.x + screenFrame.size.width;
470 CGFloat right_window_point = new_frame.origin.x + new_frame.size.width;
471 if (right_window_point > right_screen_point)
472 new_frame.origin.x -= (right_window_point - right_screen_point);
479 if ([[VLCMainWindow sharedInstance] fullscreen])
482 NSRect window_rect = [self getWindowRectForProposedVideoViewSize:nativeVideoSize];
483 [[self animator] setFrame:window_rect display:YES];
486 - (void)setNativeVideoSize:(NSSize)size
488 nativeVideoSize = size;
490 if (var_InheritBool(VLCIntf, "macosx-video-autoresize") && !var_InheritBool(VLCIntf, "video-wallpaper"))
494 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
496 if (![[VLCMain sharedInstance] activeVideoPlayback] || nativeVideoSize.width == 0. || nativeVideoSize.height == 0. || window != self)
497 return proposedFrameSize;
499 // needed when entering lion fullscreen mode
500 if ([[VLCMainWindow sharedInstance] fullscreen])
501 return proposedFrameSize;
503 if ([[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]) {
504 NSRect videoWindowFrame = [self frame];
505 NSRect viewRect = [o_video_view convertRect:[o_video_view bounds] toView: nil];
506 NSRect contentRect = [self contentRectForFrameRect:videoWindowFrame];
507 float marginy = viewRect.origin.y + videoWindowFrame.size.height - contentRect.size.height;
508 float marginx = contentRect.size.width - viewRect.size.width;
509 if (o_titlebar_view && b_dark_interface)
510 marginy += [o_titlebar_view frame].size.height;
512 proposedFrameSize.height = (proposedFrameSize.width - marginx) * nativeVideoSize.height / nativeVideoSize.width + marginy;
515 return proposedFrameSize;
519 #pragma mark Fullscreen Logic
521 - (void)lockFullscreenAnimation
523 [o_animation_lock lock];
526 - (void)unlockFullscreenAnimation
528 [o_animation_lock unlock];
531 - (void)enterFullscreen
533 NSMutableDictionary *dict1, *dict2;
537 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
539 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
540 [self lockFullscreenAnimation];
543 msg_Dbg(VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode");
544 screen = [self screen];
547 msg_Dbg(VLCIntf, "Using deepest screen");
548 screen = [NSScreen deepestScreen];
551 screen_rect = [screen frame];
554 [o_controls_bar setFullscreenState:YES];
555 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:YES];
557 [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
559 if (blackout_other_displays)
560 [screen blackoutOtherScreens];
562 /* Make sure we don't see the window flashes in float-on-top mode */
563 i_originalLevel = [self level];
564 [self setLevel:NSNormalWindowLevel];
566 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
567 if (!o_fullscreen_window) {
568 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
570 rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
571 rect.origin.x += [self frame].origin.x;
572 rect.origin.y += [self frame].origin.y;
573 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
574 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
575 [o_fullscreen_window setCanBecomeKeyWindow: YES];
576 [o_fullscreen_window setCanBecomeMainWindow: YES];
578 if (![self isVisible] || [self alphaValue] == 0.0) {
579 /* We don't animate if we are not visible, instead we
580 * simply fade the display */
581 CGDisplayFadeReservationToken token;
583 if (blackout_other_displays) {
584 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
585 CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
588 NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
589 if ([screen hasMenuBar])
590 presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
591 if ([screen hasMenuBar] || [screen hasDock])
592 presentationOpts |= NSApplicationPresentationAutoHideDock;
593 [NSApp setPresentationOptions:presentationOpts];
595 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
596 [o_temp_view setFrame:[o_video_view frame]];
597 [o_fullscreen_window setContentView:o_video_view];
599 [o_fullscreen_window makeKeyAndOrderFront:self];
600 [o_fullscreen_window orderFront:self animate:YES];
602 [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
603 [o_fullscreen_window setLevel:NSNormalWindowLevel];
605 if (blackout_other_displays) {
606 CGDisplayFade(token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
607 CGReleaseDisplayFadeReservation(token);
610 /* Will release the lock */
611 [self hasBecomeFullscreen];
616 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
617 NSDisableScreenUpdates();
618 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
619 [o_temp_view setFrame:[o_video_view frame]];
620 [o_fullscreen_window setContentView:o_video_view];
621 [o_fullscreen_window makeKeyAndOrderFront:self];
622 NSEnableScreenUpdates();
625 /* We are in fullscreen (and no animation is running) */
626 if ([[VLCMainWindow sharedInstance] fullscreen]) {
627 /* Make sure we are hidden */
628 [self orderOut: self];
630 [self unlockFullscreenAnimation];
634 if (o_fullscreen_anim1) {
635 [o_fullscreen_anim1 stopAnimation];
636 [o_fullscreen_anim1 release];
638 if (o_fullscreen_anim2) {
639 [o_fullscreen_anim2 stopAnimation];
640 [o_fullscreen_anim2 release];
643 NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
644 if ([screen hasMenuBar])
645 presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
646 if ([screen hasMenuBar] || [screen hasDock])
647 presentationOpts |= NSApplicationPresentationAutoHideDock;
648 [NSApp setPresentationOptions:presentationOpts];
650 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
651 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
653 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
654 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
656 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
657 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
658 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
660 /* Strategy with NSAnimation allocation:
661 - Keep at most 2 animation at a time
662 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
664 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
665 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
670 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
671 [o_fullscreen_anim1 setDuration: 0.3];
672 [o_fullscreen_anim1 setFrameRate: 30];
673 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
674 [o_fullscreen_anim2 setDuration: 0.2];
675 [o_fullscreen_anim2 setFrameRate: 30];
677 [o_fullscreen_anim2 setDelegate: self];
678 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
680 [o_fullscreen_anim1 startAnimation];
681 /* fullscreenAnimation will be unlocked when animation ends */
684 - (void)hasBecomeFullscreen
686 if ([[o_video_view subviews] count] > 0)
687 [o_fullscreen_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
689 [o_fullscreen_window makeKeyWindow];
690 [o_fullscreen_window setAcceptsMouseMovedEvents: YES];
692 /* tell the fspanel to move itself to front next time it's triggered */
693 [[[VLCMainWindow sharedInstance] fsPanel] setVoutWasUpdated: o_fullscreen_window];
694 [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
696 if ([self isVisible])
697 [self orderOut: self];
699 [[VLCMainWindow sharedInstance] setFullscreen:YES];
700 [self unlockFullscreenAnimation];
703 - (void)leaveFullscreen
705 [self leaveFullscreenAndFadeOut: NO];
708 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
710 NSMutableDictionary *dict1, *dict2;
712 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
714 [self lockFullscreenAnimation];
717 [o_controls_bar setFullscreenState:NO];
718 [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:NO];
720 /* We always try to do so */
721 [NSScreen unblackoutScreens];
723 vout_thread_t *p_vout = getVoutForActiveWindow();
725 if (var_GetBool(p_vout, "video-on-top"))
726 [[o_video_view window] setLevel: NSStatusWindowLevel];
728 [[o_video_view window] setLevel: NSNormalWindowLevel];
729 vlc_object_release(p_vout);
731 [[o_video_view window] makeKeyAndOrderFront: nil];
733 /* Don't do anything if o_fullscreen_window is already closed */
734 if (!o_fullscreen_window) {
735 [self unlockFullscreenAnimation];
740 /* We don't animate if we are not visible, instead we
741 * simply fade the display */
742 CGDisplayFadeReservationToken token;
744 if (blackout_other_displays) {
745 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
746 CGDisplayFade(token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
749 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
750 [NSApp setPresentationOptions: NSApplicationPresentationDefault];
752 /* Will release the lock */
753 [self hasEndedFullscreen];
755 /* Our window is hidden, and might be faded. We need to workaround that, so note it
757 b_window_is_invisible = YES;
759 if (blackout_other_displays) {
760 CGDisplayFade(token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
761 CGReleaseDisplayFadeReservation(token);
767 [self setAlphaValue: 0.0];
768 [self orderFront: self];
769 [[o_video_view window] orderFront: self];
771 [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
772 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
774 if (o_fullscreen_anim1) {
775 [o_fullscreen_anim1 stopAnimation];
776 [o_fullscreen_anim1 release];
778 if (o_fullscreen_anim2) {
779 [o_fullscreen_anim2 stopAnimation];
780 [o_fullscreen_anim2 release];
783 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
784 frame.origin.x += [self frame].origin.x;
785 frame.origin.y += [self frame].origin.y;
787 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
788 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
789 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
791 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
794 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
795 [o_fullscreen_anim2 setDuration: 0.3];
796 [o_fullscreen_anim2 setFrameRate: 30];
798 [o_fullscreen_anim2 setDelegate: self];
800 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
802 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
803 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
804 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
806 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
809 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
810 [o_fullscreen_anim1 setDuration: 0.2];
811 [o_fullscreen_anim1 setFrameRate: 30];
812 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
814 /* Make sure o_fullscreen_window is the frontmost window */
815 [o_fullscreen_window orderFront: self];
817 [o_fullscreen_anim1 startAnimation];
818 /* fullscreenAnimation will be unlocked when animation ends */
821 - (void)hasEndedFullscreen
823 [[VLCMainWindow sharedInstance] setFullscreen:NO];
825 /* This function is private and should be only triggered at the end of the fullscreen change animation */
826 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
827 NSDisableScreenUpdates();
828 [o_video_view retain];
829 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
830 [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
831 [o_video_view release];
832 [o_video_view setFrame:[o_temp_view frame]];
833 if ([[o_video_view subviews] count] > 0)
834 [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
836 [super makeKeyAndOrderFront:self]; /* our version (in main window) contains a workaround */
838 [o_fullscreen_window orderOut: self];
839 NSEnableScreenUpdates();
841 [o_fullscreen_window release];
842 o_fullscreen_window = nil;
843 [self setLevel:i_originalLevel];
844 [self setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
846 // if we quit fullscreen because there is no video anymore, make sure non-embedded window is not visible
847 if (![[VLCMain sharedInstance] activeVideoPlayback] && [self class] != [VLCMainWindow class])
848 [self orderOut: self];
850 [self unlockFullscreenAnimation];
853 - (void)animationDidEnd:(NSAnimation*)animation
855 NSArray *viewAnimations;
856 if (o_makekey_anim == animation) {
857 [o_makekey_anim release];
860 if ([animation currentValue] < 1.0)
863 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
864 viewAnimations = [o_fullscreen_anim2 viewAnimations];
865 if ([viewAnimations count] >=1 &&
866 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
867 /* Fullscreen ended */
868 [self hasEndedFullscreen];
870 /* Fullscreen started */
871 [self hasBecomeFullscreen];
875 #pragma mark Accessibility stuff
877 - (NSArray *)accessibilityAttributeNames
879 if (!b_dark_interface || !o_titlebar_view)
880 return [super accessibilityAttributeNames];
882 static NSMutableArray *attributes = nil;
883 if (attributes == nil) {
884 attributes = [[super accessibilityAttributeNames] mutableCopy];
885 NSArray *appendAttributes = [NSArray arrayWithObjects: NSAccessibilitySubroleAttribute,
886 NSAccessibilityCloseButtonAttribute,
887 NSAccessibilityMinimizeButtonAttribute,
888 NSAccessibilityZoomButtonAttribute,
891 for(NSString *attribute in appendAttributes) {
892 if (![attributes containsObject:attribute])
893 [attributes addObject:attribute];
899 - (id)accessibilityAttributeValue: (NSString*)o_attribute_name
901 if (b_dark_interface && o_titlebar_view) {
902 VLCMainWindowTitleView *o_tbv = o_titlebar_view;
904 if ([o_attribute_name isEqualTo: NSAccessibilitySubroleAttribute])
905 return NSAccessibilityStandardWindowSubrole;
907 if ([o_attribute_name isEqualTo: NSAccessibilityCloseButtonAttribute])
908 return [[o_tbv closeButton] cell];
910 if ([o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute])
911 return [[o_tbv minimizeButton] cell];
913 if ([o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute])
914 return [[o_tbv zoomButton] cell];
917 return [super accessibilityAttributeValue: o_attribute_name];