]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/Windows.m
Remove the deprecated vlc_atomic_t type.
[vlc] / modules / gui / macosx / Windows.m
index af7e65b4d3afb4ee42b5ccb14db21dbf44fdd80f..032ac24ae73c383c4ed3b45df92f5446299d38e0 100644 (file)
@@ -88,7 +88,9 @@
         return;
     }
 
-    invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(close)]];
+    // TODO this callback stuff does not work and is not needed
+    invoc = [[[NSInvocation alloc] init] autorelease];
+    [invoc setSelector:@selector(close)];
     [invoc setTarget: self];
 
     if (![self isVisible] || [self alphaValue] == 0.0) {
 
 - (void)orderOut: (id)sender animate: (BOOL)animate
 {
-    NSInvocation *invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(orderOut:)]];
+    NSInvocation *invoc = [[[NSInvocation alloc] init] autorelease];
+    [invoc setSelector:@selector(orderOut:)];
     [invoc setTarget: self];
-    [invoc setArgument: sender atIndex: 0];
+    [invoc setArgument: sender atIndex: 2];
     [self orderOut: sender animate: animate callback: invoc];
 }
 
     [dict setObject:self forKey:NSViewAnimationTargetKey];
 
     [dict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
-    anim = [[NSViewAnimation alloc] initWithViewAnimations:@[dict]];
+    anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
     [dict release];
 
     [anim setAnimationBlockingMode:NSAnimationNonblocking];
     [anim setDuration:0.9];
     [anim setFrameRate:30];
-    [anim setUserInfo: callback];
+    [anim setUserInfo:callback];
+    [anim setDelegate:self];
 
     @synchronized(self) {
         current_anim = self->o_current_animation;
     [dict setObject:self forKey:NSViewAnimationTargetKey];
 
     [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
-    anim = [[NSViewAnimation alloc] initWithViewAnimations:@[dict]];
+    anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
     [dict release];
 
     [anim setAnimationBlockingMode:NSAnimationNonblocking];
     [anim setDuration:0.5];
     [anim setFrameRate:30];
+    [anim setDelegate:self];
 
     @synchronized(self) {
         current_anim = self->o_current_animation;
         NSInvocation * invoc;
         [super orderOut: nil];
         [self setAlphaValue: 1.0];
-        if ((invoc = [anim userInfo]))
+        if ((invoc = [anim userInfo])) {
             [invoc invoke];
+        }
     }
 }
 
     if (!([self styleMask] & NSTitledWindowMask)) {
         [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowWillCloseNotification object:self];
 
-        [self orderOut: sender];
+        [self close];
     } else
         [super performClose: sender];
 }
     if (var_InheritBool(VLCIntf, "video-wallpaper") || [self level] < NSNormalWindowLevel)
         return;
 
-    [self setLevel: i_state];
-
+    if (!b_fullscreen && !b_entering_fullscreen_transition)
+        [self setLevel: i_state];
+    else {
+        // only save it for restore
+        i_originalLevel = i_state;
+    }
 }
 
 - (NSRect)getWindowRectForProposedVideoViewSize:(NSSize)size
     // workaround, see #6668
     [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
 
+    i_originalLevel = [self level];
+    // b_fullscreen and b_entering_fullscreen_transition must not be true yet
+    [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
+    [self setLevel:NSNormalWindowLevel];
+
     b_entering_fullscreen_transition = YES;
 
     var_SetBool(pl_Get(VLCIntf), "fullscreen", true);
     if ([self hasActiveVideo])
         [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
 
-    i_originalLevel = [self level];
-    [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
-    [self setLevel:NSNormalWindowLevel];
-
     if (b_dark_interface) {
         [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
 
 
     [NSCursor setHiddenUntilMouseMoves: NO];
     [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
-    
-    [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
-    [self setLevel:i_originalLevel];
+
 
     if (b_dark_interface) {
         NSRect winrect;
     if (![o_video_view isHidden]) {
         [[o_controls_bar bottomBarView] setHidden: NO];
     }
-    
+
     [self setMovableByWindowBackground: YES];
 }
 
-#pragma mark -
-#pragma mark Fullscreen Logic
-
-- (void)lockFullscreenAnimation
+- (void)windowDidExitFullScreen:(NSNotification *)notification
 {
-    [o_animation_lock lock];
+    [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
+    [self setLevel:i_originalLevel];
 }
 
-- (void)unlockFullscreenAnimation
-{
-    [o_animation_lock unlock];
-}
+#pragma mark -
+#pragma mark Fullscreen Logic
 
 - (void)enterFullscreen
 {
     BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
 
     screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
-    [self lockFullscreenAnimation];
 
     if (!screen) {
         msg_Dbg(VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode");
 
     /* Make sure we don't see the window flashes in float-on-top mode */
     i_originalLevel = [self level];
+    // b_fullscreen must not be true yet
     [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
     [self setLevel:NSNormalWindowLevel];
 
-
     /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
     if (!o_fullscreen_window) {
         /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
 
             [screen setFullscreenPresentationOptions];
 
+            [o_video_view retain];
             [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
             [o_temp_view setFrame:[o_video_view frame]];
             [o_fullscreen_window setContentView:o_video_view];
+            [o_video_view release];
 
             [o_fullscreen_window makeKeyAndOrderFront:self];
             [o_fullscreen_window orderFront:self animate:YES];
             return;
         }
 
+        /* Make sure video view gets visible in case the playlist was visible before */
+        b_video_view_was_hidden = [o_video_view isHidden];
+        [o_video_view setHidden: NO];
+
         /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
         NSDisableScreenUpdates();
+        [o_video_view retain];
         [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
         [o_temp_view setFrame:[o_video_view frame]];
         [o_fullscreen_window setContentView:o_video_view];
+        [o_video_view release];
         [o_fullscreen_window makeKeyAndOrderFront:self];
         NSEnableScreenUpdates();
     }
         /* Make sure we are hidden */
         [self orderOut: self];
 
-        [self unlockFullscreenAnimation];
         return;
     }
 
      - Keep at most 2 animation at a time
      - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
      */
-    o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:@[dict1]];
-    o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:@[dict2]];
+    o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
+    o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
 
     [dict1 release];
     [dict2 release];
 
     [o_fullscreen_anim1 startAnimation];
     /* fullscreenAnimation will be unlocked when animation ends */
+
+    b_entering_fullscreen_transition = YES;
 }
 
 - (void)hasBecomeFullscreen
     if ([self isVisible])
         [self orderOut: self];
 
+    b_entering_fullscreen_transition = NO;
     [self setFullscreen:YES];
-    [self unlockFullscreenAnimation];
 }
 
 - (void)leaveFullscreen
     NSRect frame;
     BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
 
-    [self lockFullscreenAnimation];
-
     if (o_controls_bar)
         [o_controls_bar setFullscreenState:NO];
     [[[VLCMainWindow sharedInstance] controlsBar] setFullscreenState:NO];
 
     /* Don't do anything if o_fullscreen_window is already closed */
     if (!o_fullscreen_window) {
-        [self unlockFullscreenAnimation];
         return;
     }
 
     [dict2 setObject:self forKey:NSViewAnimationTargetKey];
     [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
 
-    o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:@[dict2]];
+    o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
     [dict2 release];
 
     [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
     [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
     [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
 
-    o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:@[dict1]];
+    o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
     [dict1 release];
 
     [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
     if ([[o_video_view subviews] count] > 0)
         [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
 
+    [o_video_view setHidden: b_video_view_was_hidden];
+
     [super makeKeyAndOrderFront:self]; /* our version (in main window) contains a workaround */
 
     [o_fullscreen_window orderOut: self];
 
     [o_fullscreen_window release];
     o_fullscreen_window = nil;
-    
+
     [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: i_originalLevel];
     [self setLevel:i_originalLevel];
+
     [self setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
 
     // if we quit fullscreen because there is no video anymore, make sure non-embedded window is not visible
     if (![[VLCMain sharedInstance] activeVideoPlayback] && [self class] != [VLCMainWindow class])
         [self orderOut: self];
-
-    [self unlockFullscreenAnimation];
 }
 
 - (void)animationDidEnd:(NSAnimation*)animation
         [self hasBecomeFullscreen];
 }
 
+- (void)orderOut:(id)sender
+{
+    [super orderOut:sender];
+
+    /*
+     * TODO reimplement leaveFullscreenAndFadeOut:YES, or remove code
+     * and the hack below
+    
+    if (![NSStringFromClass([self class]) isEqualToString:@"VLCMainWindow"]) {
+        [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];
+    [dict setObject:self forKey:NSViewAnimationTargetKey];
+    [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
+
+    o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
+    [dict release];
+
+    [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
+    [o_makekey_anim setDuration: 0.1];
+    [o_makekey_anim setFrameRate: 30];
+    [o_makekey_anim setDelegate: self];
+
+    [o_makekey_anim startAnimation];
+    b_window_is_invisible = NO;
+
+    /* fullscreenAnimation will be unlocked when animation ends */
+}
+
+
 #pragma mark -
 #pragma mark Accessibility stuff
 
     static NSMutableArray *attributes = nil;
     if (attributes == nil) {
         attributes = [[super accessibilityAttributeNames] mutableCopy];
-        NSArray *appendAttributes = @[NSAccessibilitySubroleAttribute,
-                                      NSAccessibilityCloseButtonAttribute,
-                                      NSAccessibilityMinimizeButtonAttribute,
-                                      NSAccessibilityZoomButtonAttribute];
+        NSArray *appendAttributes = [NSArray arrayWithObjects:NSAccessibilitySubroleAttribute,
+                                     NSAccessibilityCloseButtonAttribute,
+                                     NSAccessibilityMinimizeButtonAttribute,
+                                     NSAccessibilityZoomButtonAttribute, nil];
 
         for(NSString *attribute in appendAttributes) {
             if (![attributes containsObject:attribute])