Mac OS X gui: Use a recursive lock to be able to trigger enter/leaveFullscreen in...
authorPierre d'Herbemont <pdherbemont@videolan.org>
Sat, 3 Mar 2007 11:45:29 +0000 (11:45 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Sat, 3 Mar 2007 11:45:29 +0000 (11:45 +0000)
modules/gui/macosx/embeddedwindow.h
modules/gui/macosx/embeddedwindow.m
modules/gui/macosx/vout.m

index 0a114c9..e541fa2 100644 (file)
@@ -50,7 +50,8 @@
     NSView          * o_temp_view;
     /* set to yes if we are fullscreen and all animations are over */
     BOOL              b_fullscreen;
-    NSLock          * o_animation_lock;
+    BOOL              b_animation_lock_alreadylocked;
+    NSRecursiveLock * o_animation_lock;
 }
 
 - (void)setTime:(NSString *)o_arg_ime position:(float)f_position;
index 232ce2a..5c34e10 100644 (file)
     /* Not fullscreen when we wake up */
     [o_btn_fullscreen setState: NO];
     b_fullscreen = NO;
-    o_animation_lock = [[NSLock alloc] init];
+    /* Use a recursive lock to be able to trigger enter/leavefullscreen
+     * in middle of an animation, providing that the enter/leave functions
+     * are called from the same thread */
+    o_animation_lock = [[NSRecursiveLock alloc] init];
+    b_animation_lock_alreadylocked = NO;
 }
 
 - (void)setTime:(NSString *)o_arg_time position:(float)f_position
     
     [self lockFullscreenAnimation];
 
+    /* This is a recursive lock. If we are already in the middle of an animation we
+     * unlock it. We don't add an extra locking here, because enter/leavefullscreen
+     * are executed always in the same thread */ 
+    if (b_animation_lock_alreadylocked)
+        [self unlockFullscreenAnimation];
+    b_animation_lock_alreadylocked = YES;
+
     if (!screen)
         screen = [self screen];
 
         /* We were already fullscreen nothing to do when NSAnimation
          * is not supported */
         [self unlockFullscreenAnimation];
+        b_animation_lock_alreadylocked = NO;
         return;
     }
 
     if (b_fullscreen)
     {
         [self unlockFullscreenAnimation];
+        b_animation_lock_alreadylocked = NO;
         return;
     }
 
 
     [self lockFullscreenAnimation];
 
+    /* This is a recursive lock. If we are already in the middle of an animation we
+     * unlock it. We don't add an extra locking here, because enter/leavefullscreen
+     * are executed always in the same thread */ 
+    if (b_animation_lock_alreadylocked)
+        [self unlockFullscreenAnimation];
+    b_animation_lock_alreadylocked = YES;
+
     b_fullscreen = NO;
     [o_btn_fullscreen setState: NO];
 
     /* Don't do anything if o_fullscreen_window is already closed */
     if (!o_fullscreen_window)
     {
-        [self lockFullscreenAnimation];
+        [self unlockFullscreenAnimation];
+        b_animation_lock_alreadylocked = NO;
         return;
     }
 
     [o_fullscreen_window release];
     o_fullscreen_window = nil;
     [self unlockFullscreenAnimation];
+    b_animation_lock_alreadylocked = NO;
 }
 
 - (void)animationDidEnd:(NSAnimation*)animation
index 0b1a347..d5aa8ab 100644 (file)
@@ -926,10 +926,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     
     if( b_return )
     {
+        [o_window lockFullscreenAnimation];
+
         [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
-        [self updateTitle];
 
-        [o_window lockFullscreenAnimation];
+        [self updateTitle];
 
         /* Make the window the front and key window before animating */
         if ([o_window isVisible] && (![o_window isFullscreen]))