]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/vout.m
Fix utf8_readdir usage
[vlc] / modules / gui / macosx / vout.m
index c9671c119d3c8e5a1cc6a9b4c1e1c3c22e381060..78e04a5daabafcb91b840f3bcab22b257d726d63 100644 (file)
@@ -245,10 +245,21 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     [o_view setFrameSize: [self frame].size];
 }
 
+- (void)drawRect:(NSRect)rect
+{
+    /* When there is no subview we draw a black background */
+    [self lockFocus];
+    [[NSColor blackColor] set];
+    NSRectFill(rect);
+    [self unlockFocus];
+}
+
 - (void)closeVout
 {
     [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeOut];
 
+    /* Make sure we don't see a white flash */
+    [[self window] disableScreenUpdatesUntilFlush];
     [o_view removeFromSuperview];
     o_view = nil;
     p_vout = NULL;
@@ -334,6 +345,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
     if ( !p_vout->b_fullscreen )
     {
+        NSView *mainView;
         NSRect new_frame;
         topleftbase.x = 0;
         topleftbase.y = [o_window frame].size.height;
@@ -355,11 +367,18 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
             newsize.height = (int) ( i_corrected_height * factor );
         }
 
+        /* In fullscreen mode we need to use a view that is different from
+         * ourselves, with the VLCEmbeddedWindow */
+        if([o_window isKindOfClass:[VLCEmbeddedWindow class]])
+            mainView = [o_window mainView];
+        else
+            mainView = self;
+
         /* Calculate the window's new size */
         new_frame.size.width = [o_window frame].size.width -
-                                    [self frame].size.width + newsize.width;
+                                    [mainView frame].size.width + newsize.width;
         new_frame.size.height = [o_window frame].size.height -
-                                    [self frame].size.height + newsize.height;
+                                    [mainView frame].size.height + newsize.height;
 
         new_frame.origin.x = topleftscreen.x;
         new_frame.origin.y = topleftscreen.y - new_frame.size.height;
@@ -398,6 +417,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 );
 }
@@ -419,6 +439,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;
@@ -731,13 +757,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];
 }
 
@@ -842,15 +868,15 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 }
 
 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
-                     frame: (NSRect *) s_arg_frame
-
+                 frame: (NSRect *)s_arg_frame showWindow: (BOOL)b_show_window
 {
     BOOL b_return;
     b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
     if( b_return )
     {
         o_window = [self window];
-        [o_window makeKeyAndOrderFront: self];
+        if (b_show_window)
+            [o_window makeKeyAndOrderFront: self];
         [o_window setAcceptsMouseMovedEvents: TRUE];
 
         if( var_GetBool( p_real_vout, "video-on-top" ) )
@@ -863,6 +889,13 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     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;
@@ -892,21 +925,46 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 - (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];
+    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];
+
         [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
+
         [self updateTitle];
-        [self scaleWindowWithFactor: 1.0 animate: NO];
-        [o_window makeKeyAndOrderFront: self];
+
+        /* 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)];
+
+        /* 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;
 }
 
 - (void)closeVout
 {
-    [o_window orderOut: self];
+    playlist_t * p_playlist = pl_Yield( VLCIntf );
+
+    if(!playlist_IsPlaying( p_playlist ))
+        [o_window performSelectorOnMainThread: @selector(orderOut:) withObject: self waitUntilDone: YES];
+    
+    vlc_object_release( p_playlist );
+
     [super closeVout];
 }
 
@@ -958,7 +1016,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 = var_GetBool( p_vout, "macosx-black" );
+    b_black = NO;
     b_embedded = var_GetBool( p_vout, "macosx-embedded" );
 
     /* Find out on which screen to open the window */
@@ -967,7 +1025,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     if( !o_screen )
         o_screen = [NSScreen mainScreen];
 
-    if( o_screen == [NSScreen mainScreen] )
+    if( [o_screen isMainScreen] )
         b_menubar_screen = VLC_TRUE;
 
     if( p_vout->b_fullscreen )
@@ -976,10 +1034,12 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         NSRect screen_rect = [o_screen frame];
         screen_rect.origin.x = screen_rect.origin.y = 0;
 
+        b_black = var_GetBool( p_vout, "macosx-black" );
+
         /* 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];
@@ -990,9 +1050,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
               backing: NSBackingStoreBuffered
               defer: YES screen: o_screen];
         
-        if( b_black == VLC_TRUE )
-            [o_screen blackoutOtherScreens];
-
         if( b_menubar_screen )
         {
             SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
@@ -1000,7 +1057,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         if( b_black == VLC_TRUE )
         {
             CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
-            CGDisplayFade( token, 2 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
+            CGDisplayFade( token, 0.6 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
+
+            [o_screen blackoutOtherScreens];
+
+            CGDisplayFade( token, 0.3 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
             CGReleaseDisplayFadeReservation( token);
         }
     }
@@ -1072,7 +1133,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 {
     /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
        Command-Q */
-    [self setContentView: NULL];
     [self performSelectorOnMainThread: @selector(closeReal:)
         withObject: NULL waitUntilDone: NO];
 }
@@ -1083,10 +1143,17 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     {
         CGDisplayFadeReservationToken token;
         CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
-        CGDisplayFade( token, 2, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
+        CGDisplayFade( token, 0.3 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
+        
+        [self disableScreenUpdatesUntilFlush];
+        [self orderOut: self];
+
+        CGDisplayFade( token, 0.6 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, YES );
         CGReleaseDisplayFadeReservation( token);
         CGDisplayRestoreColorSyncSettings();
     }
+    [NSScreen unblackoutScreens];
+
     SetSystemUIMode( kUIModeNormal, 0);
     [super close];
     /* this does only work in embedded mode */