]> git.sesse.net Git - vlc/commitdiff
macosx: move the resizing code to VLCVideoWindowCommon as its related to vout
authorDavid Fuhrmann <david.fuhrmann@googlemail.com>
Tue, 2 Oct 2012 19:05:26 +0000 (21:05 +0200)
committerDavid Fuhrmann <david.fuhrmann@googlemail.com>
Tue, 2 Oct 2012 19:13:33 +0000 (21:13 +0200)
This should fix resizing for all (one-)vout-window variants.
Furthermore, this fixes a small bug regarding aspect ratio enforcement.

modules/gui/macosx/MainWindow.h
modules/gui/macosx/MainWindow.m
modules/gui/macosx/VLCVoutWindowController.h
modules/gui/macosx/VLCVoutWindowController.m
modules/gui/macosx/Windows.h
modules/gui/macosx/Windows.m
modules/gui/macosx/intf.h
modules/gui/macosx/intf.m

index 56357652647247553edfee169c4dd26fa7ee7f1a..c4ff256bc8a9121fb7a7ed6e4bd3a16ec982e5cf 100644 (file)
@@ -98,7 +98,6 @@
     BOOL              b_fullscreen;
     BOOL              b_window_is_invisible;
     NSRecursiveLock * o_animation_lock;
-    NSSize nativeVideoSize;
 
     NSTimer *t_hide_mouse_timer;
 
 
 - (VLCVoutView *)setupVout:(vout_window_t *)p_wnd;
 - (void)setVideoplayEnabled;
-- (void)resizeWindow;
-- (void)setNativeVideoSize:(NSSize)size;
 
 - (void)hideMouseCursor:(NSTimer *)timer;
 - (void)recreateHideMouseTimer;
index 1330c4a688e50701eaf3b886db0b684bf0dce691..24a7495d4fcf2eefd5ece875ce21771a31145607 100644 (file)
@@ -54,7 +54,6 @@
 
 @end
 
-static const float f_min_video_height = 70.0;
 
 @implementation VLCMainWindow
 
@@ -521,9 +520,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
 - (void)someWindowWillClose:(NSNotification *)notification
 {
     id obj = [notification object];
-    BOOL b_is_mainwindow = [NSStringFromClass([obj class]) isEqualToString:@"VLCMainWindow"];
     
-    if (!b_is_mainwindow || (b_is_mainwindow && !b_nonembedded)) {
+    if ([obj class] == [VLCVideoWindowCommon class] || [obj class] == [VLCDetachedVideoWindow class] || ([obj class] == [VLCMainWindow class] && !b_nonembedded)) {
         if ([[VLCMain sharedInstance] activeVideoPlayback])
             [[VLCCoreInteraction sharedInstance] stop];
     }
@@ -533,40 +531,14 @@ static VLCMainWindow *_o_sharedInstance = nil;
 {
     if (config_GetInt(VLCIntf, "macosx-pause-minimized")) {
         id obj = [notification object];
-        BOOL b_is_mainwindow = [NSStringFromClass([obj class]) isEqualToString:@"VLCMainWindow"];
 
-        if (!b_is_mainwindow || (b_is_mainwindow && !b_nonembedded)) {
+        if ([obj class] == [VLCVideoWindowCommon class] || [obj class] == [VLCDetachedVideoWindow class] || ([obj class] == [VLCMainWindow class] && !b_nonembedded)) {
             if ([[VLCMain sharedInstance] activeVideoPlayback])
                 [[VLCCoreInteraction sharedInstance] pause];
         }
     }
 }
 
-- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
-{
-    id videoWindow = [o_video_view window];
-    if (![[VLCMain sharedInstance] activeVideoPlayback] || nativeVideoSize.width == 0. || nativeVideoSize.height == 0. || window != videoWindow)
-        return proposedFrameSize;
-
-    // needed when entering lion fullscreen mode
-    if (b_fullscreen)
-        return proposedFrameSize;
-
-    if ([[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]) {
-        NSRect videoWindowFrame = [videoWindow frame];
-        NSRect viewRect = [o_video_view convertRect:[o_video_view bounds] toView: nil];
-        NSRect contentRect = [videoWindow contentRectForFrameRect:videoWindowFrame];
-        float marginy = viewRect.origin.y + videoWindowFrame.size.height - contentRect.size.height;
-        float marginx = contentRect.size.width - viewRect.size.width;
-        if (b_dark_interface)// && b_video_deco)
-            marginy += [o_titlebar_view frame].size.height;
-
-        proposedFrameSize.height = (proposedFrameSize.width - marginx) * nativeVideoSize.height / nativeVideoSize.width + marginy;
-    }
-
-    return proposedFrameSize;
-}
-
 #pragma mark -
 #pragma mark Update interface and respond to foreign events
 - (void)showDropZone
@@ -762,7 +734,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
         BOOL b_no_video_deco_only = !b_video_wallpaper;
         o_new_video_window = [[VLCVideoWindowCommon alloc] initWithContentRect:window_rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
-        [o_new_video_window setDelegate:self];
+        [o_new_video_window setDelegate:o_new_video_window];
 
         if (b_video_wallpaper)
             [o_new_video_window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey) + 1];
@@ -800,7 +772,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
             o_new_video_window = [(VLCDetachedVideoWindow *)[o_controller window] retain];
             [o_controller release];
 
-            [o_new_video_window setDelegate: self];
+            [o_new_video_window setDelegate: o_new_video_window];
             [o_new_video_window setLevel:NSNormalWindowLevel];
             [o_new_video_window useOptimizedDrawing: YES];
             o_vout_view = [[o_new_video_window videoView] retain];
@@ -871,59 +843,6 @@ static VLCMainWindow *_o_sharedInstance = nil;
     }
 }
 
-- (void)resizeWindow
-{
-    if (b_fullscreen || (b_nativeFullscreenMode && [NSApp presentationOptions] & NSApplicationPresentationFullScreen))
-        return;
-
-    id o_videoWindow = [o_video_view window];
-    NSSize windowMinSize = [o_videoWindow minSize];
-    NSRect screenFrame = [[o_videoWindow screen] visibleFrame];
-
-    NSPoint topleftbase = NSMakePoint(0, [o_videoWindow frame].size.height);
-    NSPoint topleftscreen = [o_videoWindow convertBaseToScreen: topleftbase];
-
-    unsigned int i_width = nativeVideoSize.width;
-    unsigned int i_height = nativeVideoSize.height;
-    if (i_width < windowMinSize.width)
-        i_width = windowMinSize.width;
-    if (i_height < f_min_video_height)
-        i_height = f_min_video_height;
-
-    /* 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;
-
-    /* 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;
-
-    CGFloat right_screen_point = screenFrame.origin.x + screenFrame.size.width;
-    CGFloat right_window_point = new_frame.origin.x + new_frame.size.width;
-    if (right_window_point > right_screen_point)
-        new_frame.origin.x -= (right_window_point - right_screen_point);
-
-    [[o_videoWindow animator] setFrame:new_frame display:YES];
-}
-
-- (void)setNativeVideoSize:(NSSize)size
-{
-    nativeVideoSize = size;
-
-    if (var_InheritBool(VLCIntf, "macosx-video-autoresize") && !b_fullscreen && !var_InheritBool(VLCIntf, "video-wallpaper"))
-        [self performSelectorOnMainThread:@selector(resizeWindow) withObject:nil waitUntilDone:NO];
-}
 
 //  Called automatically if window's acceptsMouseMovedEvents property is true
 - (void)mouseMoved:(NSEvent *)theEvent
index c516029985a51ce37c7a0ceeb73e0a9dc6b43d11..f3d6d7dc3205b86803606fd54484ffbcc02d3178 100644 (file)
@@ -40,4 +40,6 @@
 - (void)updateWindowsControlsBarWithSelector:(SEL)aSel;
 - (void)updateWindowsUsingBlock:(void (^)(VLCVideoWindowCommon *o_window))windowUpdater;
 
+- (void)setNativeVideoSize:(NSSize)size forWindow:(vout_window_t *)p_wnd;
+
 @end
index e9ec8f9e6d9d60c3dd5fb01c3a473cfa94ae02b0..297dbc5ddb7d7c929d24a17000e56d498b88d5ae 100644 (file)
@@ -23,6 +23,7 @@
  *****************************************************************************/
 
 #import "VLCVoutWindowController.h"
+#import "intf.h"
 #import "Windows.h"
 
 @implementation VLCVoutWindowController
 - (void)removeVoutforDisplay:(NSValue *)o_key
 {
     VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:o_key];
+    if(!o_window) {
+        msg_Err(VLCIntf, "Cannot close nonexisting window");
+        return;
+    }
 
     if (![NSStringFromClass([o_window class]) isEqualToString:@"VLCMainWindow"]) {
         [o_window orderOut:self];
     }];
 }
 
+- (void)setNativeVideoSize:(NSSize)size forWindow:(vout_window_t *)p_wnd
+{
+    VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]];
+    if(!o_window) {
+        msg_Err(VLCIntf, "Cannot set size for nonexisting window");
+        return;
+    }
+
+    [o_window setNativeVideoSize:size];
+}
+
 @end
\ No newline at end of file
index e9fa3752ee17f5040b87ec38dd63c6bf1d727acf..58aac2784349dc91d51e7279ac110718f6370c17 100644 (file)
@@ -57,6 +57,9 @@
 
 @end
 
+
+static const float f_min_video_height = 70.0;
+
 @class VLCVoutView;
 @class VLCControlsBarCommon;
 
@@ -66,7 +69,7 @@
  *  Common code for main window, detached window and extra video window
  *****************************************************************************/
 
-@interface VLCVideoWindowCommon : VLCWindow
+@interface VLCVideoWindowCommon : VLCWindow <NSWindowDelegate>
 {
     NSRect previousSavedFrame;
     BOOL b_dark_interface;
     IBOutlet VLCVoutView *o_video_view;
 
     IBOutlet VLCControlsBarCommon *o_controls_bar;
+
+    NSSize nativeVideoSize;
 }
 
 @property (nonatomic, assign) VLCVoutView* videoView;
 @property (readonly) VLCControlsBarCommon* controlsBar;
 
+- (void)resizeWindow;
+- (void)setNativeVideoSize:(NSSize)size;
 
 - (void)setTitle:(NSString *)title;
 
index 141cde0ce9c74f3515f76174fec0af6908800e6f..25149690cc505e3af3167babbd2950c0c416c92e 100644 (file)
     [self setFrame: maxRect display: YES animate: YES];
 }
 
+#pragma mark -
+#pragma mark Video window resizing logic
+
+- (void)resizeWindow
+{
+    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;
+    if (i_width < windowMinSize.width)
+        i_width = windowMinSize.width;
+    if (i_height < f_min_video_height)
+        i_height = f_min_video_height;
+
+    /* Calculate the window's new size */
+    NSRect new_frame;
+    new_frame.size.width = [self frame].size.width - [o_video_view frame].size.width + i_width;
+    new_frame.size.height = [self 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;
+
+    /* 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;
+
+    CGFloat right_screen_point = screenFrame.origin.x + screenFrame.size.width;
+    CGFloat right_window_point = new_frame.origin.x + new_frame.size.width;
+    if (right_window_point > right_screen_point)
+        new_frame.origin.x -= (right_window_point - right_screen_point);
+
+    [[self animator] setFrame:new_frame display:YES];
+}
+
+- (void)setNativeVideoSize:(NSSize)size
+{
+    nativeVideoSize = size;
+
+    if (var_InheritBool(VLCIntf, "macosx-video-autoresize") && !var_InheritBool(VLCIntf, "video-wallpaper"))
+        [self resizeWindow];
+}
+
+- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
+{
+    if (![[VLCMain sharedInstance] activeVideoPlayback] || nativeVideoSize.width == 0. || nativeVideoSize.height == 0. || window != self)
+        return proposedFrameSize;
+
+    // needed when entering lion fullscreen mode
+    if ([[VLCMainWindow sharedInstance] fullscreen])
+        return proposedFrameSize;
+
+    if ([[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]) {
+        NSRect videoWindowFrame = [self frame];
+        NSRect viewRect = [o_video_view convertRect:[o_video_view bounds] toView: nil];
+        NSRect contentRect = [self contentRectForFrameRect:videoWindowFrame];
+        float marginy = viewRect.origin.y + videoWindowFrame.size.height - contentRect.size.height;
+        float marginx = contentRect.size.width - viewRect.size.width;
+        if (o_titlebar_view && b_dark_interface)
+            marginy += [o_titlebar_view frame].size.height;
+
+        proposedFrameSize.height = (proposedFrameSize.width - marginx) * nativeVideoSize.height / nativeVideoSize.width + marginy;
+    }
+
+    return proposedFrameSize;
+}
+
 #pragma mark -
 #pragma mark Accessibility stuff
 
index 866204ae7424312722453e2b013234e6e6efef64..ceb9b9c7934821b9499a968aa3c0b7782ed8c2f1 100644 (file)
@@ -165,7 +165,6 @@ struct intf_sys_t
 - (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;
-- (void)setNativeVideoSize:(NSSize)size;
 - (id)coreDialogProvider;
 - (id)eyeTVController;
 - (id)appleRemoteController;
index a93fed97feb8d500b65d1c46ed05d94f6447e874..d7bdbcdb22e05a73b1a9124ccf47a69451c54303 100644 (file)
@@ -142,7 +142,6 @@ int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
     int i_y = cfg->y;
     unsigned i_width = cfg->width;
     unsigned i_height = cfg->height;
-    NSLog(@"window open with x%i, y %i, wi %i, hei %i", i_x, i_y, i_width, i_height);
     p_wnd->handle.nsobject = [[VLCMain sharedInstance] getVideoViewAtPositionX: &i_x Y: &i_y withWidth: &i_width andHeight: &i_height forWindow: p_wnd];
 
     if (!p_wnd->handle.nsobject) {
@@ -151,7 +150,18 @@ int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
         return VLC_EGENERIC;
     }
 
-    [[VLCMain sharedInstance] setNativeVideoSize:NSMakeSize(cfg->width, cfg->height)];
+    // 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];
+
     [[VLCMain sharedInstance] setActiveVideoPlayback: YES];
     p_wnd->control = WindowControl;
     p_wnd->sys = (vout_window_sys_t *)VLCIntf;
@@ -170,9 +180,22 @@ static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
         }
         case VOUT_WINDOW_SET_SIZE:
         {
+            NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+
             unsigned int i_width  = va_arg(args, unsigned int);
             unsigned int i_height = va_arg(args, unsigned int);
-            [[VLCMain sharedInstance] setNativeVideoSize:NSMakeSize(i_width, i_height)];
+
+            NSSize newSize = NSMakeSize(i_width, i_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];
+
+            [o_pool release];
             return VLC_SUCCESS;
         }
         case VOUT_WINDOW_SET_FULLSCREEN:
@@ -1411,11 +1434,6 @@ static VLCMain *_o_sharedMainInstance = nil;
     }
 }
 
-- (void)setNativeVideoSize:(NSSize)size
-{
-    [o_mainwindow setNativeVideoSize:size];
-}
-
 #pragma mark -
 #pragma mark Other objects getters