X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fmacosx%2Fvout.m;h=2d9b3a1d04b9cc0bd651582cb2ed33d6bb7b7fd8;hb=afafeb19b897427835244a34607b7327cddff45d;hp=a3e460cc085327575ff0beb15e64b8d3030a3e4f;hpb=1aeb8f055facaf73d8d287941a37f6a52c3b44b1;p=vlc diff --git a/modules/gui/macosx/vout.m b/modules/gui/macosx/vout.m index a3e460cc08..2d9b3a1d04 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-2006 the VideoLAN team + * Copyright (C) 2001-2007 the VideoLAN team * $Id$ * * Authors: Colin Delacroix @@ -40,7 +40,10 @@ #include #include "intf.h" +#include "fspanel.h" #include "vout.h" +#import "controls.h" +#import "embeddedwindow.h" /***************************************************************************** * DeviceCallback: Callback triggered when the video-device variable is changed @@ -52,8 +55,8 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, vout_thread_t *p_vout = (vout_thread_t *)p_this; msg_Dbg( p_vout, "set %d", new_val.i_int ); - var_Create( p_vout->p_vlc, "video-device", VLC_VAR_INTEGER ); - var_Set( p_vout->p_vlc, "video-device", new_val ); + var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER ); + var_Set( p_vout->p_libvlc, "video-device", new_val ); val.b_bool = VLC_TRUE; var_Set( p_vout, "intf-change", val ); @@ -111,9 +114,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, - (BOOL)windowContainsEmbedded: (id)o_window { -/* if( ![[o_window className] isEqualToString: @"VLCWindow"] ) +/* if( ![[o_window className] isEqualToString: @"VLCVoutWindow"] ) { - NSLog( @"We were not given a VLCWindow" ); + NSLog( @"We were not given a VLCVoutWindow" ); }*/ return ([self getViewForWindow: o_window] == nil ? NO : YES ); } @@ -172,13 +175,13 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, p_real_vout = [VLCVoutView getRealVout: 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_vlc, "video-device" ) == 0 ) + if( var_Type( p_real_vout->p_libvlc, "video-device" ) == 0 ) { i_device = var_GetInteger( p_vout, "macosx-vdev" ); } else { - i_device = var_GetInteger( p_real_vout->p_vlc, "video-device" ); + i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" ); } /* Setup the menuitem for the multiple displays. */ @@ -211,10 +214,10 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, (int)s_rect.size.width, (int)s_rect.size.height ); text.psz_string = psz_temp; - val2.i_int = i; + val2.i_int = (int)[o_screen displayID]; var_Change( p_real_vout, "video-device", VLC_VAR_ADDCHOICE, &val2, &text ); - if( i == i_device ) + if( (int)[o_screen displayID] == i_device ) { var_Set( p_real_vout, "video-device", val2 ); } @@ -242,14 +245,27 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, [o_view setFrameSize: [self frame].size]; } +- (void)drawRect:(NSRect)rect +{ + /* When there is no subview we draw a black background */ + [self lockFocus]; + [[NSColor blackColor] set]; + NSRectFill(rect); + [self unlockFocus]; +} + - (void)closeVout { + [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeOut]; + + /* Make sure we don't see a white flash */ + [[self window] disableScreenUpdatesUntilFlush]; [o_view removeFromSuperview]; o_view = nil; p_vout = NULL; s_frame = nil; o_window = nil; - p_real_vout = NULL; + p_real_vout = NULL; } - (void)updateTitle @@ -269,24 +285,35 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, return; } - if( p_input->input.p_item->psz_name != NULL ) + if( input_GetItem(p_input)->psz_name != NULL ) o_title = [NSMutableString stringWithUTF8String: - p_input->input.p_item->psz_name]; - if( p_input->input.p_item->psz_uri != NULL ) + input_GetItem(p_input)->psz_name]; + if( input_GetItem(p_input)->psz_uri != NULL ) o_mrl = [NSMutableString stringWithUTF8String: - p_input->input.p_item->psz_uri]; + input_GetItem(p_input)->psz_uri]; if( o_title == nil ) o_title = o_mrl; if( o_mrl != nil ) { - if( p_input->input.p_access && !strcmp( p_input->input.p_access->p_module->psz_shortname, "File" ) ) - { - NSRange prefix_range = [o_mrl rangeOfString: @"file:"]; - if( prefix_range.location != NSNotFound ) - [o_mrl deleteCharactersInRange: prefix_range]; + /* FIXME once psz_access is exported, we could check if we are + * reading from a file in a smarter way. */ + + NSRange prefix_range = [o_mrl rangeOfString: @"file:"]; + if( prefix_range.location != NSNotFound ) + [o_mrl deleteCharactersInRange: prefix_range]; + + if( [o_mrl characterAtIndex:0] == '/' ) + { + /* it's a local file */ [o_window setRepresentedFilename: o_mrl]; } + else + { + /* it's from the network or somewhere else, + * we clear the previous path */ + [o_window setRepresentedFilename: @""]; + } [o_window setTitle: o_title]; } else @@ -309,7 +336,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, } } -- (void)scaleWindowWithFactor: (float)factor +- (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate { NSSize newsize; int i_corrected_height, i_corrected_width; @@ -318,6 +345,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, if ( !p_vout->b_fullscreen ) { + NSView *mainView; NSRect new_frame; topleftbase.x = 0; topleftbase.y = [o_window frame].size.height; @@ -339,16 +367,23 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, newsize.height = (int) ( i_corrected_height * factor ); } + /* In fullscreen mode we need to use a view that is different from + * ourselves, with the VLCEmbeddedWindow */ + if([o_window isKindOfClass:[VLCEmbeddedWindow class]]) + mainView = [o_window mainView]; + else + mainView = self; + /* Calculate the window's new size */ new_frame.size.width = [o_window frame].size.width - - [self frame].size.width + newsize.width; + [mainView frame].size.width + newsize.width; new_frame.size.height = [o_window frame].size.height - - [self frame].size.height + newsize.height; + [mainView frame].size.height + newsize.height; new_frame.origin.x = topleftscreen.x; new_frame.origin.y = topleftscreen.y - new_frame.size.height; - [o_window setFrame: new_frame display: YES]; + [o_window setFrame: new_frame display: animate animate: animate]; p_vout->i_changes |= VOUT_SIZE_CHANGE; } @@ -393,8 +428,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, - (void)manage { - /* Disable Screensaver */ - UpdateSystemActivity( UsrActivity ); + /* Disable Screensaver, when we're playing something, but allow it on pause */ + if( VLCIntf->p_sys->i_play_status == PLAYING_S ) + UpdateSystemActivity( UsrActivity ); } - (id)getWindow @@ -436,12 +472,12 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, { vlc_value_t val; val.i_int = config_GetInt( p_vout, "key-play-pause" ); - var_Set( p_vout->p_vlc, "key-pressed", val ); + var_Set( p_vout->p_libvlc, "key-pressed", val ); } else { val.i_int |= CocoaKeyToVLC( key ); - var_Set( p_vout->p_vlc, "key-pressed", val ); + var_Set( p_vout->p_libvlc, "key-pressed", val ); } } else @@ -479,94 +515,79 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" ); [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]]; } - - /* always forward to core as well */ - [super mouseDown: o_event]; } + + [super mouseDown: o_event]; } - (void)otherMouseDown:(NSEvent *)o_event { vlc_value_t val; - if( p_vout ) + if( p_vout && [o_event type] == NSOtherMouseDown ) { - if( [o_event type] == NSOtherMouseDown ) - { - var_Get( p_vout, "mouse-button-down", &val ); - val.i_int |= 2; - var_Set( p_vout, "mouse-button-down", val ); - } - - [super mouseDown: o_event]; + var_Get( p_vout, "mouse-button-down", &val ); + val.i_int |= 2; + var_Set( p_vout, "mouse-button-down", val ); } + + [super mouseDown: o_event]; } - (void)rightMouseDown:(NSEvent *)o_event { - if( p_vout ) + if( p_vout && [o_event type] == NSRightMouseDown ) { - if( [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]]; - } - - [super mouseDown: o_event]; + msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" ); + [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]]; } + + [super mouseDown: o_event]; } - (void)mouseUp:(NSEvent *)o_event { vlc_value_t val; - if( p_vout ) + if( p_vout && [o_event type] == NSLeftMouseUp ) { - if( [o_event type] == NSLeftMouseUp ) - { - vlc_value_t b_val; - b_val.b_bool = VLC_TRUE; - var_Set( p_vout, "mouse-clicked", b_val ); + vlc_value_t b_val; + b_val.b_bool = VLC_TRUE; + var_Set( p_vout, "mouse-clicked", b_val ); - var_Get( p_vout, "mouse-button-down", &val ); - val.i_int &= ~1; - var_Set( p_vout, "mouse-button-down", val ); - } - - [super mouseUp: o_event]; + var_Get( p_vout, "mouse-button-down", &val ); + val.i_int &= ~1; + var_Set( p_vout, "mouse-button-down", val ); } + + [super mouseUp: o_event]; } - (void)otherMouseUp:(NSEvent *)o_event { vlc_value_t val; - if( p_vout ) + if( p_vout && [o_event type] == NSOtherMouseUp ) { - if( [o_event type] == NSOtherMouseUp ) - { - var_Get( p_vout, "mouse-button-down", &val ); - val.i_int &= ~2; - var_Set( p_vout, "mouse-button-down", val ); - } - - [super mouseUp: o_event]; + var_Get( p_vout, "mouse-button-down", &val ); + val.i_int &= ~2; + var_Set( p_vout, "mouse-button-down", val ); } + + [super mouseUp: o_event]; } - (void)rightMouseUp:(NSEvent *)o_event { - if( p_vout ) + if( p_vout && [o_event type] == NSRightMouseUp ) { - if( [o_event type] == NSRightMouseUp ) - { - /* 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]]; - } - [super mouseUp: o_event]; + /* 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]]; } + + [super mouseUp: o_event]; } - (void)mouseDragged:(NSEvent *)o_event @@ -624,7 +645,10 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, val.b_bool = VLC_TRUE; var_Set( p_vout, "mouse-moved", val ); } + if( [self isFullscreen] ) + [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn]; } + [super mouseMoved: o_event]; } @@ -669,12 +693,10 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, vlc_value_t value_drawable; int i_timeout; id o_return = nil; - vout_thread_t * p_real_vout = [VLCVoutView getRealVout: p_vout]; - var_Get( p_vout->p_vlc, "drawable", &value_drawable ); + var_Get( p_vout->p_libvlc, "drawable", &value_drawable ); var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); - var_Create( p_vout, "macosx-fill", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); @@ -706,7 +728,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, else { if ( VLCIntf && !(p_vout->b_fullscreen) && - !(var_GetBool( p_real_vout, "macosx-background" )) && + !(var_GetBool( p_vout, "macosx-background" )) && var_GetBool( p_vout, "macosx-embedded") ) { o_return = [[[VLCMain sharedInstance] getEmbeddedList] @@ -726,6 +748,18 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, return o_return; } +- (void)enterFullscreen +{ + [[o_view class] resetVout: p_vout]; + [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil]; +} + +- (void)leaveFullscreen +{ + [[o_view class] resetVout: p_vout]; + [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil]; +} + @end /***************************************************************************** @@ -745,7 +779,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, { BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame]; i_time_mouse_last_moved = mdate(); - o_window = [[VLCWindow alloc] initWithVout: p_arg_vout view: self + o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self frame: s_arg_frame]; [self updateTitle]; [view setFrame: [self frame]]; @@ -869,34 +903,62 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, @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]; + /* o_window needs to point to our o_embeddedwindow, super might have set it + * to the fullscreen window that o_embeddedwindow setups during fullscreen */ + o_window = o_embeddedwindow; + if( b_return ) { [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )]; [self updateTitle]; - [self scaleWindowWithFactor: 1.0]; - [o_window makeKeyAndOrderFront: self]; + + if(!([o_window isFullscreen])) + [o_window makeKeyAndOrderFront: self]; + + [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])]; } return b_return; } - (void)closeVout { - [o_window orderOut: self]; + playlist_t * p_playlist = pl_Yield( VLCIntf ); + + if(!playlist_IsPlaying( p_playlist )) + [o_window performSelectorOnMainThread: @selector(orderOut:) withObject: self waitUntilDone: YES]; + + vlc_object_release( p_playlist ); + [super closeVout]; } +- (void)enterFullscreen +{ + /* We are in a VLCEmbeddedWindow */ + [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES]; +} + +- (void)leaveFullscreen +{ + /* We are in a VLCEmbeddedWindow */ + [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES]; +} @end /***************************************************************************** - * VLCWindow implementation + * VLCVoutWindow implementation *****************************************************************************/ -@implementation VLCWindow +@implementation VLCVoutWindow - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view frame: (NSRect *) frame @@ -927,24 +989,18 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, b_init_ok = VLC_FALSE; p_real_vout = [VLCVoutView getRealVout: p_vout]; - i_device = var_GetInteger( p_real_vout->p_vlc, "video-device" ); - b_black = var_GetBool( p_real_vout->p_vlc, "macosx-black" ); + i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" ); + b_black = var_GetBool( p_vout, "macosx-black" ); + b_embedded = var_GetBool( p_vout, "macosx-embedded" ); /* Find out on which screen to open the window */ - if( i_device <= 0 || i_device > (int)[o_screens count] ) - { - /* No preference specified. Use the main screen */ + o_screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device]; + + if( !o_screen ) o_screen = [NSScreen mainScreen]; - i_device = [o_screens indexOfObject: o_screen]; - if( o_screen == [o_screens objectAtIndex: 0] ) - b_menubar_screen = VLC_TRUE; - } - else - { - i_device--; - o_screen = [o_screens objectAtIndex: i_device]; - b_menubar_screen = ( i_device == 0 ); - } + + if( [o_screen isMainScreen] ) + b_menubar_screen = VLC_TRUE; if( p_vout->b_fullscreen ) { @@ -952,50 +1008,23 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, NSRect screen_rect = [o_screen frame]; screen_rect.origin.x = screen_rect.origin.y = 0; + /* 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] orderFront: self]; + + /* 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( var_GetBool( p_real_vout, "macosx-black" ) ) + if( b_black == VLC_TRUE ) - { - CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token); - CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, true ); - CGReleaseDisplayFadeReservation( token ); - unsigned int i; - for( i = 0 ; i < [o_screens count]; i++) - { - struct - { - CGDirectDisplayID displayID; - CGGammaValue redMin, redMax, redGamma, - greenMin, greenMax, greenGamma, - blueMin, blueMax, blueGamma; - } dispSettings; - CGDisplayCount dspyCnt; - CGPoint gPoint; - - if( i == (unsigned int)i_device ) continue; - - screen_rect = [[o_screens objectAtIndex: i] frame]; - - gPoint.x = screen_rect.origin.x; - gPoint.y = screen_rect.origin.y; - CGGetDisplaysWithPoint( gPoint, 1, &(dispSettings.displayID), &dspyCnt); - CGGetDisplayTransferByFormula( - dispSettings.displayID, - &dispSettings.redMin, &dispSettings.redMax, &dispSettings.redGamma, - &dispSettings.greenMin, &dispSettings.greenMax, &dispSettings.greenGamma, - &dispSettings.blueMin, &dispSettings.blueMax, &dispSettings.blueGamma ); - CGSetDisplayTransferByFormula( - dispSettings.displayID, - dispSettings.redMin, 0, dispSettings.redGamma, - dispSettings.greenMin, 0, dispSettings.greenGamma, - dispSettings.blueMin, 0, dispSettings.blueGamma ); - } - } + [o_screen blackoutOtherScreens]; + if( b_menubar_screen ) { SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar); @@ -1007,7 +1036,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, CGReleaseDisplayFadeReservation( token); } } - else if( var_GetBool( p_real_vout, "macosx-background" ) ) + else if( var_GetBool( p_vout, "macosx-background" ) ) { NSRect screen_rect = [o_screen frame]; screen_rect.origin.x = screen_rect.origin.y = 0; @@ -1071,7 +1100,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, [o_view closeVout]; } -- (void) closeWindow +- (void)closeWindow { /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting Command-Q */ @@ -1080,7 +1109,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, withObject: NULL waitUntilDone: NO]; } -- (id) closeReal: (id) sender +- (id)closeReal:(id)sender { if( b_black == VLC_TRUE ) { @@ -1092,6 +1121,10 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, } SetSystemUIMode( kUIModeNormal, 0); [super close]; + /* this does only work in embedded mode */ + if( b_embedded == VLC_TRUE ) + [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self]; + return NULL; }