]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/vout.m
qt4/macosx: fixed the embedded vout setting
[vlc] / modules / gui / macosx / vout.m
index 94d0437b9c02ebccd01a3b5e0276580a76760365..bc7900e9ba4af45ceddbd17678ff61a14a723029 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 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>
@@ -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];
@@ -265,12 +266,13 @@ 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;
 
     if( p_vout == NULL )
@@ -285,12 +287,21 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         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];
+    char *psz_nowPlaying = input_item_GetNowPlaying ( input_GetItem( p_input ) );
+    char *psz_name = input_item_GetName( input_GetItem( p_input ) );
+    char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
+    if( psz_nowPlaying != NULL )
+        o_title = [NSString stringWithUTF8String: psz_nowPlaying];
+    else if( psz_name != NULL )
+        o_title = [NSString stringWithUTF8String: psz_name];
+
+    if( psz_uri != NULL )
+        o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
+
+    FREENULL( psz_nowPlaying );
+    FREENULL( psz_name );
+    FREENULL( psz_uri );
+
     if( o_title == nil )
         o_title = o_mrl;
 
@@ -304,7 +315,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 +329,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 );
 }
@@ -417,6 +428,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 - (BOOL)isFullscreen
 {
     vlc_value_t val;
+    if( !p_real_vout ) return NO;
     var_Get( p_real_vout, "fullscreen", &val );
     return( val.b_bool );
 }
@@ -429,6 +441,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 );
 }
@@ -438,6 +453,12 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     return o_window;
 }
 
+- (void)scrollWheel:(NSEvent *)theEvent
+{
+    VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
+    [o_controls scrollWheel: theEvent];
+}
+
 - (void)keyDown:(NSEvent *)o_event
 {
     unichar key = 0;
@@ -583,7 +604,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]];
     }
 
@@ -701,7 +722,6 @@ 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 );
 
 
     /* We only wait for NSApp to initialise if we're not embedded (as in the
@@ -729,7 +749,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];
@@ -750,13 +770,13 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 - (void)enterFullscreen
 {
-    [[o_view class] resetVout: p_vout];
+    [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
     [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
 }
 
 - (void)leaveFullscreen
 {
-    [[o_view class] resetVout: p_vout];
+    [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
     [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
 }
 
@@ -923,10 +943,13 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     /* 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];
+
         [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
+
         [self updateTitle];
 
         /* Make the window the front and key window before animating */
@@ -935,9 +958,12 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
         [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)];
+
         /* Make sure our window is visible, if we are not in fullscreen */
         if (![o_window isFullscreen])
             [o_window makeKeyAndOrderFront: self];
+        [o_window unlockFullscreenAnimation];
 
     }
     return b_return;
@@ -949,7 +975,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
     if(!playlist_IsPlaying( p_playlist ))
         [o_window performSelectorOnMainThread: @selector(orderOut:) withObject: self waitUntilDone: YES];
-    
     vlc_object_release( p_playlist );
 
     [super closeVout];
@@ -1004,7 +1030,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     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,8 +1052,8 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         /* move the FSPanel to front in case that it is currently shown
          * 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] orderFront: self];
-        
+            [[[[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];
 
@@ -1036,7 +1062,7 @@ 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);
@@ -1131,7 +1157,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         CGDisplayFadeReservationToken token;
         CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
         CGDisplayFade( token, 0.3 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
-        
         [self disableScreenUpdatesUntilFlush];
         [self orderOut: self];