[vlc-commits] macosx: move resize code from vout to macosx module

David Fuhrmann git at videolan.org
Sun Apr 15 22:19:56 CEST 2012


vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Sun Apr 15 20:48:11 2012 +0200| [12b4d49591f5843bdaaac3d0c2f45193c65bdc62] | committer: David Fuhrmann

macosx: move resize code from vout to macosx module

Also, this commit reenables resize to native video size, if video starts.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=12b4d49591f5843bdaaac3d0c2f45193c65bdc62
---

 modules/gui/macosx/MainWindow.m |   57 +++++++++++++++++++++++-----------
 modules/video_output/macosx.m   |   64 +-------------------------------------
 2 files changed, 41 insertions(+), 80 deletions(-)

diff --git a/modules/gui/macosx/MainWindow.m b/modules/gui/macosx/MainWindow.m
index 0e4a1db..18ea11c 100644
--- a/modules/gui/macosx/MainWindow.m
+++ b/modules/gui/macosx/MainWindow.m
@@ -1498,33 +1498,53 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (void)resizeWindow
 {
-    if ( b_fullscreen || (b_nativeFullscreenMode && [NSApp presentationOptions] & NSApplicationPresentationFullScreen ))
+    if( b_fullscreen || ( b_nativeFullscreenMode && [NSApp presentationOptions] & NSApplicationPresentationFullScreen ) )
         return;
 
-    NSPoint topleftbase = NSMakePoint(0, [self frame].size.height);
-    NSPoint topleftscreen = [self convertBaseToScreen: topleftbase];
+    id o_videoWindow = b_nonembedded ? o_detached_video_window : self;
+    NSSize windowMinSize = [o_videoWindow minSize];
+    NSRect screenFrame = [[o_videoWindow screen] visibleFrame];
 
-    /* Calculate the window's new size */
-    float w = [self frame].size.width  - [o_video_view frame].size.width
-        + nativeVideoSize.width;
-    float h = [self frame].size.height - [o_video_view frame].size.height
-        + nativeVideoSize.height;
+    NSPoint topleftbase = NSMakePoint( 0, [o_videoWindow frame].size.height );
+    NSPoint topleftscreen = [o_videoWindow convertBaseToScreen: topleftbase];
 
-    if (b_dark_interface)
-        h += [o_titlebar_view frame].size.height;
+    unsigned int i_width = nativeVideoSize.width;
+    unsigned int i_height = nativeVideoSize.height;
+    if (i_width < windowMinSize.width)
+        i_width = windowMinSize.width;
+    if (i_height < windowMinSize.height)
+        i_height = windowMinSize.height;
 
-    NSRect new_frame = NSMakeRect(topleftscreen.x, topleftscreen.y - h, w, h);
+    /* Calculate the window's new size */
+    NSRect new_frame;
+    new_frame.size.width = [o_videoWindow frame].size.width - [o_video_view frame].size.width + i_width;
+    new_frame.size.height = [o_videoWindow frame].size.height - [o_video_view frame].size.height + i_height;
+    new_frame.origin.x = topleftscreen.x;
+    new_frame.origin.y = topleftscreen.y - new_frame.size.height;
 
-    [[self animator] setFrame:new_frame display:YES];
+    /* make sure the window doesn't exceed the screen size the window is on */
+    if( new_frame.size.width > screenFrame.size.width )
+    {
+        new_frame.size.width = screenFrame.size.width;
+        new_frame.origin.x = screenFrame.origin.x;
+    }
+    if( new_frame.size.height > screenFrame.size.height )
+    {
+        new_frame.size.height = screenFrame.size.height;
+        new_frame.origin.y = screenFrame.origin.y;
+    }
+    if( new_frame.origin.y < screenFrame.origin.y )
+        new_frame.origin.y = screenFrame.origin.y;
+
+    [[o_videoWindow animator] setFrame:new_frame display:YES];
 }
 
 - (void)setNativeVideoSize:(NSSize)size
 {
-    if (size.width != nativeVideoSize.width || size.height != nativeVideoSize.height )
-    {
-        nativeVideoSize = size;
-        [self resizeWindow];
-    }
+    nativeVideoSize = size;
+
+    if( config_GetInt( VLCIntf, "macosx-video-autoresize" ) && !b_fullscreen )
+        [self performSelectorOnMainThread:@selector(resizeWindow) withObject:nil waitUntilDone:NO];
 }
 
 //  Called automatically if window's acceptsMouseMovedEvents property is true
@@ -1789,7 +1809,6 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
     [self lockFullscreenAnimation];
 
-    b_fullscreen = NO;
     [o_fullscreen_btn setState: NO];
     [o_detached_fullscreen_btn setState: NO];
 
@@ -1911,6 +1930,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (void)hasEndedFullscreen
 {
+    b_fullscreen = NO;
+
     /* This function is private and should be only triggered at the end of the fullscreen change animation */
     /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
     NSDisableScreenUpdates();
diff --git a/modules/video_output/macosx.m b/modules/video_output/macosx.m
index b0508aa..26849e0 100644
--- a/modules/video_output/macosx.m
+++ b/modules/video_output/macosx.m
@@ -337,18 +337,12 @@ static int Control (vout_display_t *vd, int query, va_list ap)
                 return VLC_EGENERIC;
 
             NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
-            NSPoint topleftbase;
-            NSPoint topleftscreen;
-            NSRect new_frame;
 
             id o_window = [sys->glView window];
             if (!o_window)
                 return VLC_SUCCESS; // this is okay, since the event will occur again when we have a window
-            NSRect windowFrame = [o_window frame];
-            NSRect glViewFrame = [sys->glView frame];
-            NSRect screenFrame = [[o_window screen] visibleFrame];
-            NSSize windowMinSize = [o_window minSize];
 
+            NSSize windowMinSize = [o_window minSize];
             int i_width = 0;
             int i_height = 0;
 
@@ -358,10 +352,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
 
             vout_display_place_t place;
 
-            topleftbase.x = 0;
-            topleftbase.y = windowFrame.size.height;
-            topleftscreen = [o_window convertBaseToScreen: topleftbase];
-
             if (query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT || query == VOUT_DISPLAY_CHANGE_SOURCE_CROP)
             {
                 source = (const video_format_t *)va_arg (ap, const video_format_t *);
@@ -390,8 +380,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
                 cfg_tmp.display.height = windowMinSize.height;
 
             vout_display_PlacePicture (&place, source, &cfg_tmp, false);
-            i_width = place.width;
-            i_height = place.height;
 
             if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP || query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT)
             {
@@ -425,44 +413,13 @@ static int Control (vout_display_t *vd, int query, va_list ap)
                This has the positive side effect that we avoid erratic sizing as we animate every resize. */
             if (query != VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
             {
-                glViewport (place.x, place.y, i_width, i_height);
+                glViewport (place.x, place.y, place.width, place.height);
             }
 
             // this should not be needed, but currently it improves crop somehow, when we are in fullscreen
             if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP)
                 [sys->glView performSelectorOnMainThread:@selector(reshapeView:) withObject:nil waitUntilDone:NO];
 
-            /* Calculate the window's new size, if it is larger than our minimal size */
-            if (i_width < windowMinSize.width)
-                i_width = windowMinSize.width;
-            if (i_height < windowMinSize.height)
-                i_height = windowMinSize.height;
-
-            if (config_GetInt (vd, "macosx-video-autoresize") && query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE && is_forced && 
-                (i_height != glViewFrame.size.height || i_width != glViewFrame.size.width))
-            {
-                new_frame.size.width = windowFrame.size.width - glViewFrame.size.width + i_width;
-                new_frame.size.height = windowFrame.size.height - glViewFrame.size.height + i_height;
-
-                new_frame.origin.x = topleftscreen.x;
-                new_frame.origin.y = topleftscreen.y - new_frame.size.height;
-
-                /* make sure the window doesn't exceed the screen size the window is on */
-                if( new_frame.size.width > screenFrame.size.width )
-                {
-                    new_frame.size.width = screenFrame.size.width;
-                    new_frame.origin.x = screenFrame.origin.x;
-                }
-                if( new_frame.size.height > screenFrame.size.height )
-                {
-                    new_frame.size.height = screenFrame.size.height;
-                    new_frame.origin.y = screenFrame.origin.y;
-                }
-                if( new_frame.origin.y < screenFrame.origin.y )
-                    new_frame.origin.y = screenFrame.origin.y;
-
-                [sys->glView performSelectorOnMainThread:@selector(setWindowFrameWithValue:) withObject:[NSValue valueWithRect:new_frame] waitUntilDone:NO];
-            }
             [o_pool release];
             return VLC_SUCCESS;
         }
@@ -581,23 +538,6 @@ static void OpenglSwap(vlc_gl_t *gl)
 }
 
 /**
- * Gets called by Control() to make sure that we're performing on the main thread
- */
-- (void)setWindowFrameWithValue:(NSValue *)value
-{
-    id window = [self window];
-    NSRect frame = [value rectValue];
-
-    if ([window respondsToSelector:@selector(isFullscreen)])
-    {
-        if (!(BOOL)[[self window] isFullscreen])
-            [[self window] setFrame:frame display:YES animate:YES];
-    }
-    else
-        [[self window] setFrame:frame display:YES animate:YES];
-}
-
-/**
  * Gets called by the Close and Open methods.
  * (Non main thread).
  */



More information about the vlc-commits mailing list