]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/vout.m
macosx: Fix aspect ratio.
[vlc] / modules / gui / macosx / vout.m
index bb487d0d79a0458f610e50300a2eeedfb3720215..868eb2daa16a56a90532cb45b206a71d8af526ad 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * vout.m: MacOS X video output module
  *****************************************************************************
- * Copyright (C) 2001-2007 the VideoLAN team
+ * Copyright (C) 2001-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Colin Delacroix <colin@zoy.org>
@@ -10,7 +10,7 @@
  *          Derk-Jan Hartman <hartman at videolan dot org>
  *          Eric Petit <titer@m0k.org>
  *          Benjamin Pracht <bigben at videolan dot org>
- *          Felix K\9fhne <fkuehne at videolan dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@
  *****************************************************************************/
 #include <errno.h>                                                 /* ENOMEM */
 #include <stdlib.h>                                                /* free() */
-#include <string.h>                                            /* strerror() */
+#include <string.h>
 
 /* BeginFullScreen, EndFullScreen */
 #include <QuickTime/QuickTime.h>
@@ -58,7 +58,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER );
     var_Set( p_vout->p_libvlc, "video-device", new_val );
 
-    val.b_bool = VLC_TRUE;
+    val.b_bool = true;
     var_Set( p_vout, "intf-change", val );
     return VLC_SUCCESS;
 }
@@ -143,7 +143,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
  *****************************************************************************/
 @implementation VLCVoutView
 
-- (id)initWithFrame:(NSRect)frameRect
+- (id)initWithFrame: (NSRect)frameRect
 {
     [super initWithFrame: frameRect];
     p_vout = NULL;
@@ -155,8 +155,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     return self;
 }
 
-- (BOOL)setVout: (vout_thread_t *) vout subView: (NSView *) view
-                     frame: (NSRect *) frame
+- (BOOL)setVout: (vout_thread_t *) vout
+        subView: (NSView *) view
+          frame: (NSRect *) frame
 {
     int i_device;
     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
@@ -193,7 +194,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
         var_Create( p_real_vout, "video-device", VLC_VAR_INTEGER |
                                             VLC_VAR_HASCHOICE );
-        text.psz_string = _("Video Device");
+        text.psz_string = _("Fullscreen Video Device");
         var_Change( p_real_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL );
 
         NSEnumerator * o_enumerator = [o_screens objectEnumerator];
@@ -227,7 +228,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         var_AddCallback( p_real_vout, "video-device", DeviceCallback,
                          NULL );
 
-        val2.b_bool = VLC_TRUE;
+        val2.b_bool = true;
         var_Set( p_real_vout, "intf-change", val2 );
     }
 
@@ -265,33 +266,39 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     p_vout = NULL;
     s_frame = nil;
     o_window = nil;
-    p_real_vout = NULL;            
+    p_real_vout = NULL;
 }
 
 - (void)updateTitle
 {
-    NSMutableString * o_title = nil, * o_mrl = nil;
+    NSString * o_title = nil; 
+    NSMutableString * o_mrl = nil;
     input_thread_t * p_input;
+    char * psz_title;
 
-    if( p_vout == NULL )
-    {
-        return;
-    }
+    if( !p_vout ) return;
 
     p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
 
-    if( p_input == NULL )
-    {
-        return;
-    }
+    if( !p_input ) return;
 
-    if( input_GetItem(p_input)->psz_name != NULL )
-        o_title = [NSMutableString stringWithUTF8String:
-            input_GetItem(p_input)->psz_name];
-    if( input_GetItem(p_input)->psz_uri != NULL )
-        o_mrl = [NSMutableString stringWithUTF8String:
-            input_GetItem(p_input)->psz_uri];
-    if( o_title == nil )
+    input_item_t * p_item = input_GetItem( p_input );
+
+    psz_title = input_item_GetNowPlaying ( p_item );
+    if( !psz_title )
+        psz_title = input_item_GetName( p_item );
+
+    if( psz_title )
+        o_title = [NSString stringWithUTF8String: psz_title];
+
+    char *psz_uri = input_item_GetURI( p_item );
+    if( psz_uri )
+        o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
+
+    free( psz_title );
+    free( psz_uri );
+
+    if( !o_title )
         o_title = o_mrl;
 
     if( o_mrl != nil )
@@ -304,7 +311,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
             [o_mrl deleteCharactersInRange: prefix_range];
 
         if( [o_mrl characterAtIndex:0] == '/' )
-        { 
+        {
             /* it's a local file */
             [o_window setRepresentedFilename: o_mrl];
         }
@@ -318,7 +325,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     }
     else
     {
-        [o_window setTitle: [NSString stringWithCString: VOUT_TITLE]];
+        [o_window setTitle: [NSString stringWithUTF8String: VOUT_TITLE]];
     }
     vlc_object_release( p_input );
 }
@@ -336,36 +343,44 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     }
 }
 
-- (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
+- (NSSize)voutSizeForFactor: (float)factor
 {
-    NSSize newsize;
     int i_corrected_height, i_corrected_width;
-    NSPoint topleftbase;
-    NSPoint topleftscreen;
+    NSSize newsize;
+
+    if( p_vout->render.i_height * p_vout->render.i_aspect >
+                    p_vout->render.i_width * VOUT_ASPECT_FACTOR )
+    {
+        i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
+                                        VOUT_ASPECT_FACTOR;
+        newsize.width = (int) ( i_corrected_width * factor );
+        newsize.height = (int) ( p_vout->render.i_height * factor );
+    }
+    else
+    {
+        i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
+                                        p_vout->render.i_aspect;
+        newsize.width = (int) ( p_vout->render.i_width * factor );
+        newsize.height = (int) ( i_corrected_height * factor );
+    }
+
+    return newsize;
+}
 
+- (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
+{
     if ( !p_vout->b_fullscreen )
     {
+        NSSize newsize;
+        NSPoint topleftbase;
+        NSPoint topleftscreen;
         NSView *mainView;
         NSRect new_frame;
         topleftbase.x = 0;
         topleftbase.y = [o_window frame].size.height;
         topleftscreen = [o_window convertBaseToScreen: topleftbase];
 
-        if( p_vout->render.i_height * p_vout->render.i_aspect >
-                        p_vout->render.i_width * VOUT_ASPECT_FACTOR )
-        {
-            i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
-                                            VOUT_ASPECT_FACTOR;
-            newsize.width = (int) ( i_corrected_width * factor );
-            newsize.height = (int) ( p_vout->render.i_height * factor );
-        }
-        else
-        {
-            i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
-                                            p_vout->render.i_aspect;
-            newsize.width = (int) ( p_vout->render.i_width * factor );
-            newsize.height = (int) ( i_corrected_height * factor );
-        }
+        newsize = [self voutSizeForFactor:factor];
 
         /* In fullscreen mode we need to use a view that is different from
          * ourselves, with the VLCEmbeddedWindow */
@@ -383,8 +398,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         new_frame.origin.x = topleftscreen.x;
         new_frame.origin.y = topleftscreen.y - new_frame.size.height;
 
-        [o_window setFrame: new_frame display: animate animate: animate];
-
+        [o_window setFrame:new_frame display:animate animate:animate];
         p_vout->i_changes |= VOUT_SIZE_CHANGE;
     }
 }
@@ -396,11 +410,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     if( !p_real_vout ) return;
     if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
     {
-        val.b_bool = VLC_FALSE;
+        val.b_bool = false;
     }
     else
     {
-        val.b_bool = VLC_TRUE;
+        val.b_bool = true;
     }
     var_Set( p_real_vout, "video-on-top", val );
 }
@@ -430,6 +444,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 - (void)manage
 {
     /* Disable Screensaver, when we're playing something, but allow it on pause */
+    if( !VLCIntf || !VLCIntf->p_sys || !VLCIntf->p_sys->i_play_status )
+        return;
+
     if( VLCIntf->p_sys->i_play_status == PLAYING_S )
         UpdateSystemActivity( UsrActivity );
 }
@@ -559,7 +576,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     if( p_vout && [o_event type] == NSLeftMouseUp )
     {
         vlc_value_t b_val;
-        b_val.b_bool = VLC_TRUE;
+        b_val.b_bool = true;
         var_Set( p_vout, "mouse-clicked", b_val );
 
         var_Get( p_vout, "mouse-button-down", &val );
@@ -590,7 +607,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     {
         /* FIXME: this isn't the appropriate place, but we can't receive
          * NSRightMouseDown some how */
-        msg_Dbg( p_vout, "received NSRightMouseUp" ); 
+        msg_Dbg( p_vout, "received NSRightMouseUp" );
         [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
     }
 
@@ -649,7 +666,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
             }
             var_Set( p_vout, "mouse-y", val );
 
-            val.b_bool = VLC_TRUE;
+            val.b_bool = true;
             var_Set( p_vout, "mouse-moved", val );
         }
         if( [self isFullscreen] )
@@ -708,8 +725,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    var_Create( p_vout, "macosx-embedded", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-
+    var_Create( p_vout, "embedded-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
 
     /* We only wait for NSApp to initialise if we're not embedded (as in the
      * case of the Mozilla plugin).  We can tell whether we're embedded or not
@@ -736,7 +752,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         {
             if ( VLCIntf && !(p_vout->b_fullscreen) &&
                         !(var_GetBool( p_vout, "macosx-background" )) &&
-                        var_GetBool( p_vout, "macosx-embedded") )
+                        var_GetBool( p_vout, "embedded-video") )
             {
                 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
                                                             getEmbeddedVout];
@@ -757,14 +773,18 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 - (void)enterFullscreen
 {
-    [[o_view class] resetVout: p_vout];
-    [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
+    /* Save the settings for next playing item */
+    playlist_t * p_playlist = pl_Yield( p_real_vout );
+    var_SetBool( p_playlist, "fullscreen", true );
+    pl_Release( p_real_vout );
 }
 
 - (void)leaveFullscreen
 {
-    [[o_view class] resetVout: p_vout];
-    [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
+    /* Save the settings for next playing item */
+    playlist_t * p_playlist = pl_Yield( p_real_vout );
+    var_SetBool( p_playlist, "fullscreen", false );
+    pl_Release( p_real_vout );
 }
 
 @end
@@ -796,7 +816,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         [o_window setLevel: NSStatusWindowLevel];
     }
 
-
     [o_window setAcceptsMouseMovedEvents: TRUE];
     return b_return;
 }
@@ -838,9 +857,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 - (void)manage
 {
     [super manage];
+    unsigned int i_mouse_hide_timeout =
+        var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;
     if( p_vout->b_fullscreen )
     {
-        if( mdate() - i_time_mouse_last_moved > 3000000 )
+        if( mdate() - i_time_mouse_last_moved > i_mouse_hide_timeout )
         {
             [self hideMouse: YES];
         }
@@ -851,6 +872,33 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     }
 }
 
+
+- (void)enterFullscreen
+{
+    [super enterFullscreen];
+
+    if( var_GetBool( p_real_vout, "video-on-top" ) )
+    {
+        [o_window setLevel: NSNormalWindowLevel];
+    }
+
+    [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
+    [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
+}
+
+- (void)leaveFullscreen
+{
+    [super leaveFullscreen];
+
+    if( var_GetBool( p_real_vout, "video-on-top" ) )
+    {
+        [o_window setLevel: NSStatusWindowLevel];
+    }
+
+    [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
+    [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
+}
+
 @end
 
 /*****************************************************************************
@@ -859,24 +907,34 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 @implementation VLCEmbeddedVoutView
 
+- (void)awakeFromNib
+{
+    o_embeddedwindow = [self window];
+}
+
 - (id)initWithFrame: (NSRect)frameRect
 {
-    [super initWithFrame: frameRect];
-    b_used = NO;
-    [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
+    if(self = [super initWithFrame: frameRect])
+    {
+        b_used = NO;
+        [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
+        o_embeddedwindow = nil; /* Filled later on in -awakeFromNib */
+    }
     return self;
 }
 
 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
-                 frame: (NSRect *)s_arg_frame showWindow: (BOOL)b_show_window
+                 frame: (NSRect *)s_arg_frame
 {
     BOOL b_return;
+
+    [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
+
     b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
     if( b_return )
     {
         o_window = [self window];
-        if (b_show_window)
-            [o_window makeKeyAndOrderFront: self];
+
         [o_window setAcceptsMouseMovedEvents: TRUE];
 
         if( var_GetBool( p_real_vout, "video-on-top" ) )
@@ -886,51 +944,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
         [view setFrameSize: [self frame].size];
     }
-    return b_return;
-}
-
-- (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
-                     frame: (NSRect *) s_arg_frame
-
-{
-    return [self setVout: p_arg_vout subView: view frame:s_arg_frame showWindow: YES];
-}
-
-- (void)setUsed: (BOOL)b_new_used
-{
-    b_used = b_new_used;
-}
-
-- (BOOL)isUsed
-{
-    return b_used;
-}
-
-- (void)closeVout
-{
-    [super closeVout];
-    [o_window setAcceptsMouseMovedEvents: NO];
-    [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
-}
-
-
-@end
-
-@implementation VLCDetachedEmbeddedVoutView
-- (void)awakeFromNib
-{
-    o_embeddedwindow = [self window];
-}
-
-- (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
-                     frame: (NSRect *) s_arg_frame
-{
-    BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame showWindow: NO];
 
     /* o_window needs to point to our o_embeddedwindow, super might have set it
      * to the fullscreen window that o_embeddedwindow setups during fullscreen */
     o_window = o_embeddedwindow;
-    
     if( b_return )
     {
         [o_window lockFullscreenAnimation];
@@ -939,13 +957,15 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
         [self updateTitle];
 
+        [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
+
         /* Make the window the front and key window before animating */
         if ([o_window isVisible] && (![o_window isFullscreen]))
             [o_window makeKeyAndOrderFront: self];
 
         [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])];
 
-        [o_window setAspectRatio:NSMakeSize([o_window frame].size.width, [o_window frame].size.height)];
+        [o_embeddedwindow setVideoRatio:[self voutSizeForFactor:1.0]];
 
         /* Make sure our window is visible, if we are not in fullscreen */
         if (![o_window isFullscreen])
@@ -953,29 +973,47 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         [o_window unlockFullscreenAnimation];
 
     }
+
     return b_return;
 }
 
-- (void)closeVout
+- (void)setUsed: (BOOL)b_new_used
 {
-    playlist_t * p_playlist = pl_Yield( VLCIntf );
+    b_used = b_new_used;
+}
 
-    if(!playlist_IsPlaying( p_playlist ))
-        [o_window performSelectorOnMainThread: @selector(orderOut:) withObject: self waitUntilDone: YES];
-    
-    vlc_object_release( p_playlist );
+- (BOOL)isUsed
+{
+    return b_used;
+}
 
+- (void)closeVout
+{
     [super closeVout];
+
+    /* Don't close the window yet, wait a bit to see if a new input is poping up */
+    /* FIXME: Probably fade the window In and Out */
+    /* FIXME: fix core */
+    [o_embeddedwindow performSelector:@selector(orderOut:) withObject:nil afterDelay:3.];
+
+    [o_window setAcceptsMouseMovedEvents: NO];
+    [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
 }
 
 - (void)enterFullscreen
 {
+    /* Save settings */
+    [super enterFullscreen];
+
     /* We are in a VLCEmbeddedWindow */
     [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
 }
 
 - (void)leaveFullscreen
 {
+    /* Save settings */
+    [super leaveFullscreen];
+
     /* We are in a VLCEmbeddedWindow */
     [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES];
 }
@@ -993,7 +1031,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     o_view  = view;
     s_frame = frame;
 
-    [self performSelectorOnMainThread: @selector(initReal:)
+    [self performSelectorOnMainThread: @selector(initMainThread:)
         withObject: NULL waitUntilDone: YES];
 
     if( !b_init_ok )
@@ -1004,20 +1042,20 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     return self;
 }
 
-- (id)initReal: (id) sender
+- (id)initMainThread: (id) sender
 {
     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
     NSArray *o_screens = [NSScreen screens];
     NSScreen *o_screen;
-    vlc_bool_t b_menubar_screen = VLC_FALSE;
+    bool b_menubar_screen = false;
     int i_device;
 
-    b_init_ok = VLC_FALSE;
+    b_init_ok = false;
 
     p_real_vout = [VLCVoutView getRealVout: p_vout];
     i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
     b_black = NO;
-    b_embedded = var_GetBool( p_vout, "macosx-embedded" );
+    b_embedded = var_GetBool( p_vout, "embedded-video" );
 
     /* Find out on which screen to open the window */
     o_screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
@@ -1026,7 +1064,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         o_screen = [NSScreen mainScreen];
 
     if( [o_screen isMainScreen] )
-        b_menubar_screen = VLC_TRUE;
+        b_menubar_screen = true;
 
     if( p_vout->b_fullscreen )
     {
@@ -1040,7 +1078,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
          * this won't and is not supposed to work when it's fading right now */
         if( [[[[VLCMain sharedInstance] getControls] getFSPanel] isDisplayed] )
             [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
-        
         /* tell the fspanel to move itself to front next time it's triggered */
         [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
 
@@ -1049,12 +1087,12 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
               styleMask: NSBorderlessWindowMask
               backing: NSBackingStoreBuffered
               defer: YES screen: o_screen];
-        
         if( b_menubar_screen )
         {
             SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
         }
-        if( b_black == VLC_TRUE )
+        if( b_black == true )
         {
             CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
             CGDisplayFade( token, 0.6 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
@@ -1120,7 +1158,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
     [o_pool release];
 
-    b_init_ok = VLC_TRUE;
+    b_init_ok = true;
     return self;
 }
 
@@ -1133,18 +1171,18 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 {
     /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
        Command-Q */
-    [self performSelectorOnMainThread: @selector(closeReal:)
+    [self performSelectorOnMainThread: @selector(closeMainThread:)
         withObject: NULL waitUntilDone: NO];
 }
 
-- (id)closeReal:(id)sender
+- (id)closeMainThread:(id)sender
 {
-    if( b_black == VLC_TRUE )
+    if( b_black == true )
     {
         CGDisplayFadeReservationToken token;
         CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
         CGDisplayFade( token, 0.3 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
-        
         [self disableScreenUpdatesUntilFlush];
         [self orderOut: self];
 
@@ -1157,7 +1195,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     SetSystemUIMode( kUIModeNormal, 0);
     [super close];
     /* this does only work in embedded mode */
-    if( b_embedded == VLC_TRUE )
+    if( b_embedded == true )
         [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
 
     return NULL;
@@ -1183,8 +1221,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 - (BOOL)windowShouldClose:(id)sender
 {
-    playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
-                                                       FIND_ANYWHERE );
+    playlist_t * p_playlist = pl_Yield( p_vout );
     if( p_playlist == NULL )
     {
         return NO;
@@ -1197,5 +1234,4 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     return NO;
 }
 
-
 @end