]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/vout.m
macosx: Fix aspect ratio.
[vlc] / modules / gui / macosx / vout.m
index 883040988faea1c5b59c5aa9df1ea1d13e514fdb..868eb2daa16a56a90532cb45b206a71d8af526ad 100644 (file)
@@ -274,35 +274,31 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     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;
+
+    input_item_t * p_item = input_GetItem( p_input );
 
-    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];
+    psz_title = input_item_GetNowPlaying ( p_item );
+    if( !psz_title )
+        psz_title = input_item_GetName( p_item );
 
-    if( psz_uri != NULL )
+    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];
 
-    FREENULL( psz_nowPlaying );
-    FREENULL( psz_name );
-    FREENULL( psz_uri );
+    free( psz_title );
+    free( psz_uri );
 
-    if( o_title == nil )
+    if( !o_title )
         o_title = o_mrl;
 
     if( o_mrl != nil )
@@ -347,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 */
@@ -394,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;
     }
 }
@@ -770,24 +773,18 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 - (void)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];
+    /* 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
 {
-    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];
+    /* 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
@@ -819,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;
 }
@@ -876,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
 
 /*****************************************************************************
@@ -884,16 +907,24 @@ 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;
 
@@ -903,8 +934,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     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" ) )
@@ -914,46 +944,6 @@ 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 */
@@ -975,7 +965,7 @@ 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)];
+        [o_embeddedwindow setVideoRatio:[self voutSizeForFactor:1.0]];
 
         /* Make sure our window is visible, if we are not in fullscreen */
         if (![o_window isFullscreen])
@@ -983,28 +973,47 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         [o_window unlockFullscreenAnimation];
 
     }
+
     return b_return;
 }
 
+- (void)setUsed: (BOOL)b_new_used
+{
+    b_used = b_new_used;
+}
+
+- (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 */
-    if(![self isFullscreen])
-        [o_window performSelector:@selector(orderOut:) withObject:nil afterDelay:1.5];
+    [o_embeddedwindow performSelector:@selector(orderOut:) withObject:nil afterDelay:3.];
 
-    [super closeVout];
+    [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];
 }
@@ -1022,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 )
@@ -1033,7 +1042,7 @@ 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];
@@ -1162,11 +1171,11 @@ 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 == true )
     {
@@ -1225,5 +1234,4 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     return NO;
 }
 
-
 @end