X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fmacosx%2Fvout.m;h=224ed25f48363f64ebd811760ee1966d488b9b16;hb=46c93c9cc984b99142b6e7321c8f5c4c8c4e65bb;hp=dfc756be681df0097963482ddabab013a256e051;hpb=8840aa586a3fa553dcc7a6c5b4b6edf9e5743644;p=vlc diff --git a/modules/gui/macosx/vout.m b/modules/gui/macosx/vout.m index dfc756be68..224ed25f48 100644 --- a/modules/gui/macosx/vout.m +++ b/modules/gui/macosx/vout.m @@ -1,7 +1,7 @@ /***************************************************************************** * vout.m: MacOS X video output module ***************************************************************************** - * Copyright (C) 2001-2008 the VideoLAN team + * Copyright (C) 2001-2009 the VideoLAN team * $Id$ * * Authors: Colin Delacroix @@ -34,8 +34,8 @@ #include /* free() */ #include -/* BeginFullScreen, EndFullScreen */ -#include +/* prevent system sleep */ +#import #include @@ -76,7 +76,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, return self; } -- (id)getEmbeddedVout +- (id)embeddedVout { unsigned int i; @@ -118,19 +118,24 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, { NSLog( @"We were not given a VLCVoutWindow" ); }*/ - return ([self getViewForWindow: o_window] == nil ? NO : YES ); + return ([self viewForWindow: o_window] == nil ? NO : YES ); } -- (id)getViewForWindow: (id)o_window +- (id)viewForWindow: (id)o_window { - id o_enumerator = [o_embedded_array objectEnumerator]; - id o_current_embedded; - - while( (o_current_embedded = [o_enumerator nextObject]) ) + if( o_embedded_array != nil ) { - if( [o_current_embedded getWindow] == o_window ) + id o_enumerator = [o_embedded_array objectEnumerator]; + id o_current_embedded; + if( o_window != nil ) { - return o_current_embedded; + while( (o_current_embedded = [o_enumerator nextObject]) ) + { + if( [o_current_embedded voutWindow] == o_window ) + { + return o_current_embedded; + } + } } } return nil; @@ -145,7 +150,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, - (id)initWithFrame: (NSRect)frameRect { - [super initWithFrame: frameRect]; + self = [super initWithFrame: frameRect]; p_vout = NULL; o_view = nil; s_frame = &frameRect; @@ -173,7 +178,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, return NO; } - p_real_vout = [VLCVoutView getRealVout: p_vout]; + p_real_vout = [VLCVoutView realVout: p_vout]; /* Get the pref value when this is the first time, otherwise retrieve the device from the top level video-device var */ if( var_Type( p_real_vout->p_libvlc, "video-device" ) == 0 ) @@ -257,10 +262,10 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, - (void)closeVout { - [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeOut]; + [[[[VLCMain sharedInstance] controls] fspanel] fadeOut]; /* Make sure we don't see a white flash */ - [[self window] disableScreenUpdatesUntilFlush]; + [[self voutWindow] disableScreenUpdatesUntilFlush]; [o_view removeFromSuperview]; o_view = nil; p_vout = NULL; @@ -274,35 +279,31 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, NSString * o_title = nil; NSMutableString * o_mrl = nil; input_thread_t * p_input; + char * psz_title; - if( p_vout == NULL ) - { - return; - } + if( !p_vout ) return; p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT ); - if( p_input == NULL ) - { - return; - } + if( !p_input ) return; + + input_item_t * p_item = input_GetItem( p_input ); - char *psz_nowPlaying = input_item_GetNowPlaying ( input_GetItem( p_input ) ); - char *psz_name = input_item_GetName( input_GetItem( p_input ) ); - char *psz_uri = input_item_GetURI( input_GetItem( p_input ) ); - if( psz_nowPlaying != NULL ) - o_title = [NSString stringWithUTF8String: psz_nowPlaying]; - else if( psz_name != NULL ) - o_title = [NSString stringWithUTF8String: psz_name]; + psz_title = input_item_GetNowPlaying ( p_item ); + if( !psz_title ) + psz_title = input_item_GetName( p_item ); - if( psz_uri != NULL ) + if( psz_title ) + o_title = [NSString stringWithUTF8String: psz_title]; + + char *psz_uri = input_item_GetURI( p_item ); + if( psz_uri ) o_mrl = [NSMutableString stringWithUTF8String: psz_uri]; - FREENULL( psz_nowPlaying ); - FREENULL( psz_name ); - FREENULL( psz_uri ); + free( psz_title ); + free( psz_uri ); - if( o_title == nil ) + if( !o_title ) o_title = o_mrl; if( o_mrl != nil ) @@ -334,7 +335,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, vlc_object_release( p_input ); } - - (void)setOnTop:(BOOL)b_on_top { if( b_on_top ) @@ -347,36 +347,44 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, } } -- (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate +- (NSSize)voutSizeForFactor: (float)factor { - NSSize newsize; int i_corrected_height, i_corrected_width; - NSPoint topleftbase; - NSPoint topleftscreen; + NSSize newsize; + + if( p_vout->render.i_height * p_vout->render.i_aspect > + p_vout->render.i_width * VOUT_ASPECT_FACTOR ) + { + i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect / + VOUT_ASPECT_FACTOR; + newsize.width = (int) ( i_corrected_width * factor ); + newsize.height = (int) ( p_vout->render.i_height * factor ); + } + else + { + i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR / + p_vout->render.i_aspect; + newsize.width = (int) ( p_vout->render.i_width * factor ); + newsize.height = (int) ( i_corrected_height * factor ); + } + + return newsize; +} +- (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate +{ if ( !p_vout->b_fullscreen ) { + NSSize newsize; + NSPoint topleftbase; + NSPoint topleftscreen; NSView *mainView; NSRect new_frame; topleftbase.x = 0; topleftbase.y = [o_window frame].size.height; topleftscreen = [o_window convertBaseToScreen: topleftbase]; - if( p_vout->render.i_height * p_vout->render.i_aspect > - p_vout->render.i_width * VOUT_ASPECT_FACTOR ) - { - i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect / - VOUT_ASPECT_FACTOR; - newsize.width = (int) ( i_corrected_width * factor ); - newsize.height = (int) ( p_vout->render.i_height * factor ); - } - else - { - i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR / - p_vout->render.i_aspect; - newsize.width = (int) ( p_vout->render.i_width * factor ); - newsize.height = (int) ( i_corrected_height * factor ); - } + newsize = [self voutSizeForFactor:factor]; /* In fullscreen mode we need to use a view that is different from * ourselves, with the VLCEmbeddedWindow */ @@ -394,8 +402,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, new_frame.origin.x = topleftscreen.x; new_frame.origin.y = topleftscreen.y - new_frame.size.height; - [o_window setFrame: new_frame display: animate animate: animate]; - + [o_window setFrame:new_frame display:animate animate:animate]; p_vout->i_changes |= VOUT_SIZE_CHANGE; } } @@ -435,27 +442,28 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, - (void)snapshot { - vout_Control( p_real_vout, VOUT_SNAPSHOT ); + var_TriggerCallback( p_real_vout, "video-snapshot" ); } - (void)manage { /* Disable Screensaver, when we're playing something, but allow it on pause */ - if( !VLCIntf || !VLCIntf->p_sys || !VLCIntf->p_sys->i_play_status ) + if( !VLCIntf || !VLCIntf->p_sys ) return; + UInt8 UsrActivity; if( VLCIntf->p_sys->i_play_status == PLAYING_S ) UpdateSystemActivity( UsrActivity ); } -- (id)getWindow +- (id)voutWindow { return o_window; } - (void)scrollWheel:(NSEvent *)theEvent { - VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls]; + VLCControls * o_controls = (VLCControls *)[[NSApp delegate] controls]; [o_controls scrollWheel: theEvent]; } @@ -477,7 +485,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, if( i_pressed_modifiers & NSCommandKeyMask ) val.i_int |= KEY_MODIFIER_COMMAND; - key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0]; + key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0]; if( key ) { @@ -489,28 +497,23 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, [self toggleFullscreen]; } } - else if ( key == ' ' ) - { - vlc_value_t val; - val.i_int = config_GetInt( p_vout, "key-play-pause" ); - var_Set( p_vout->p_libvlc, "key-pressed", val ); - } - else + else if ( p_vout ) { - val.i_int |= CocoaKeyToVLC( key ); + if( key == ' ') + val.i_int = config_GetInt( p_vout, "key-play-pause" ); + else + val.i_int |= (int)CocoaKeyToVLC( key ); var_Set( p_vout->p_libvlc, "key-pressed", val ); } + else NSLog( @"Could not send keyevent to VLC core" ); } else - { [super keyDown: o_event]; - } } - (void)mouseDown:(NSEvent *)o_event { vlc_value_t val; - if( p_vout ) { if( ( [o_event type] == NSLeftMouseDown ) && @@ -534,7 +537,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ( [o_event modifierFlags] & NSControlKeyMask ) ) ) { msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" ); - [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]]; + [NSMenu popUpContextMenu: [[VLCMain sharedInstance] voutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] controls] voutView]]; } } @@ -560,7 +563,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, if( p_vout && [o_event type] == NSRightMouseDown ) { msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" ); - [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]]; + [NSMenu popUpContextMenu: [[VLCMain sharedInstance] voutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] controls] voutView]]; } [super mouseDown: o_event]; @@ -572,9 +575,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, if( p_vout && [o_event type] == NSLeftMouseUp ) { - vlc_value_t b_val; - b_val.b_bool = true; - var_Set( p_vout, "mouse-clicked", b_val ); + var_SetBool( p_vout, "mouse-clicked", true ); var_Get( p_vout, "mouse-button-down", &val ); val.i_int &= ~1; @@ -605,7 +606,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, /* FIXME: this isn't the appropriate place, but we can't receive * NSRightMouseDown some how */ msg_Dbg( p_vout, "received NSRightMouseUp" ); - [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]]; + [NSMenu popUpContextMenu: [[VLCMain sharedInstance] voutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] controls] voutView]]; } [super mouseUp: o_event]; @@ -667,7 +668,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, var_Set( p_vout, "mouse-moved", val ); } if( [self isFullscreen] ) - [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn]; + [[[[VLCMain sharedInstance] controls] fspanel] fadeIn]; } [super mouseMoved: o_event]; @@ -692,30 +693,25 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, /* Class methods used by the different vout modules */ -+ (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout ++ (vout_thread_t *)realVout: (vout_thread_t *)p_vout { /* p_real_vout: the vout we have to use to check for video-on-top and a few other things. If we are the QuickTime output, it's us. - It we are the OpenGL provider, it is our parent. */ - if( p_vout->i_object_type == VLC_OBJECT_OPENGL ) - { - return (vout_thread_t *) p_vout->p_parent; - } - else - { - return p_vout; - } - + It we are the OpenGL provider, it is our parent. + Since we can't be the QuickTime output anymore, we need to be + the parent. + FIXME: check with the caca and x11 vouts! */ + return (vout_thread_t *) p_vout->p_parent; } -+ (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view - frame: (NSRect *)s_frame ++ (id)voutView: (vout_thread_t *)p_vout subView: (NSView *)view + frame: (NSRect *)s_frame { - vlc_value_t value_drawable; + int i_drawable_gl; int i_timeout; id o_return = nil; - var_Get( p_vout->p_libvlc, "drawable", &value_drawable ); + i_drawable_gl = var_GetInteger( p_vout->p_libvlc, "drawable-gl" ); var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); @@ -726,9 +722,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, /* We only wait for NSApp to initialise if we're not embedded (as in the * case of the Mozilla plugin). We can tell whether we're embedded or not - * by examining the "drawable" value: if it's zero, we're running in the + * by examining the "drawable-gl" value: if it's zero, we're running in the * main Mac intf; if it's non-zero, we're embedded. */ - if( value_drawable.i_int == 0 ) + if( i_drawable_gl == 0 ) { /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */ for( i_timeout = 20 ; i_timeout-- ; ) @@ -751,8 +747,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, !(var_GetBool( p_vout, "macosx-background" )) && var_GetBool( p_vout, "embedded-video") ) { - o_return = [[[VLCMain sharedInstance] getEmbeddedList] - getEmbeddedVout]; + o_return = [[[VLCMain sharedInstance] embeddedList] embeddedVout]; } } } @@ -770,24 +765,18 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, - (void)enterFullscreen { - if( var_GetBool( p_real_vout, "video-on-top" ) ) - { - [o_window setLevel: NSNormalWindowLevel]; - } - - [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES]; - [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil]; + /* Save the settings for next playing item */ + playlist_t * p_playlist = pl_Hold( p_real_vout ); + var_SetBool( p_playlist, "fullscreen", true ); + pl_Release( p_real_vout ); } - (void)leaveFullscreen { - if( var_GetBool( p_real_vout, "video-on-top" ) ) - { - [o_window setLevel: NSStatusWindowLevel]; - } - - [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES]; - [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil]; + /* Save the settings for next playing item */ + playlist_t * p_playlist = pl_Hold( p_real_vout ); + var_SetBool( p_playlist, "fullscreen", false ); + pl_Release( p_real_vout ); } @end @@ -804,30 +793,31 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, return self; } -- (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view +- (BOOL)mouseDownCanMoveWindow +{ + return YES; +} + +- (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view frame: (NSRect *) s_arg_frame { BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame]; i_time_mouse_last_moved = mdate(); o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self frame: s_arg_frame]; + [self updateTitle]; - [view setFrame: [self frame]]; - - if( var_GetBool( p_real_vout, "video-on-top" ) ) - { - [o_window setLevel: NSStatusWindowLevel]; - } - + if([self isFullscreen]) + [o_window performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES]; + else + [view setFrame: [self frame]]; - [o_window setAcceptsMouseMovedEvents: TRUE]; return b_return; } - (void)closeVout { - [o_window closeWindow]; - [o_window setAcceptsMouseMovedEvents: NO]; + [o_window performSelectorOnMainThread: @selector(close) withObject: NULL waitUntilDone: YES]; i_time_mouse_last_moved = 0; [super closeVout]; } @@ -860,13 +850,18 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, - (void)manage { + /* Dooh, why do we spend processor time doing this kind of stuff? */ [super manage]; unsigned int i_mouse_hide_timeout = - var_GetInteger(p_vout, "mouse-hide-timeout") * 1000; + var_CreateGetInteger(p_vout, "mouse-hide-timeout") * 1000; + + if( i_mouse_hide_timeout < 100000 ) + i_mouse_hide_timeout = 100000; if( p_vout->b_fullscreen ) { if( mdate() - i_time_mouse_last_moved > i_mouse_hide_timeout ) { + i_time_mouse_last_moved = mdate(); [self hideMouse: YES]; } } @@ -876,6 +871,29 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, } } + +- (void)enterFullscreen +{ + [o_window performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: NO]; + [super enterFullscreen]; + +} + +- (void)leaveFullscreen +{ + [o_window performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: NO]; + [super leaveFullscreen]; +} + + +- (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate +{ + if( p_vout->b_fullscreen ) + return; + [o_window setMovableByWindowBackground: NO]; + [super scaleWindowWithFactor: factor animate: animate]; + [o_window setMovableByWindowBackground: YES]; +} @end /***************************************************************************** @@ -884,16 +902,29 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, @implementation VLCEmbeddedVoutView +- (void)awakeFromNib +{ + o_embeddedwindow = [self window]; +} + +- (BOOL)mouseDownCanMoveWindow +{ + return YES; +} + - (id)initWithFrame: (NSRect)frameRect { - [super initWithFrame: frameRect]; - b_used = NO; - [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self]; + if(self = [super initWithFrame: frameRect]) + { + b_used = NO; + [[[VLCMain sharedInstance] embeddedList] addEmbeddedVout: self]; + o_embeddedwindow = nil; /* Filled later on in -awakeFromNib */ + } return self; } - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view - frame: (NSRect *)s_arg_frame showWindow: (BOOL)b_show_window + frame: (NSRect *)s_arg_frame { BOOL b_return; @@ -903,57 +934,16 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, if( b_return ) { o_window = [self window]; - if (b_show_window) - [o_window makeKeyAndOrderFront: self]; + [o_window setAcceptsMouseMovedEvents: TRUE]; - if( var_GetBool( p_real_vout, "video-on-top" ) ) + if( var_CreateGetBool( p_real_vout, "video-on-top" ) ) { [o_window setLevel: NSStatusWindowLevel]; } [view setFrameSize: [self frame].size]; } - return b_return; -} - -- (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view - frame: (NSRect *) s_arg_frame - -{ - return [self setVout: p_arg_vout subView: view frame:s_arg_frame showWindow: YES]; -} - -- (void)setUsed: (BOOL)b_new_used -{ - b_used = b_new_used; -} - -- (BOOL)isUsed -{ - return b_used; -} - -- (void)closeVout -{ - [super closeVout]; - [o_window setAcceptsMouseMovedEvents: NO]; - [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self]; -} - - -@end - -@implementation VLCDetachedEmbeddedVoutView -- (void)awakeFromNib -{ - o_embeddedwindow = [self window]; -} - -- (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view - frame: (NSRect *) s_arg_frame -{ - BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame showWindow: NO]; /* o_window needs to point to our o_embeddedwindow, super might have set it * to the fullscreen window that o_embeddedwindow setups during fullscreen */ @@ -975,7 +965,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])]; - [o_window setAspectRatio:NSMakeSize([o_window frame].size.width, [o_window frame].size.height)]; + [o_embeddedwindow setVideoRatio:[self voutSizeForFactor:1.0]]; /* Make sure our window is visible, if we are not in fullscreen */ if (![o_window isFullscreen]) @@ -983,27 +973,46 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, [o_window unlockFullscreenAnimation]; } + return b_return; } +- (void)setUsed: (BOOL)b_new_used +{ + b_used = b_new_used; +} + +- (BOOL)isUsed +{ + return b_used; +} + - (void)closeVout { + [super closeVout]; + /* Don't close the window yet, wait a bit to see if a new input is poping up */ /* FIXME: Probably fade the window In and Out */ /* FIXME: fix core */ - [o_window performSelector:@selector(orderOut:) withObject:nil afterDelay:1.5]; + [o_embeddedwindow performSelector:@selector(orderOut:) withObject:nil afterDelay:3.]; - [super closeVout]; + [[[VLCMain sharedInstance] embeddedList] releaseEmbeddedVout: self]; } - (void)enterFullscreen { + /* Save settings */ + [super enterFullscreen]; + /* We are in a VLCEmbeddedWindow */ [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES]; } - (void)leaveFullscreen { + /* Save settings */ + [super leaveFullscreen]; + /* We are in a VLCEmbeddedWindow */ [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES]; } @@ -1020,209 +1029,123 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, p_vout = vout; o_view = view; s_frame = frame; - - [self performSelectorOnMainThread: @selector(initReal:) + b_init_ok = NO; + [self performSelectorOnMainThread: @selector(initMainThread:) withObject: NULL waitUntilDone: YES]; - if( !b_init_ok ) - { - return NULL; - } - - return self; + return b_init_ok ? self : nil; } -- (id)initReal: (id) sender +- (id)initMainThread: (id) sender { - NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init]; - NSArray *o_screens = [NSScreen screens]; - NSScreen *o_screen; - bool b_menubar_screen = false; - int i_device; - - b_init_ok = false; - - p_real_vout = [VLCVoutView getRealVout: p_vout]; - i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" ); - b_black = NO; - b_embedded = var_GetBool( p_vout, "embedded-video" ); + NSRect rect; + rect.size.height = p_vout->i_window_height; + rect.size.width = p_vout->i_window_width; + rect.origin.x = rect.origin.y = 70.; - /* Find out on which screen to open the window */ - o_screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device]; - - if( !o_screen ) - o_screen = [NSScreen mainScreen]; - - if( [o_screen isMainScreen] ) - b_menubar_screen = true; - - if( p_vout->b_fullscreen ) + if( self = [super initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]) { - CGDisplayFadeReservationToken token; - NSRect screen_rect = [o_screen frame]; - screen_rect.origin.x = screen_rect.origin.y = 0; - - b_black = var_GetBool( p_vout, "macosx-black" ); - - /* move the FSPanel to front in case that it is currently shown - * this won't and is not supposed to work when it's fading right now */ - if( [[[[VLCMain sharedInstance] getControls] getFSPanel] isDisplayed] ) - [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil]; - - /* tell the fspanel to move itself to front next time it's triggered */ - [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device]; - - /* Creates a window with size: screen_rect on o_screen */ - [self initWithContentRect: screen_rect - styleMask: NSBorderlessWindowMask - backing: NSBackingStoreBuffered - defer: YES screen: o_screen]; - - if( b_menubar_screen ) + [self setBackgroundColor:[NSColor blackColor]]; + [self setHasShadow:YES]; + [self setMovableByWindowBackground: YES]; + [self center]; + [self makeKeyAndOrderFront: self]; + [self setReleasedWhenClosed: YES]; + [self setFrameUsingName:@"VLCVoutWindowDetached"]; + [self setFrameAutosaveName:@"VLCVoutWindowDetached"]; + + /* We'll catch mouse events */ + [self makeFirstResponder: o_view]; + [self setCanBecomeKeyWindow: YES]; + [self setAcceptsMouseMovedEvents: YES]; + [self setIgnoresMouseEvents: NO]; + + if( var_CreateGetBool( p_vout, "macosx-background" ) ) { - SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar); - } - if( b_black == true ) - { - CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token); - CGDisplayFade( token, 0.6 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES ); - - [o_screen blackoutOtherScreens]; + int i_device = var_GetInteger( p_vout->p_libvlc, "video-device" ); - CGDisplayFade( token, 0.3 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO ); - CGReleaseDisplayFadeReservation( token); - } - } - else if( var_GetBool( p_vout, "macosx-background" ) ) - { - NSRect screen_rect = [o_screen frame]; - screen_rect.origin.x = screen_rect.origin.y = 0; + /* Find out on which screen to open the window */ + NSScreen * screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device]; + if( !screen ) screen = [NSScreen mainScreen]; - /* Creates a window with size: screen_rect on o_screen */ - [self initWithContentRect: screen_rect - styleMask: NSBorderlessWindowMask - backing: NSBackingStoreBuffered - defer: YES screen: o_screen]; + NSRect screen_rect = [screen frame]; + screen_rect.origin.x = screen_rect.origin.y = 0; - [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; - } - else - { - unsigned int i_stylemask = NSTitledWindowMask | - NSMiniaturizableWindowMask | - NSClosableWindowMask | - NSResizableWindowMask; + /* Creates a window with size: screen_rect on o_screen */ + [self setFrame: screen_rect display: NO]; - NSRect s_rect; - if( !s_frame ) - { - s_rect.size.width = p_vout->i_window_width; - s_rect.size.height = p_vout->i_window_height; + [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; + [self setMovableByWindowBackground: NO]; } - else + if( var_CreateGetBool( p_vout, "video-on-top" ) ) { - s_rect = *s_frame; + [self setLevel: NSStatusWindowLevel]; } - [self initWithContentRect: s_rect - styleMask: i_stylemask - backing: NSBackingStoreBuffered - defer: YES screen: o_screen]; + [self setAlphaValue: var_CreateGetFloat( p_vout, "macosx-opaqueness" )]; - [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )]; + /* Add the view. It's automatically resized to fit the window */ + [self setContentView: o_view]; - if( !s_frame ) - { - [self center]; - } + b_init_ok = YES; } - - [self makeKeyAndOrderFront: nil]; - [self setReleasedWhenClosed: YES]; - - /* We'll catch mouse events */ - [self makeFirstResponder: o_view]; - - /* Add the view. It's automatically resized to fit the window */ - [self setContentView: o_view]; - - [o_pool release]; - - b_init_ok = true; return self; } -- (void)close +- (void)enterFullscreen { - [o_view closeVout]; -} + if( fullscreen ) return; -- (void)closeWindow -{ - /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting - Command-Q */ - [self performSelectorOnMainThread: @selector(closeReal:) - withObject: NULL waitUntilDone: NO]; -} + NSScreen *screen; + int i_device; + BOOL b_black = NO; -- (id)closeReal:(id)sender -{ - if( b_black == true ) - { - CGDisplayFadeReservationToken token; - CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token); - CGDisplayFade( token, 0.3 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES ); - - [self disableScreenUpdatesUntilFlush]; - [self orderOut: self]; + i_device = var_GetInteger( p_vout->p_libvlc, "video-device" ); + b_black = var_CreateGetBool( p_vout, "macosx-black" ); - CGDisplayFade( token, 0.6 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, YES ); - CGReleaseDisplayFadeReservation( token); - CGDisplayRestoreColorSyncSettings(); - } - [NSScreen unblackoutScreens]; + /* Find out on which screen to open the window */ + screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device]; + if( !screen ) screen = [self screen]; - SetSystemUIMode( kUIModeNormal, 0); - [super close]; - /* this does only work in embedded mode */ - if( b_embedded == true ) - [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self]; + if( b_black ) + [screen blackoutOtherScreens]; - return NULL; -} + [self setMovableByWindowBackground: NO]; -- (id)getVoutView -{ - return o_view; -} + if( [screen isMainScreen] ) + [NSMenu setMenuBarVisible:NO]; -- (BOOL)canBecomeKeyWindow -{ - return YES; -} + initialFrame = [self frame]; + [self setFrame:[screen frame] display:YES animate:YES]; + [self setLevel:NSNormalWindowLevel]; -/* Sometimes crashes VLC.... -- (BOOL)performKeyEquivalent:(NSEvent *)o_event -{ - return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event]; -}*/ + /* tell the fspanel to move itself to front next time it's triggered */ + [[[[VLCMain sharedInstance] controls] fspanel] setVoutWasUpdated: i_device]; + [[[[VLCMain sharedInstance] controls] fspanel] setActive: nil]; -/* This is actually the same as VLCControls::stop. */ + fullscreen = YES; +} -- (BOOL)windowShouldClose:(id)sender +- (void)leaveFullscreen { - playlist_t * p_playlist = pl_Yield( p_vout ); - if( p_playlist == NULL ) - { - return NO; - } + if( !fullscreen ) return; + fullscreen = NO; - playlist_Stop( p_playlist ); - vlc_object_release( p_playlist ); + [NSScreen unblackoutScreens]; - /* The window will be closed by the intf later. */ - return NO; + [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil]; + [NSMenu setMenuBarVisible:YES]; + + [self setFrame:initialFrame display:YES animate:YES]; + [self setMovableByWindowBackground: YES]; + if( var_GetBool( p_vout, "video-on-top" ) ) + [self setLevel: NSStatusWindowLevel]; } +- (id)voutView +{ + return o_view; +} @end +