]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/embeddedwindow.m
Fixed fullscreen on exit (the embedded video can live longer than QT
[vlc] / modules / gui / macosx / embeddedwindow.m
index 774e18d016a71a98f7dd542ec2554e92e307609c..03b2aa0e0751719bd448b4efb10c33446363aa02 100644 (file)
     [o_btn_fullscreen setState: NO];
     b_fullscreen = NO;
 
+    [self setMovableByWindowBackground:YES];
+
+    [self setDelegate:self];
+
     /* Make sure setVisible: returns NO */
     [self orderOut:self];
     b_window_is_invisible = YES;
+    videoRatio = NSMakeSize( 0., 0. );
 }
 
 - (void)controlTintChanged
         return o_view;
 }
 
+- (void)setVideoRatio:(NSSize)ratio
+{
+    videoRatio = ratio;
+}
+
+- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
+{
+    if( videoRatio.height == 0. || videoRatio.width == 0. )
+        return proposedFrameSize;
+
+    NSRect viewRect = [o_view convertRect:[o_view bounds] toView: nil];
+    NSRect contentRect = [self contentRectForFrameRect:[self frame]];
+    float marginy = viewRect.origin.y + [self frame].size.height - contentRect.size.height;
+    float marginx = contentRect.size.width - viewRect.size.width;
+    proposedFrameSize.height = (proposedFrameSize.width - marginx) * videoRatio.height / videoRatio.width + marginy;
+
+    return proposedFrameSize;
+}
+
 /*****************************************************************************
  * Fullscreen support
  */
     if( blackout_other_displays )        
         [screen blackoutOtherScreens];
 
+    /* Make sure we don't see the window flashes in float-on-top mode */
+    originalLevel = [self level];
+    [self setLevel:NSNormalWindowLevel];
+
     /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
     if (!o_fullscreen_window)
     {
 
     [o_fullscreen_window release];
     o_fullscreen_window = nil;
+    [self setLevel:originalLevel];
+
     [self unlockFullscreenAnimation];
 }
 
 {
     struct args { NSRect frame; BOOL display; BOOL animate; } * args = (struct args*)[packedargs bytes];
 
-    [super setFrame: args->frame display: args->display animate:args->animate];
+    if( args->animate )
+    {
+        /* Make sure we don't block too long and set up a non blocking animation */
+        NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
+            self, NSViewAnimationTargetKey,
+            [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
+            [NSValue valueWithRect:args->frame], NSViewAnimationEndFrameKey, nil];
+
+        NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
+
+        [anim setAnimationBlockingMode: NSAnimationNonblocking];
+        [anim setDuration: 0.4];
+        [anim setFrameRate: 30];
+        [anim startAnimation];
+    }
+    else {
+        [super setFrame:args->frame display:args->display animate:args->animate];
+    }
+
 }
 @end