macosx: move the resizing code to VLCVideoWindowCommon as its related to vout

This should fix resizing for all (one-)vout-window variants.
Furthermore, this fixes a small bug regarding aspect ratio enforcement.
This commit is contained in:
David Fuhrmann 2012-10-02 21:05:26 +02:00
parent 0b3c20521a
commit ebfdeea1f9
8 changed files with 136 additions and 98 deletions

View File

@ -98,7 +98,6 @@
BOOL b_fullscreen;
BOOL b_window_is_invisible;
NSRecursiveLock * o_animation_lock;
NSSize nativeVideoSize;
NSTimer *t_hide_mouse_timer;
@ -138,8 +137,6 @@
- (VLCVoutView *)setupVout:(vout_window_t *)p_wnd;
- (void)setVideoplayEnabled;
- (void)resizeWindow;
- (void)setNativeVideoSize:(NSSize)size;
- (void)hideMouseCursor:(NSTimer *)timer;
- (void)recreateHideMouseTimer;

View 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

View 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

View File

@ -23,6 +23,7 @@
*****************************************************************************/
#import "VLCVoutWindowController.h"
#import "intf.h"
#import "Windows.h"
@implementation VLCVoutWindowController
@ -48,6 +49,10 @@
- (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];
@ -72,4 +77,15 @@
}];
}
- (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

View 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;
@ -75,11 +78,15 @@
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;

View File

@ -399,6 +399,86 @@
[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

View 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;

View 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