]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/VLCVoutWindowController.m
macosx: save idle main window frame as early as possible (refs #8826)
[vlc] / modules / gui / macosx / VLCVoutWindowController.m
index c5005d469c68814063df44c36f6e50108d4011f5..0ddc33860687b6fbfe174cd736d10036fe664a2f 100644 (file)
@@ -53,6 +53,8 @@
     [super dealloc];
 }
 
+#pragma mark -
+#pragma mark Methods for vout provider
 
 - (VLCVoutView *)setupVoutForWindow:(vout_window_t *)p_wnd withProposedVideoViewPosition:(NSRect)videoViewPosition
 {
     VLCVoutView *o_vout_view;
     VLCVideoWindowCommon *o_new_video_window;
 
+    // should be called before any window resizing occurs
+    [[VLCMainWindow sharedInstance] videoplayWillBeStarted];
+
     if (b_multiple_vout_windows && b_video_wallpaper)
         b_video_wallpaper = false;
 
-    // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
+    // TODO: make lion fullscreen compatible with video-wallpaper
     if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
         // b_video_wallpaper is priorized over !b_video_deco
 
                 [o_new_video_window center];
                 [o_new_video_window setFrameAutosaveName:@"extra-videowindow"];
             }
-            
+
             [o_new_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
         }
 
         }
     }
 
+    NSSize videoViewSize = NSMakeSize(videoViewPosition.size.width, videoViewPosition.size.height);
+
+    // TODO: find a cleaner way for "start in fullscreen"
+    // Start in fs, because either prefs settings, or fullscreen button was pressed before
+    if (var_InheritBool(VLCIntf, "fullscreen") || var_GetBool(pl_Get(VLCIntf), "fullscreen")) {
+
+        // this is not set when we start in fullscreen because of
+        // fullscreen settings in video prefs the second time
+        var_SetBool(p_wnd->p_parent, "fullscreen", 1);
+
+        int i_full = 1;
+
+        SEL sel = @selector(setFullscreen:forWindow:);
+        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:sel]];
+        [inv setTarget:self];
+        [inv setSelector:sel];
+        [inv setArgument:&i_full atIndex:2];
+        [inv setArgument:&p_wnd atIndex:3];
+
+        NSTimeInterval resizeTime = 0.;
+        if(!b_nonembedded && !b_video_wallpaper) {
+            NSRect window_rect = [o_new_video_window getWindowRectForProposedVideoViewSize:videoViewSize];
+            resizeTime = [o_new_video_window animationResizeTime:window_rect];
+            resizeTime += 0.1;
+        }
+        
+        [NSTimer scheduledTimerWithTimeInterval:resizeTime invocation:inv repeats:NO];
+    }
+
     if (!b_video_wallpaper) {
         // set window size
-        NSSize videoViewSize = NSMakeSize(videoViewPosition.size.width, videoViewPosition.size.height);
 
         if (b_nonembedded) {
             NSRect window_rect = [o_new_video_window getWindowRectForProposedVideoViewSize:videoViewSize];
+            if (videoViewPosition.origin.x > 0.)
+                window_rect.origin.x = videoViewPosition.origin.x;
+            if (videoViewPosition.origin.y > 0.)
+                window_rect.origin.y = videoViewPosition.origin.y;
+
             [o_new_video_window setFrame:window_rect display:YES];
         }
 
         // cascade windows if we have more than one vout
         if (b_multiple_vout_windows) {
             if ([o_vout_dict count] == 1) {
-                NSWindow * o_first_window = [o_vout_dict objectForKey: [[o_vout_dict allKeys] objectAtIndex: 0]];
+                NSWindow * o_first_window = [o_vout_dict objectForKey: [[o_vout_dict allKeys] objectAtIndex:0]];
 
                 NSPoint topleftbase = NSMakePoint(0, [o_first_window frame].size.height);
                 top_left_point = [o_first_window convertBaseToScreen: topleftbase];
             top_left_point = [o_new_video_window cascadeTopLeftFromPoint: top_left_point];
             [o_new_video_window setFrameTopLeftPoint: top_left_point];
         }
-        
+
         [o_new_video_window setNativeVideoSize:videoViewSize];
 
         [o_new_video_window makeKeyAndOrderFront: self];
         [[VLCMain sharedInstance] setActiveVideoPlayback:NO];
 }
 
-- (void)updateWindowsControlsBarWithSelector:(SEL)aSel
-{
-    [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
-        if ([obj respondsToSelector:@selector(controlsBar)]) {
-            id o_controlsBar = [obj controlsBar];
-            if (o_controlsBar)
-                [o_controlsBar performSelector:aSel];
-        }
-    }];
-}
-
-- (void)updateWindow:(vout_window_t *)p_wnd withSelector:(SEL)aSel;
-{
-    VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]];
-    if (!o_window) {
-        msg_Err(VLCIntf, "Cannot call selector for nonexisting window");
-        return;
-    }
-
-    [o_window performSelector:aSel];
-}
-
-- (VLCVideoWindowCommon *)getWindow:(vout_window_t *)p_wnd
-{
-    VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]];
-    assert(o_window);
-    return o_window;
-
-}
-
-- (void)updateWindowsUsingBlock:(void (^)(VLCVideoWindowCommon *o_window))windowUpdater
-{
-    [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
-        if ([obj isKindOfClass: [NSWindow class]])
-            windowUpdater(obj);
-    }];
-}
 
 - (void)setNativeVideoSize:(NSSize)size forWindow:(vout_window_t *)p_wnd
 {
     [o_window setWindowLevel:i_level];
 }
 
+
+- (void)setFullscreen:(int)i_full forWindow:(vout_window_t *)p_wnd
+{
+    intf_thread_t *p_intf = VLCIntf;
+    BOOL b_nativeFullscreenMode = [[VLCMain sharedInstance] nativeFullscreenMode];
+
+    if (!p_intf || (!b_nativeFullscreenMode && !p_wnd))
+        return;
+    playlist_t *p_playlist = pl_Get(p_intf);
+    BOOL b_fullscreen = i_full;
+
+    if (!var_GetBool(p_playlist, "fullscreen") != !b_fullscreen)
+        var_SetBool(p_playlist, "fullscreen", b_fullscreen);
+
+    VLCVideoWindowCommon *o_current_window = nil;
+    if(p_wnd)
+        o_current_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]];
+
+    if (b_nativeFullscreenMode) {
+        if(!o_current_window)
+            o_current_window = [VLCMainWindow sharedInstance];
+        assert(o_current_window);
+
+        // fullscreen might be triggered twice (vout event)
+        // so ignore duplicate events here
+        if((b_fullscreen && !([o_current_window fullscreen] || [o_current_window enteringFullscreenTransition])) ||
+           (!b_fullscreen && [o_current_window fullscreen])) {
+
+            [o_current_window toggleFullScreen:self];
+        }
+
+        if (b_fullscreen)
+            [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
+        else
+            [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
+    } else {
+        assert(o_current_window);
+
+        if (b_fullscreen) {
+            input_thread_t * p_input = pl_CurrentInput(p_intf);
+            if (p_input != NULL && [[VLCMain sharedInstance] activeVideoPlayback]) {
+                // activate app, as method can also be triggered from outside the app (prevents nasty window layout)
+                [NSApp activateIgnoringOtherApps:YES];
+                [o_current_window enterFullscreen];
+
+            }
+            if (p_input)
+                vlc_object_release(p_input);
+        } else {
+            // leaving fullscreen is always allowed
+            [o_current_window leaveFullscreen];
+        }
+    }
+}
+
+#pragma mark -
+#pragma mark Misc methods
+
+- (void)updateWindowsControlsBarWithSelector:(SEL)aSel
+{
+    [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
+        if ([obj respondsToSelector:@selector(controlsBar)]) {
+            id o_controlsBar = [obj controlsBar];
+            if (o_controlsBar)
+                [o_controlsBar performSelector:aSel];
+        }
+    }];
+}
+
+- (void)updateWindowsUsingBlock:(void (^)(VLCVideoWindowCommon *o_window))windowUpdater
+{
+    [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
+        if ([obj isKindOfClass: [NSWindow class]])
+            windowUpdater(obj);
+    }];
+}
+
 - (void)updateWindowLevelForHelperWindows:(NSInteger)i_level
 {
     if (var_InheritBool(VLCIntf, "video-wallpaper"))
 
 @synthesize currentWindowLevel=i_currentWindowLevel;
 
-
 @end