embeddedwindow.m
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:21k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * embeddedwindow.m: MacOS X interface module
  3.  *****************************************************************************
  4.  * Copyright (C) 2005-2009 the VideoLAN team
  5.  * $Id: 123dd4818502097e82beff992e33bfd8cdda45f9 $
  6.  *
  7.  * Authors: Benjamin Pracht <bigben at videolan dot org>
  8.  *          Felix Paul Kühne <fkuehne at videolan dot org>
  9.  *
  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.
  14.  *
  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.
  19.  *
  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.  *****************************************************************************/
  24. /*****************************************************************************
  25.  * Preamble
  26.  *****************************************************************************/
  27. #import "intf.h"
  28. #import "controls.h"
  29. #import "vout.h"
  30. #import "embeddedwindow.h"
  31. #import "fspanel.h"
  32. /* SetSystemUIMode, ... */
  33. #import <Carbon/Carbon.h>
  34. /*****************************************************************************
  35.  * VLCEmbeddedWindow Implementation
  36.  *****************************************************************************/
  37. @implementation VLCEmbeddedWindow
  38. - (id)initWithContentRect:(NSRect)contentRect styleMask: (NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
  39. {
  40.     BOOL b_useTextured = YES;
  41.     if( [[NSWindow class] instancesRespondToSelector:@selector(setContentBorderThickness:forEdge:)] )
  42.     {
  43.         b_useTextured = NO;
  44.         windowStyle ^= NSTexturedBackgroundWindowMask;
  45.     }
  46.     self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
  47.     if(! b_useTextured )
  48.     {
  49.         [self setContentBorderThickness:28.0 forEdge:NSMinYEdge];
  50.     }
  51.     return self;
  52. }
  53. - (void)awakeFromNib
  54. {
  55.     [self setDelegate: self];
  56.     [o_btn_backward setToolTip: _NS("Rewind")];
  57.     [o_btn_forward setToolTip: _NS("Fast Forward")];
  58.     [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
  59.     [o_btn_play setToolTip: _NS("Play")];
  60.     [o_slider setToolTip: _NS("Position")];
  61.     o_img_play = [NSImage imageNamed: @"play_embedded"];
  62.     o_img_pause = [NSImage imageNamed: @"pause_embedded"];
  63.     [self controlTintChanged];
  64.     [[NSNotificationCenter defaultCenter] addObserver: self
  65.                                              selector: @selector( controlTintChanged )
  66.                                                  name: NSControlTintDidChangeNotification
  67.                                                object: nil];
  68.     /* Useful to save o_view frame in fullscreen mode */
  69.     o_temp_view = [[NSView alloc] init];
  70.     [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
  71.     o_fullscreen_window = nil;
  72.     o_makekey_anim = o_fullscreen_anim1 = o_fullscreen_anim2 = nil;
  73.     /* Not fullscreen when we wake up */
  74.     [o_btn_fullscreen setState: NO];
  75.     b_fullscreen = NO;
  76.     [self setMovableByWindowBackground:YES];
  77.     [self setDelegate:self];
  78.     /* Make sure setVisible: returns NO */
  79.     [self orderOut:self];
  80.     b_window_is_invisible = YES;
  81.     videoRatio = NSMakeSize( 0., 0. );
  82. }
  83. - (void)controlTintChanged
  84. {
  85.     BOOL b_playing = NO;
  86.     if( [o_btn_play alternateImage] == o_img_play_pressed )
  87.         b_playing = YES;
  88.     
  89.     if( [NSColor currentControlTint] == NSGraphiteControlTint )
  90.     {
  91.         o_img_play_pressed = [NSImage imageNamed: @"play_embedded_graphite"];
  92.         o_img_pause_pressed = [NSImage imageNamed: @"pause_embedded_graphite"];
  93.         [o_btn_backward setAlternateImage: [NSImage imageNamed: @"skip_previous_embedded_graphite"]];
  94.         [o_btn_forward setAlternateImage: [NSImage imageNamed: @"skip_forward_embedded_graphite"]];
  95.         [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];
  96.     }
  97.     else
  98.     {
  99.         o_img_play_pressed = [NSImage imageNamed: @"play_embedded_blue"];
  100.         o_img_pause_pressed = [NSImage imageNamed: @"pause_embedded_blue"];
  101.         [o_btn_backward setAlternateImage: [NSImage imageNamed: @"skip_previous_embedded_blue"]];
  102.         [o_btn_forward setAlternateImage: [NSImage imageNamed: @"skip_forward_embedded_blue"]];
  103.         [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];
  104.     }
  105.     
  106.     if( b_playing )
  107.         [o_btn_play setAlternateImage: o_img_play_pressed];
  108.     else
  109.         [o_btn_play setAlternateImage: o_img_pause_pressed];
  110. }
  111. - (void)dealloc
  112. {
  113.     [[NSNotificationCenter defaultCenter] removeObserver: self];
  114.     [o_img_play release];
  115.     [o_img_play_pressed release];
  116.     [o_img_pause release];
  117.     [o_img_pause_pressed release];
  118.     
  119.     [super dealloc];
  120. }
  121. - (void)setTime:(NSString *)o_arg_time position:(float)f_position
  122. {
  123.     [o_time setStringValue: o_arg_time];
  124.     [o_slider setFloatValue: f_position];
  125. }
  126. - (void)playStatusUpdated:(int)i_status
  127. {
  128.     if( i_status == PLAYING_S )
  129.     {
  130.         [o_btn_play setImage: o_img_pause];
  131.         [o_btn_play setAlternateImage: o_img_pause_pressed];
  132.         [o_btn_play setToolTip: _NS("Pause")];
  133.     }
  134.     else
  135.     {
  136.         [o_btn_play setImage: o_img_play];
  137.         [o_btn_play setAlternateImage: o_img_play_pressed];
  138.         [o_btn_play setToolTip: _NS("Play")];
  139.     }
  140. }
  141. - (void)setSeekable:(BOOL)b_seekable
  142. {
  143.     [o_btn_forward setEnabled: b_seekable];
  144.     [o_btn_backward setEnabled: b_seekable];
  145.     [o_slider setEnabled: b_seekable];
  146. }
  147. - (BOOL)windowShouldZoom:(NSWindow *)sender toFrame:(NSRect)newFrame
  148. {
  149.     [self setFrame: newFrame display: YES animate: YES];
  150.     return NO;
  151. }
  152. - (BOOL)windowShouldClose:(id)sender
  153. {
  154.     playlist_t * p_playlist = pl_Hold( VLCIntf );
  155.     playlist_Stop( p_playlist );
  156.     pl_Release( VLCIntf );
  157.     return YES;
  158. }
  159. - (NSView *)mainView
  160. {
  161.     if (o_fullscreen_window)
  162.         return o_temp_view;
  163.     else
  164.         return o_view;
  165. }
  166. - (void)setVideoRatio:(NSSize)ratio
  167. {
  168.     videoRatio = ratio;
  169. }
  170. - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
  171. {
  172.     if( videoRatio.height == 0. || videoRatio.width == 0. )
  173.         return proposedFrameSize;
  174.     if( [[[VLCMain sharedInstance] controls] aspectRatioIsLocked] )
  175.     {
  176.         NSRect viewRect = [o_view convertRect:[o_view bounds] toView: nil];
  177.         NSRect contentRect = [self contentRectForFrameRect:[self frame]];
  178.         float marginy = viewRect.origin.y + [self frame].size.height - contentRect.size.height;
  179.         float marginx = contentRect.size.width - viewRect.size.width;
  180.         proposedFrameSize.height = (proposedFrameSize.width - marginx) * videoRatio.height / videoRatio.width + marginy;
  181.     }
  182.     return proposedFrameSize;
  183. }
  184. /*****************************************************************************
  185.  * Fullscreen support
  186.  */
  187. - (BOOL)isFullscreen
  188. {
  189.     return b_fullscreen;
  190. }
  191. - (void)lockFullscreenAnimation
  192. {
  193.     [o_animation_lock lock];
  194. }
  195. - (void)unlockFullscreenAnimation
  196. {
  197.     [o_animation_lock unlock];
  198. }
  199. - (void)enterFullscreen
  200. {
  201.     NSMutableDictionary *dict1, *dict2;
  202.     NSScreen *screen;
  203.     NSRect screen_rect;
  204.     NSRect rect;
  205.     vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
  206.     BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
  207.     screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_GetInteger( p_vout, "video-device" )]; 
  208.  
  209.     [self lockFullscreenAnimation];
  210.     if (!screen)
  211.     {
  212.         msg_Dbg( p_vout, "chosen screen isn't present, using current screen for fullscreen mode" );
  213.         screen = [self screen];
  214.     }
  215.     if (!screen)
  216.     {
  217.         msg_Dbg( p_vout, "Using deepest screen" );
  218.         screen = [NSScreen deepestScreen];
  219.     }
  220.     vlc_object_release( p_vout );
  221.     screen_rect = [screen frame];
  222.     [o_btn_fullscreen setState: YES];
  223.     [NSCursor setHiddenUntilMouseMoves: YES];
  224.  
  225.     if( blackout_other_displays )        
  226.         [screen blackoutOtherScreens];
  227.     /* Make sure we don't see the window flashes in float-on-top mode */
  228.     originalLevel = [self level];
  229.     [self setLevel:NSNormalWindowLevel];
  230.     /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
  231.     if (!o_fullscreen_window)
  232.     {
  233.         /* We can't change the styleMask of an already created NSWindow, so we create an other window, and do eye catching stuff */
  234.         rect = [[o_view superview] convertRect: [o_view frame] toView: nil]; /* Convert to Window base coord */
  235.         rect.origin.x += [self frame].origin.x;
  236.         rect.origin.y += [self frame].origin.y;
  237.         o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
  238.         [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
  239.         [o_fullscreen_window setCanBecomeKeyWindow: YES];
  240.         if (![self isVisible] || [self alphaValue] == 0.0)
  241.         {
  242.             /* We don't animate if we are not visible, instead we
  243.              * simply fade the display */
  244.             CGDisplayFadeReservationToken token;
  245.  
  246.             CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
  247.             CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
  248.  
  249.             if ([screen isMainScreen])
  250.                 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
  251.  
  252.             [[self contentView] replaceSubview:o_view with:o_temp_view];
  253.             [o_temp_view setFrame:[o_view frame]];
  254.             [o_fullscreen_window setContentView:o_view];
  255.             [o_fullscreen_window makeKeyAndOrderFront:self];
  256.             [o_fullscreen_window orderFront:self animate:YES];
  257.             [o_fullscreen_window setFrame:screen_rect display:YES];
  258.             CGDisplayFade( token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
  259.             CGReleaseDisplayFadeReservation( token);
  260.             /* Will release the lock */
  261.             [self hasBecomeFullscreen];
  262.             return;
  263.         }
  264.  
  265.         /* Make sure we don't see the o_view disappearing of the screen during this operation */
  266.         NSDisableScreenUpdates();
  267. [[self contentView] replaceSubview:o_view with:o_temp_view];
  268.         [o_temp_view setFrame:[o_view frame]];
  269.         [o_fullscreen_window setContentView:o_view];
  270.         [o_fullscreen_window makeKeyAndOrderFront:self];
  271.         NSEnableScreenUpdates();
  272.     }
  273.     /* We are in fullscreen (and no animation is running) */
  274.     if (b_fullscreen)
  275.     {
  276.         /* Make sure we are hidden */
  277.         [super orderOut: self];
  278.         [self unlockFullscreenAnimation];
  279.         return;
  280.     }
  281.     if (o_fullscreen_anim1)
  282.     {
  283.         [o_fullscreen_anim1 stopAnimation];
  284.         [o_fullscreen_anim1 release];
  285.     }
  286.     if (o_fullscreen_anim2)
  287.     {
  288.         [o_fullscreen_anim2 stopAnimation];
  289.         [o_fullscreen_anim2 release];
  290.     }
  291.  
  292.     if ([screen isMainScreen])
  293.         SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
  294.     dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
  295.     dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
  296.     [dict1 setObject:self forKey:NSViewAnimationTargetKey];
  297.     [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
  298.     [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
  299.     [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
  300.     [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
  301.     /* Strategy with NSAnimation allocation:
  302.         - Keep at most 2 animation at a time
  303.         - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
  304.     */
  305.     o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
  306.     o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
  307.     [dict1 release];
  308.     [dict2 release];
  309.     [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
  310.     [o_fullscreen_anim1 setDuration: 0.3];
  311.     [o_fullscreen_anim1 setFrameRate: 30];
  312.     [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
  313.     [o_fullscreen_anim2 setDuration: 0.2];
  314.     [o_fullscreen_anim2 setFrameRate: 30];
  315.     [o_fullscreen_anim2 setDelegate: self];
  316.     [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
  317.     [o_fullscreen_anim1 startAnimation];
  318.     /* fullscreenAnimation will be unlocked when animation ends */
  319. }
  320. - (void)hasBecomeFullscreen
  321. {
  322.     [o_fullscreen_window makeFirstResponder: [[[VLCMain sharedInstance] controls] voutView]];
  323.     [o_fullscreen_window makeKeyWindow];
  324.     [o_fullscreen_window setAcceptsMouseMovedEvents: TRUE];
  325.     /* tell the fspanel to move itself to front next time it's triggered */
  326.     [[[[VLCMain sharedInstance] controls] fspanel] setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
  327.     if([self isVisible])
  328.         [super orderOut: self];
  329.     [[[[VLCMain sharedInstance] controls] fspanel] setActive: nil];
  330.     b_fullscreen = YES;
  331.     [self unlockFullscreenAnimation];
  332. }
  333. - (void)leaveFullscreen
  334. {
  335.     [self leaveFullscreenAndFadeOut: NO];
  336. }
  337. - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
  338. {
  339.     NSMutableDictionary *dict1, *dict2;
  340.     NSRect frame;
  341.     [self lockFullscreenAnimation];
  342.     b_fullscreen = NO;
  343.     [o_btn_fullscreen setState: NO];
  344.     /* We always try to do so */
  345.     [NSScreen unblackoutScreens];
  346.     /* Don't do anything if o_fullscreen_window is already closed */
  347.     if (!o_fullscreen_window)
  348.     {
  349.         [self unlockFullscreenAnimation];
  350.         return;
  351.     }
  352.     if (fadeout)
  353.     {
  354.         /* We don't animate if we are not visible, instead we
  355.         * simply fade the display */
  356.         CGDisplayFadeReservationToken token;
  357.         CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
  358.         CGDisplayFade( token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
  359.         [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
  360.         SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
  361.         /* Will release the lock */
  362.         [self hasEndedFullscreen];
  363.         /* Our window is hidden, and might be faded. We need to workaround that, so note it
  364.          * here */
  365.         b_window_is_invisible = YES;
  366.         CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
  367.         CGReleaseDisplayFadeReservation( token);
  368.         return;
  369.     }
  370.     [self setAlphaValue: 0.0];
  371.     [self orderFront: self];
  372.     [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
  373.     SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
  374.     if (o_fullscreen_anim1)
  375.     {
  376.         [o_fullscreen_anim1 stopAnimation];
  377.         [o_fullscreen_anim1 release];
  378.     }
  379.     if (o_fullscreen_anim2)
  380.     {
  381.         [o_fullscreen_anim2 stopAnimation];
  382.         [o_fullscreen_anim2 release];
  383.     }
  384.     frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
  385.     frame.origin.x += [self frame].origin.x;
  386.     frame.origin.y += [self frame].origin.y;
  387.     dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
  388.     [dict2 setObject:self forKey:NSViewAnimationTargetKey];
  389.     [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
  390.     o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
  391.     [dict2 release];
  392.     [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
  393.     [o_fullscreen_anim2 setDuration: 0.3];
  394.     [o_fullscreen_anim2 setFrameRate: 30];
  395.     [o_fullscreen_anim2 setDelegate: self];
  396.     dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
  397.     [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
  398.     [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
  399.     [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
  400.     o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
  401.     [dict1 release];
  402.     [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
  403.     [o_fullscreen_anim1 setDuration: 0.2];
  404.     [o_fullscreen_anim1 setFrameRate: 30];
  405.     [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
  406.     /* Make sure o_fullscreen_window is the frontmost window */
  407.     [o_fullscreen_window orderFront: self];
  408.     [o_fullscreen_anim1 startAnimation];
  409.     /* fullscreenAnimation will be unlocked when animation ends */
  410. }
  411. - (void)hasEndedFullscreen
  412. {
  413.     /* This function is private and should be only triggered at the end of the fullscreen change animation */
  414.     /* Make sure we don't see the o_view disappearing of the screen during this operation */
  415.     NSDisableScreenUpdates();
  416.     [o_view retain];
  417.     [o_view removeFromSuperviewWithoutNeedingDisplay];
  418.     [[self contentView] replaceSubview:o_temp_view with:o_view];
  419.     [o_view release];
  420.     [o_view setFrame:[o_temp_view frame]];
  421.     [self makeFirstResponder: o_view];
  422.     if ([self isVisible])
  423.         [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
  424.     [o_fullscreen_window orderOut: self];
  425.     NSEnableScreenUpdates();
  426.     [o_fullscreen_window release];
  427.     o_fullscreen_window = nil;
  428.     [self setLevel:originalLevel];
  429.     [self unlockFullscreenAnimation];
  430. }
  431. - (void)animationDidEnd:(NSAnimation*)animation
  432. {
  433.     NSArray *viewAnimations;
  434.     if( o_makekey_anim == animation )
  435.     {
  436.         [o_makekey_anim release];
  437.         return;
  438.     }
  439.     if ([animation currentValue] < 1.0)
  440.         return;
  441.     /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
  442.     viewAnimations = [o_fullscreen_anim2 viewAnimations];
  443.     if ([viewAnimations count] >=1 &&
  444.         [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect])
  445.     {
  446.         /* Fullscreen ended */
  447.         [self hasEndedFullscreen];
  448.     }
  449.     else
  450.     {
  451.         /* Fullscreen started */
  452.         [self hasBecomeFullscreen];
  453.     }
  454. }
  455. - (void)orderOut: (id)sender
  456. {
  457.     [super orderOut: sender];
  458.     /* Make sure we leave fullscreen */
  459.     [self leaveFullscreenAndFadeOut: YES];
  460. }
  461. - (void)makeKeyAndOrderFront: (id)sender
  462. {
  463.     /* Hack
  464.      * when we exit fullscreen and fade out, we may endup in
  465.      * having a window that is faded. We can't have it fade in unless we
  466.      * animate again. */
  467.     if(!b_window_is_invisible)
  468.     {
  469.         /* Make sure we don't do it too much */
  470.         [super makeKeyAndOrderFront: sender];
  471.         return;
  472.     }
  473.     [super setAlphaValue:0.0f];
  474.     [super makeKeyAndOrderFront: sender];
  475.     NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
  476.     [dict setObject:self forKey:NSViewAnimationTargetKey];
  477.     [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
  478.     o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
  479.     [dict release];
  480.     [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
  481.     [o_makekey_anim setDuration: 0.1];
  482.     [o_makekey_anim setFrameRate: 30];
  483.     [o_makekey_anim setDelegate: self];
  484.     [o_makekey_anim startAnimation];
  485.     b_window_is_invisible = NO;
  486.     /* fullscreenAnimation will be unlocked when animation ends */
  487. }
  488. /* Make sure setFrame gets executed on main thread especially if we are animating.
  489.  * (Thus we won't block the video output thread) */
  490. - (void)setFrame:(NSRect)frame display:(BOOL)display animate:(BOOL)animate
  491. {
  492.     struct { NSRect frame; BOOL display; BOOL animate;} args;
  493.     NSData *packedargs;
  494.     args.frame = frame;
  495.     args.display = display;
  496.     args.animate = animate;
  497.     packedargs = [NSData dataWithBytes:&args length:sizeof(args)];
  498.     [self performSelectorOnMainThread:@selector(setFrameOnMainThread:)
  499.                     withObject: packedargs waitUntilDone: YES];
  500. }
  501. - (void)setFrameOnMainThread:(NSData*)packedargs
  502. {
  503.     struct args { NSRect frame; BOOL display; BOOL animate; } * args = (struct args*)[packedargs bytes];
  504.     if( args->animate )
  505.     {
  506.         /* Make sure we don't block too long and set up a non blocking animation */
  507.         NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
  508.             self, NSViewAnimationTargetKey,
  509.             [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
  510.             [NSValue valueWithRect:args->frame], NSViewAnimationEndFrameKey, nil];
  511.         NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
  512.         [dict release];
  513.         [anim setAnimationBlockingMode: NSAnimationNonblocking];
  514.         [anim setDuration: 0.4];
  515.         [anim setFrameRate: 30];
  516.         [anim startAnimation];
  517.     }
  518.     else {
  519.         [super setFrame:args->frame display:args->display animate:args->animate];
  520.     }
  521. }
  522. @end