]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/embeddedwindow.m
macosx: Make sure makeKeyAndOrderFront doesn't hide and then display the window if...
[vlc] / modules / gui / macosx / embeddedwindow.m
index 4ce60e655c601168d7573930f2b10048f250d38b..774e18d016a71a98f7dd542ec2554e92e307609c 100644 (file)
     /* Not fullscreen when we wake up */
     [o_btn_fullscreen setState: NO];
     b_fullscreen = NO;
+
+    /* Make sure setVisible: returns NO */
+    [self orderOut:self];
+    b_window_is_invisible = YES;
 }
 
 - (void)controlTintChanged
         msg_Dbg( p_vout, "chosen screen isn't present, using current screen for fullscreen mode" );
         screen = [self screen];
     }
-    
+    if (!screen)
+    {
+        msg_Dbg( p_vout, "Using deepest screen" );
+        screen = [NSScreen deepestScreen];
+    }
+
     vlc_object_release( p_vout );
 
     screen_rect = [screen frame];
              * 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 );
+            CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
  
             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];
+
             [o_fullscreen_window makeKeyAndOrderFront:self];
-            [self orderOut: self];
 
-            CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
+            [o_fullscreen_window makeKeyAndOrderFront:self];
+            [o_fullscreen_window orderFront:self animate:YES];
+
+            [o_fullscreen_window setFrame:screen_rect display:YES];
+
+            CGDisplayFade( token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
             CGReleaseDisplayFadeReservation( token);
 
             /* Will release the lock */
 
     /* 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];
+
+    if([self isVisible])
+        [super orderOut: self];
 
     [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
+
     b_fullscreen = YES;
     [self unlockFullscreenAnimation];
 }
         /* Will release the lock */
         [self hasEndedFullscreen];
 
+        /* Our window is hidden, and might be faded. We need to workaround that, so note it
+         * here */
+        b_window_is_invisible = YES;
+
         CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
         CGReleaseDisplayFadeReservation( token);
         return;
     [o_view setFrame:[o_temp_view frame]];
     [self makeFirstResponder: o_view];
     if ([self isVisible])
-        [self makeKeyAndOrderFront:self];
+        [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
     [o_fullscreen_window orderOut: self];
     EnableScreenUpdates();
 
 - (void)orderOut: (id)sender
 {
     [super orderOut: sender];
+
     /* Make sure we leave fullscreen */
     [self leaveFullscreenAndFadeOut: YES];
 }
 
+- (void)makeKeyAndOrderFront: (id)sender
+{
+    /* Hack
+     * when we exit fullscreen and fade out, we may endup in
+     * having a window that is faded. We can't have it fade in unless we
+     * animate again. */
+
+    if(!b_window_is_invisible)
+    {
+        /* Make sure we don't do it too much */
+        [super makeKeyAndOrderFront: sender];
+        return;
+    }
+
+    [super setAlphaValue:0.0f];
+    [super makeKeyAndOrderFront: sender];
+
+    NSMutableDictionary * dict = [[[NSMutableDictionary alloc] initWithCapacity:2] autorelease];
+    [dict setObject:self forKey:NSViewAnimationTargetKey];
+    [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
+
+    NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
+
+    [anim setAnimationBlockingMode: NSAnimationNonblocking];
+    [anim setDuration: 0.1];
+    [anim setFrameRate: 30];
+
+    [anim startAnimation];
+    b_window_is_invisible = NO;
+
+    /* fullscreenAnimation will be unlocked when animation ends */
+}
+
+
+
 /* Make sure setFrame gets executed on main thread especially if we are animating.
  * (Thus we won't block the video output thread) */
 - (void)setFrame:(NSRect)frame display:(BOOL)display animate:(BOOL)animate