[vlc-commits] macosx: simplify vout window instantiation

David Fuhrmann git at videolan.org
Sat Nov 10 21:57:44 CET 2012


vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Sat Nov 10 21:16:20 2012 +0100| [354dcd7df98f6c62105420db0062ef8a2188f9df] | committer: David Fuhrmann

macosx: simplify vout window instantiation

This removes unused pointering. Furthermore, for nonembedded windows
the video size is set directly to avoid strange resizing after window
creation.

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

 modules/gui/macosx/VLCVoutWindowController.h |    2 +-
 modules/gui/macosx/VLCVoutWindowController.m |   13 ++++-
 modules/gui/macosx/Windows.h                 |    2 +
 modules/gui/macosx/Windows.m                 |   20 +++++---
 modules/gui/macosx/intf.h                    |    1 -
 modules/gui/macosx/intf.m                    |   67 ++++++++------------------
 6 files changed, 48 insertions(+), 57 deletions(-)

diff --git a/modules/gui/macosx/VLCVoutWindowController.h b/modules/gui/macosx/VLCVoutWindowController.h
index 150e6b3..8a81822 100644
--- a/modules/gui/macosx/VLCVoutWindowController.h
+++ b/modules/gui/macosx/VLCVoutWindowController.h
@@ -35,7 +35,7 @@
     NSMutableDictionary *o_vout_dict;
 }
 
-- (VLCVoutView *)setupVout:(vout_window_t *)p_wnd;
+- (VLCVoutView *)setupVoutForWindow:(vout_window_t *)p_wnd withProposedVideoViewPosition:(NSRect)videoViewPosition;
 - (void)removeVoutforDisplay:(NSValue *)o_key;
 
 - (void)updateWindowsControlsBarWithSelector:(SEL)aSel;
diff --git a/modules/gui/macosx/VLCVoutWindowController.m b/modules/gui/macosx/VLCVoutWindowController.m
index 6e3ea1c..0ba8612 100644
--- a/modules/gui/macosx/VLCVoutWindowController.m
+++ b/modules/gui/macosx/VLCVoutWindowController.m
@@ -47,7 +47,7 @@
 }
 
 
-- (VLCVoutView *)setupVout:(vout_window_t *)p_wnd
+- (VLCVoutView *)setupVoutForWindow:(vout_window_t *)p_wnd withProposedVideoViewPosition:(NSRect)videoViewPosition
 {
     BOOL b_nonembedded = NO;
     BOOL b_nativeFullscreenMode = [[VLCMain sharedInstance] nativeFullscreenMode];
@@ -57,6 +57,7 @@
     VLCVoutView *o_vout_view;
     VLCVideoWindowCommon *o_new_video_window;
 
+
     // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
     if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
         // b_video_wallpaper is priorized over !b_video_deco
@@ -126,6 +127,15 @@
     }
 
     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];
+            [o_new_video_window setFrame:window_rect display:YES];
+        }
+        [o_new_video_window setNativeVideoSize:videoViewSize];
+
         [o_new_video_window makeKeyAndOrderFront: self];
 
         vout_thread_t *p_vout = getVout();
@@ -137,6 +147,7 @@
             vlc_object_release(p_vout);
         }
     }
+
     [o_new_video_window setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
 
     if (!b_multiple_vout_windows)
diff --git a/modules/gui/macosx/Windows.h b/modules/gui/macosx/Windows.h
index bdc2de7..81c458f 100644
--- a/modules/gui/macosx/Windows.h
+++ b/modules/gui/macosx/Windows.h
@@ -104,6 +104,8 @@ static const float f_min_video_height = 70.0;
 
 - (void)resizeWindow;
 - (void)setNativeVideoSize:(NSSize)size;
+- (NSRect)getWindowRectForProposedVideoViewSize:(NSSize)size;
+
 
 - (void)setTitle:(NSString *)title;
 
diff --git a/modules/gui/macosx/Windows.m b/modules/gui/macosx/Windows.m
index d710a3a..10332e7 100644
--- a/modules/gui/macosx/Windows.m
+++ b/modules/gui/macosx/Windows.m
@@ -422,19 +422,16 @@
 #pragma mark -
 #pragma mark Video window resizing logic
 
-- (void)resizeWindow
+- (NSRect)getWindowRectForProposedVideoViewSize:(NSSize)size
 {
-    if ([[VLCMainWindow sharedInstance] fullscreen])
-        return;
-
     NSSize windowMinSize = [self minSize];
     NSRect screenFrame = [[self screen] visibleFrame];
 
     NSPoint topleftbase = NSMakePoint(0, [self frame].size.height);
     NSPoint topleftscreen = [self convertBaseToScreen: topleftbase];
 
-    unsigned int i_width = nativeVideoSize.width;
-    unsigned int i_height = nativeVideoSize.height;
+    unsigned int i_width = size.width;
+    unsigned int i_height = size.height;
     if (i_width < windowMinSize.width)
         i_width = windowMinSize.width;
     if (i_height < f_min_video_height)
@@ -464,7 +461,16 @@
     if (right_window_point > right_screen_point)
         new_frame.origin.x -= (right_window_point - right_screen_point);
 
-    [[self animator] setFrame:new_frame display:YES];
+    return new_frame;
+}
+
+- (void)resizeWindow
+{
+    if ([[VLCMainWindow sharedInstance] fullscreen])
+        return;
+
+    NSRect window_rect = [self getWindowRectForProposedVideoViewSize:nativeVideoSize];
+    [[self animator] setFrame:window_rect display:YES];
 }
 
 - (void)setNativeVideoSize:(NSSize)size
diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h
index 897b0bd..ccb2624 100644
--- a/modules/gui/macosx/intf.h
+++ b/modules/gui/macosx/intf.h
@@ -166,7 +166,6 @@ struct intf_sys_t
 - (id)playlist;
 - (id)info;
 - (id)wizard;
-- (id)getVideoViewAtPositionX: (int *)pi_x Y: (int *)pi_y withWidth: (unsigned int*)pi_width andHeight: (unsigned int*)pi_height forWindow:(vout_window_t *)p_wnd;
 - (id)coreDialogProvider;
 - (id)eyeTVController;
 - (id)appleRemoteController;
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 18c8fe2..bdf3181 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -137,29 +137,31 @@ int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
         return VLC_EGENERIC;
     }
 
-    int i_x = cfg->x;
-    int i_y = cfg->y;
-    unsigned i_width = cfg->width;
-    unsigned i_height = cfg->height;
-    p_wnd->handle.nsobject = [[VLCMain sharedInstance] getVideoViewAtPositionX: &i_x Y: &i_y withWidth: &i_width andHeight: &i_height forWindow: p_wnd];
+    NSRect proposedVideoViewPosition = NSMakeRect(cfg->x, cfg->y, cfg->width, cfg->height);
 
-    if (!p_wnd->handle.nsobject) {
+    VLCVoutWindowController *o_vout_controller = [[VLCMain sharedInstance] voutController];
+    SEL sel = @selector(setupVoutForWindow:withProposedVideoViewPosition:);
+    NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
+    [inv setTarget:o_vout_controller];
+    [inv setSelector:sel];
+    [inv setArgument:&p_wnd atIndex:2]; // starting at 2!
+    [inv setArgument:&proposedVideoViewPosition atIndex:3];
+
+    [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
+                       waitUntilDone:YES];
+
+    VLCVoutView *videoView = nil;
+    [inv getReturnValue:&videoView];
+
+    if (!videoView) {
         msg_Err(p_wnd, "got no video view from the interface");
         [o_pool release];
         return VLC_EGENERIC;
     }
 
-    // TODO: this seems to be strange. Why not just allocating in the right size?
-    // This could avoid strange resize-animations...
-    NSSize newSize = NSMakeSize(cfg->width, cfg->height);
-    SEL sel = @selector(setNativeVideoSize:forWindow:);
-    NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[[VLCMain sharedInstance] voutController] methodSignatureForSelector:sel]];
-    [inv setTarget:[[VLCMain sharedInstance] voutController]];
-    [inv setSelector:sel];
-    [inv setArgument:&newSize atIndex:2]; // starting at 2!
-    [inv setArgument:&p_wnd atIndex:3];
-    [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
-                       waitUntilDone:NO];
+    msg_Dbg(VLCIntf, "returning videoview with proposed position x=%i, y=%i, width=%i, height=%i", cfg->x, cfg->y, cfg->width, cfg->height);
+    p_wnd->handle.nsobject = videoView;
+
 
     // TODO: find a cleaner way for "start in fullscreen"
     if (var_GetBool(pl_Get(VLCIntf), "fullscreen")) {
@@ -177,7 +179,7 @@ int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
 
     [[VLCMain sharedInstance] setActiveVideoPlayback: YES];
     p_wnd->control = WindowControl;
-    p_wnd->sys = (vout_window_sys_t *)VLCIntf;
+
     [o_pool release];
     return VLC_SUCCESS;
 }
@@ -225,8 +227,6 @@ static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
             [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
                                waitUntilDone:NO];
 
-
-            //[[VLCMain sharedInstance] performSelectorOnMainThread:@selector(fullscreenChanged:) withObject:[NSValue valueWithPointer:p_wnd] waitUntilDone:NO];
             [o_pool release];
             return VLC_SUCCESS;
         }
@@ -1550,33 +1550,6 @@ static VLCMain *_o_sharedMainInstance = nil;
     return o_wizard;
 }
 
-- (id)getVideoViewAtPositionX: (int *)pi_x Y: (int *)pi_y withWidth: (unsigned int*)pi_width andHeight: (unsigned int*)pi_height forWindow:(vout_window_t *)p_wnd
-{
-    SEL sel = @selector(setupVout:);
-    NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
-    [inv setTarget:o_vout_controller];
-    [inv setSelector:sel];
-    [inv setArgument:&p_wnd atIndex:2]; // starting at 2!
-
-    [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
-                       waitUntilDone:YES];
-
-    VLCVoutView *videoView;
-    [inv getReturnValue:&videoView];
-
-    NSRect videoRect = [videoView frame];
-    int i_x = (int)videoRect.origin.x;
-    int i_y = (int)videoRect.origin.y;
-    unsigned int i_width = (int)videoRect.size.width;
-    unsigned int i_height = (int)videoRect.size.height;
-    pi_x = &i_x;
-    pi_y = &i_y;
-    pi_width = &i_width;
-    pi_height = &i_height;
-    msg_Dbg(VLCIntf, "returning videoview with x=%i, y=%i, width=%i, height=%i", i_x, i_y, i_width, i_height);
-    return videoView;
-}
-
 - (id)coreDialogProvider
 {
     if (o_coredialogs)



More information about the vlc-commits mailing list