]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/embeddedwindow.m
Removes trailing spaces. Removes tabs.
[vlc] / modules / gui / macosx / embeddedwindow.m
index 7510e787671dfbf5631eb1b561bd7180ff0d9a4b..b5d4a02d065ce5a2c4a58ed316718106c9ebb6a5 100644 (file)
@@ -55,8 +55,6 @@
     o_img_pause = [NSImage imageNamed: @"pause_embedded"];
     o_img_pause_pressed = [NSImage imageNamed: @"pause_embedded_blue"];
 
-    o_saved_frame = NSMakeRect( 0.0f, 0.0f, 0.0f, 0.0f );
-
     /* Useful to save o_view frame in fullscreen mode */
     o_temp_view = [[NSView alloc] init];
     [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
     /* Not fullscreen when we wake up */
     [o_btn_fullscreen setState: NO];
     b_fullscreen = NO;
+    /* 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
     [o_slider setEnabled: b_seekable];
 }
 
-- (void)zoom:(id)sender
+- (BOOL)windowShouldZoom:(NSWindow *)sender toFrame:(NSRect)newFrame
 {
-    if( ![self isZoomed] )
-    {
-        NSRect zoomRect = [[self screen] frame];
-        o_saved_frame = [self frame];
-        /* we don't have to take care of the eventual menu bar and dock
-          as zoomRect will be cropped automatically by setFrame:display:
-          to the right rectangle */
-        [self setFrame: zoomRect display: YES animate: YES];
-    }
-    else
-    {
-        /* unzoom to the saved_frame if the o_saved_frame coords look sound
-           (just in case) */
-        if( o_saved_frame.size.width > 0 && o_saved_frame.size.height > 0 )
-            [self setFrame: o_saved_frame display: YES animate: YES];
-    }
+    [self setFrame: newFrame display: YES animate: YES];
+    return YES;
 }
 
 - (BOOL)windowShouldClose:(id)sender
     return b_fullscreen;
 }
 
+- (void)lockFullscreenAnimation
+{
+    [o_animation_lock lock];
+}
+
+- (void)unlockFullscreenAnimation
+{
+    [o_animation_lock unlock];
+}
+
 - (void)enterFullscreen
 {
     NSMutableDictionary *dict1, *dict2;
     screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_GetInteger( p_vout, "video-device" )];
 
     vlc_object_release( p_vout );
+    [self lockFullscreenAnimation];
 
     if (!screen)
         screen = [self screen];
     [o_btn_fullscreen setState: YES];
 
     [NSCursor setHiddenUntilMouseMoves: YES];
-    
     if (blackout_other_displays)
         [screen blackoutOtherScreens]; /* We should do something like [screen blackoutOtherScreens]; */
 
              * Mac OS X <10.4 which doesn't support NSAnimation, instead we
              * simply fade the display */
             CGDisplayFadeReservationToken token;
-            
             [o_fullscreen_window setFrame:screen_rect display:NO];
-            
             CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
             CGDisplayFade( token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
-            
-            if (screen == [NSScreen mainScreen])
+            if ([screen isMainScreen])
                 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
-            
             [[self contentView] replaceSubview:o_view with:o_temp_view];
             [o_temp_view setFrame:[o_view frame]];
             [o_fullscreen_window setContentView:o_view];
 
             CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
             CGReleaseDisplayFadeReservation( token);
+
+            /* Will release the lock */
             [self hasBecomeFullscreen];
+
             return;
         }
-        
         /* Make sure we don't see the o_view disappearing of the screen during this operation */
         DisableScreenUpdates();
         [[self contentView] replaceSubview:o_view with:o_temp_view];
     {
         /* We were already fullscreen nothing to do when NSAnimation
          * is not supported */
+        b_animation_lock_alreadylocked = NO;
+        [self unlockFullscreenAnimation];
         return;
     }
 
     /* We are in fullscreen (and no animation is running) */
     if (b_fullscreen)
+    {
+        /* Make sure we are hidden */
+        [super orderOut: self];
+        b_animation_lock_alreadylocked = NO;
+        [self unlockFullscreenAnimation];
         return;
+    }
 
     if (o_fullscreen_anim1)
     {
         [o_fullscreen_anim2 release];
     }
  
-    if (screen == [NSScreen mainScreen])
+     /* 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 isMainScreen])
         SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
 
     dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
     [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
 
     [o_fullscreen_anim1 startAnimation];
+    /* fullscreenAnimation will be unlocked when animation ends */
 }
 
 - (void)hasBecomeFullscreen
 
     /* tell the fspanel to move itself to front next time it's triggered */
     [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
-    
+    [super orderOut: self];
+
     [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
     b_fullscreen = YES;
+    [self unlockFullscreenAnimation];
 }
 
 - (void)leaveFullscreen
+{
+    [self leaveFullscreenAndFadeOut: NO];
+}
+
+- (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
 {
     NSMutableDictionary *dict1, *dict2;
     NSRect frame;
-    
+
+    [self lockFullscreenAnimation];
+
     b_fullscreen = NO;
     [o_btn_fullscreen setState: NO];
 
 
     /* Don't do anything if o_fullscreen_window is already closed */
     if (!o_fullscreen_window)
+    {
+        b_animation_lock_alreadylocked = NO;
+        [self unlockFullscreenAnimation];
         return;
+    }
 
-    if (![self isVisible] || MACOS_VERSION < 10.4f)
+    if (fadeout || MACOS_VERSION < 10.4f)
     {
         /* We don't animate if we are not visible or if we are running on
         * Mac OS X <10.4 which doesn't support NSAnimation, instead we
         [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
         SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
 
+        /* Will release the lock */
         [self hasEndedFullscreen];
 
         CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
         return;
     }
 
+    [self setAlphaValue: 0.0];
+    [self orderFront: self];
+
     [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
     SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
 
         [o_fullscreen_anim2 release];
     }
 
+    /* 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;
+
     frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
-    frame.origin.x += [self frame].origin.x; 
+    frame.origin.x += [self frame].origin.x;
     frame.origin.y += [self frame].origin.y;
 
     dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
     [o_fullscreen_anim1 setDuration: 0.2];
     [o_fullscreen_anim1 setFrameRate: 30];
     [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
+
+    /* Make sure o_fullscreen_window is the frontmost window */
+    [o_fullscreen_window orderFront: self];
+
     [o_fullscreen_anim1 startAnimation];
+    /* fullscreenAnimation will be unlocked when animation ends */
 }
 
 - (void)hasEndedFullscreen
     [[self contentView] replaceSubview:o_temp_view with:o_view];
     [o_view release];
     [o_view setFrame:[o_temp_view frame]];
+    [self makeFirstResponder: o_view];
     if ([self isVisible])
         [self makeKeyAndOrderFront:self];
     [o_fullscreen_window orderOut: self];
 
     [o_fullscreen_window release];
     o_fullscreen_window = nil;
+    b_animation_lock_alreadylocked = NO;
+    [self unlockFullscreenAnimation];
 }
 
 - (void)animationDidEnd:(NSAnimation*)animation
 {
     [super orderOut: sender];
     /* Make sure we leave fullscreen */
-    [self leaveFullscreen];
+    [self leaveFullscreenAndFadeOut: YES];
 }
 
 /* Make sure setFrame gets executed on main thread especially if we are animating.