[vlc-commits] [Git][videolan/vlc][master] 4 commits: macosx: Refactor setupVoutForWindow video window creation for readability

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sun Nov 6 08:42:54 UTC 2022



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
dfc14f60 by Claudio Cambra at 2022-11-06T08:25:59+00:00
macosx: Refactor setupVoutForWindow video window creation for readability

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
7452b3fe by Claudio Cambra at 2022-11-06T08:25:59+00:00
macosx: Refactor setupVoutForWindow video window resizing and positioning for readability

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
435aa118 by Claudio Cambra at 2022-11-06T08:25:59+00:00
macosx: Refactor setupVoutForWindow video window video activation for readability

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
861594fa by Claudio Cambra at 2022-11-06T08:25:59+00:00
macosx: Refactor setupVoutForWindow video window fullscreen start for readability

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


1 changed file:

- modules/gui/macosx/windows/video/VLCVideoOutputProvider.m


Changes:

=====================================
modules/gui/macosx/windows/video/VLCVideoOutputProvider.m
=====================================
@@ -263,100 +263,127 @@ int WindowOpen(vlc_window_t *p_wnd)
     return newVideoWindow;
 }
 
-- (VLCVoutView *)setupVoutForWindow:(vlc_window_t *)p_wnd withProposedVideoViewPosition:(NSRect)videoViewPosition
+- (VLCVideoWindowCommon *)setupMainLibraryVideoWindow
 {
     VLCMain *mainInstance = [VLCMain sharedInstance];
-    _playerController = mainInstance.playlistController.playerController;
-    VLCVideoWindowCommon *newVideoWindow;
+    
+    // should be called before any window resizing occurs
+    [mainInstance.libraryWindow videoPlaybackWillBeStarted];
+    b_mainWindowHasVideo = YES;
+    
+    return mainInstance.libraryWindow;
+}
+
+- (VLCVideoWindowCommon *)setupDetachedVideoWindow
+{
+    BOOL multipleVoutWindows = _voutWindows.count > 0;
+    // setup detached window with controls
+    NSWindowController *o_controller = [[NSWindowController alloc] initWithWindowNibName:@"DetachedVideoWindow"];
+    [o_controller loadWindow];
+    VLCVideoWindowCommon *newVideoWindow = (VLCDetachedVideoWindow *)o_controller.window;
+
+    // no frame autosave for additional vout windows
+    if (multipleVoutWindows) {
+        newVideoWindow.frameAutosaveName = @"";
+    }
 
+    newVideoWindow.delegate = newVideoWindow;
+    newVideoWindow.level = NSNormalWindowLevel;
+    return newVideoWindow;
+}
+
+- (VLCVideoWindowCommon *)setupVideoWindow
+{
     BOOL isNativeFullscreen = var_InheritBool(getIntf(), "macosx-nativefullscreenmode");
     BOOL windowDecorations = var_InheritBool(getIntf(), "video-deco");
     BOOL videoWallpaper = var_InheritBool(getIntf(), "video-wallpaper");
 
-    BOOL isEmbedded = NO;
-    BOOL multipleVoutWindows = _voutWindows.count > 0;
-
-    // should be called before any window resizing occurs
-    if (!multipleVoutWindows) {
-        [mainInstance.libraryWindow videoPlaybackWillBeStarted];
-    } else if (videoWallpaper) {
-        videoWallpaper = false;
-    }
-
     // TODO: make lion fullscreen compatible with video-wallpaper
     if ((videoWallpaper || !windowDecorations) && !isNativeFullscreen) {
-        newVideoWindow = [self borderlessVideoWindowAsVideoWallpaper:videoWallpaper withWindowDecorations:windowDecorations];
-    } else {
-        isEmbedded = var_InheritBool(getIntf(), "embedded-video") && !b_mainWindowHasVideo;
-        if (isEmbedded) {
-            // setup embedded video
-            newVideoWindow = mainInstance.libraryWindow;
-            b_mainWindowHasVideo = YES;
-        } else {
-            // setup detached window with controls
-            NSWindowController *o_controller = [[NSWindowController alloc] initWithWindowNibName:@"DetachedVideoWindow"];
-            [o_controller loadWindow];
-            newVideoWindow = (VLCDetachedVideoWindow *)o_controller.window;
-
-            // no frame autosave for additional vout windows
-            if (multipleVoutWindows) {
-                newVideoWindow.frameAutosaveName = @"";
-            }
-
-            newVideoWindow.delegate = newVideoWindow;
-            newVideoWindow.level = NSNormalWindowLevel;
-        }
+        return [self borderlessVideoWindowAsVideoWallpaper:videoWallpaper withWindowDecorations:windowDecorations];
     }
+    
+    BOOL isEmbedded = var_InheritBool(getIntf(), "embedded-video") && !b_mainWindowHasVideo;
+    if (isEmbedded) {
+        return [self setupMainLibraryVideoWindow];
+    }
+    
+    return [self setupDetachedVideoWindow];
+}
 
-    VLCVoutView *voutView = newVideoWindow.videoView;
-    NSSize videoViewSize = NSMakeSize(videoViewPosition.size.width, videoViewPosition.size.height);
+- (void)setupWindowOriginForVideoWindow:(VLCVideoWindowCommon *)videoWindow
+                             atPosition:(NSRect)videoViewPosition
+{
+    NSRect window_rect = [videoWindow frame];
+    if (videoViewPosition.origin.x > 0.)
+        window_rect.origin.x = videoViewPosition.origin.x;
+    if (videoViewPosition.origin.y > 0.)
+        window_rect.origin.y = videoViewPosition.origin.y;
 
-    // Avoid flashes if video will directly start in fullscreen
-    [NSAnimationContext beginGrouping];
+    [videoWindow setFrame:window_rect display:YES];
+}
 
-    if (!videoWallpaper) {
-        // set (only!) window origin if specified
-        if (!isEmbedded) {
-            NSRect window_rect = [newVideoWindow frame];
-            if (videoViewPosition.origin.x > 0.)
-                window_rect.origin.x = videoViewPosition.origin.x;
-            if (videoViewPosition.origin.y > 0.)
-                window_rect.origin.y = videoViewPosition.origin.y;
-
-            [newVideoWindow setFrame:window_rect display:YES];
-        }
+- (void)cascadeVoutWindowsForVideoWindow:(VLCVideoWindowCommon *)videoWindow
+{
+    if (_voutWindows.count == 1) {
+        NSWindow * firstWindow = [_voutWindows objectForKey:_voutWindows.allKeys.firstObject];
 
-        // cascade windows if we have more than one vout
-        if (multipleVoutWindows) {
-            if (_voutWindows.count == 1) {
-                NSWindow * firstWindow = [_voutWindows objectForKey:_voutWindows.allKeys.firstObject];
+        NSRect topleftBaseRect = NSMakeRect(0, firstWindow.frame.size.height, 0, 0);
+        _topLeftPoint = [firstWindow convertRectToScreen:topleftBaseRect].origin;
+    }
 
-                NSRect topleftBaseRect = NSMakeRect(0, firstWindow.frame.size.height, 0, 0);
-                _topLeftPoint = [firstWindow convertRectToScreen:topleftBaseRect].origin;
-            }
+    _topLeftPoint = [videoWindow cascadeTopLeftFromPoint:_topLeftPoint];
+    [videoWindow setFrameTopLeftPoint:_topLeftPoint];
+}
 
-            _topLeftPoint = [newVideoWindow cascadeTopLeftFromPoint:_topLeftPoint];
-            [newVideoWindow setFrameTopLeftPoint:_topLeftPoint];
-        }
+- (void)setupPositionAndSizeForVideoWindow:(VLCVideoWindowCommon *)videoWindow
+                                atPosition:(NSRect)videoViewPosition
+{
+    BOOL isEmbedded = [videoWindow isKindOfClass:[VLCLibraryWindow class]];
+    BOOL multipleVoutWindows = _voutWindows.count > 0;
+    NSSize videoViewSize = NSMakeSize(videoViewPosition.size.width, videoViewPosition.size.height);
+    
+    // set (only!) window origin if specified
+    if (!isEmbedded) {
+        [self setupWindowOriginForVideoWindow:videoWindow
+                                   atPosition:videoViewPosition];
+    }
 
-        // resize window
-        [newVideoWindow setNativeVideoSize:videoViewSize];
-        [newVideoWindow makeKeyAndOrderFront: self];
+    // cascade windows if we have more than one vout
+    if (multipleVoutWindows) {
+        [self cascadeVoutWindowsForVideoWindow:videoWindow];
     }
 
-    [newVideoWindow setAlphaValue:config_GetFloat("macosx-opaqueness")];
-    [_voutWindows setObject:newVideoWindow forKey:[NSValue valueWithPointer:p_wnd]];
+    // resize window
+    [videoWindow setNativeVideoSize:videoViewSize];
+    [videoWindow makeKeyAndOrderFront: self];
+}
+
+- (void)setupVideoOutputForVideoWindow:(VLCVideoWindowCommon *)videoWindow
+                         withVlcWindow:(vlc_window_t *)p_wnd
+{
+    VLCVoutView *voutView = videoWindow.videoView;
+    
+    [videoWindow setAlphaValue:config_GetFloat("macosx-opaqueness")];
+    [_voutWindows setObject:videoWindow forKey:[NSValue valueWithPointer:p_wnd]];
     [voutView setVoutThread:(vout_thread_t *)vlc_object_parent(p_wnd)];
-    newVideoWindow.hasActiveVideo = YES;
+    videoWindow.hasActiveVideo = YES;
     _playerController.activeVideoPlayback = YES;
-    mainInstance.libraryWindow.nonembedded = !b_mainWindowHasVideo;
+    [VLCMain sharedInstance].libraryWindow.nonembedded = !b_mainWindowHasVideo;
+}
 
+- (void)setupFullscreenStartIfNeededForVout:(VLCVoutView *)voutView
+                              withVlcWindow:(vlc_window_t *)p_wnd
+{
     // TODO: find a cleaner way for "start in fullscreen"
     // Start in fs, because either prefs settings, or fullscreen button was pressed before
     /* detect the video-splitter and prevent starts in fullscreen if it is enabled */
     char *psz_splitter = var_GetString(voutView.voutThread, "video-splitter");
     BOOL b_have_splitter = psz_splitter != NULL && strcmp(psz_splitter, "none");
     free(psz_splitter);
+    
+    BOOL multipleVoutWindows = _voutWindows.count > 0;
+    BOOL videoWallpaper = var_InheritBool(getIntf(), "video-wallpaper") && !multipleVoutWindows;
 
     if (!videoWallpaper && !b_have_splitter && (var_InheritBool(getIntf(), "fullscreen") || _playerController.fullscreen)) {
         // this is not set when we start in fullscreen because of
@@ -364,6 +391,27 @@ int WindowOpen(vlc_window_t *p_wnd)
         var_SetBool(vlc_object_parent(p_wnd), "fullscreen", 1);
         [self setFullscreen:1 forWindow:p_wnd withAnimation:NO];
     }
+}
+
+- (VLCVoutView *)setupVoutForWindow:(vlc_window_t *)p_wnd
+      withProposedVideoViewPosition:(NSRect)videoViewPosition
+{
+    _playerController = [VLCMain sharedInstance].playlistController.playerController;
+    VLCVideoWindowCommon *newVideoWindow = [self setupVideoWindow];
+    VLCVoutView *voutView = newVideoWindow.videoView;
+
+    BOOL multipleVoutWindows = _voutWindows.count > 0;
+    BOOL videoWallpaper = var_InheritBool(getIntf(), "video-wallpaper") && !multipleVoutWindows;
+
+    // Avoid flashes if video will directly start in fullscreen
+    [NSAnimationContext beginGrouping];
+
+    if (!videoWallpaper) {
+        [self setupPositionAndSizeForVideoWindow:newVideoWindow atPosition:videoViewPosition];
+    }
+
+    [self setupVideoOutputForVideoWindow:newVideoWindow withVlcWindow:p_wnd];
+    [self setupFullscreenStartIfNeededForVout:voutView withVlcWindow:p_wnd];
 
     [NSAnimationContext endGrouping];
     return voutView;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b252236cff1c9cd0352f6fb5c7a128df8372368d...861594faef1530fe38805be0427960921ed3f3ba

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b252236cff1c9cd0352f6fb5c7a128df8372368d...861594faef1530fe38805be0427960921ed3f3ba
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list