X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fmacosx%2Fvout.m;h=4af48c00ef98f11fd0e569060c6312396c6f9e82;hb=89d0545b1b4f7f6ba1c817990919b5d08b6329d9;hp=e809402f1f8a916e5d73c51a1c5c3d1e73a7ec68;hpb=89885149e814b2d287dd7166a92eb69f3221f0af;p=vlc diff --git a/modules/gui/macosx/vout.m b/modules/gui/macosx/vout.m index e809402f1f..4af48c00ef 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-2003 VideoLAN + * Copyright (C) 2001-2005 VideoLAN * $Id$ * * Authors: Colin Delacroix @@ -40,16 +40,90 @@ #include "intf.h" #include "vout.h" + +/***************************************************************************** + * DeviceCallback: Callback triggered when the video-device variable is changed + *****************************************************************************/ +int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, + vlc_value_t old_val, vlc_value_t new_val, void *param ) +{ + vlc_value_t val; + 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 ); + + val.b_bool = VLC_TRUE; + var_Set( p_vout, "intf-change", val ); + return VLC_SUCCESS; +} + + /***************************************************************************** * VLCWindow implementation *****************************************************************************/ @implementation VLCWindow -- (id)initWithVout:(vout_thread_t *)_p_vout frame:(NSRect *)s_frame +- (id) initWithVout: (vout_thread_t *) vout view: (NSView *) view + frame: (NSRect *) frame { - [self setReleasedWhenClosed: YES]; + p_vout = vout; + o_view = view; + s_frame = frame; + + [self performSelectorOnMainThread: @selector(initReal:) + withObject: NULL waitUntilDone: YES]; + + if( !b_init_ok ) + { + return NULL; + } + + return self; +} + +- (id) initReal: (id) sender +{ + NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init]; + NSArray *o_screens = [NSScreen screens]; + NSScreen *o_screen; + vlc_bool_t b_menubar_screen = VLC_FALSE; + int i_timeout, i_device; + vlc_value_t value_drawable; + + b_init_ok = VLC_FALSE; - p_vout = _p_vout; + var_Get( p_vout->p_vlc, "drawable", &value_drawable ); + + /* 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 + * main Mac intf; if it's non-zero, we're embedded. */ + if( value_drawable.i_int == 0 ) + { + /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */ + for( i_timeout = 20 ; i_timeout-- ; ) + { + if( NSApp == NULL ) + { + msleep( INTF_IDLE_SLEEP ); + } + } + + if( NSApp == NULL ) + { + /* No MacOS X intf, unable to communicate with MT */ + msg_Err( p_vout, "no MacOS X interface present" ); + return NULL; + } + } + + if( [o_screens count] <= 0 ) + { + msg_Err( p_vout, "no OSX screens available" ); + return NULL; + } /* 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. @@ -66,31 +140,41 @@ p_fullscreen_state = NULL; i_time_mouse_last_moved = mdate(); - NSScreen * o_screen; - vlc_bool_t b_main_screen; - 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 ); - /* Setup the menuitem for the multiple displays. Read the vlc preference (macosx-vdev) for the primary display */ - NSArray * o_screens = [NSScreen screens]; - if( [o_screens count] > 0 && var_Type( p_real_vout, "video-device" ) == 0 ) + /* 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 ) + { + i_device = var_GetInteger( p_vout, "macosx-vdev" ); + } + else + { + i_device = var_GetInteger( p_real_vout->p_vlc, "video-device" ); + } + + /* Setup the menuitem for the multiple displays. */ + if( var_Type( p_real_vout, "video-device" ) == 0 ) { int i = 1; - vlc_value_t val, val2, text; + vlc_value_t val2, text; NSScreen * o_screen; - var_Get( p_real_vout, "macosx-vdev", &val ); - var_Create( p_real_vout, "video-device", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE ); - text.psz_string = _("Video device"); + text.psz_string = _("Video Device"); var_Change( p_real_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL ); NSEnumerator * o_enumerator = [o_screens objectEnumerator]; + val2.i_int = 0; + text.psz_string = _("Default"); + var_Change( p_real_vout, "video-device", + VLC_VAR_ADDCHOICE, &val2, &text ); + var_Set( p_real_vout, "video-device", val2 ); + while( (o_screen = [o_enumerator nextObject]) != NULL ) { char psz_temp[255]; @@ -104,15 +188,14 @@ val2.i_int = i; var_Change( p_real_vout, "video-device", VLC_VAR_ADDCHOICE, &val2, &text ); - - if( ( i - 1 ) == val.i_int ) + if( i == i_device ) { var_Set( p_real_vout, "video-device", val2 ); } i++; } - var_AddCallback( p_real_vout, "video-device", vout_VarCallback, + var_AddCallback( p_real_vout, "video-device", DeviceCallback, NULL ); val2.b_bool = VLC_TRUE; @@ -120,33 +203,20 @@ } /* Find out on which screen to open the window */ - int i_device = var_GetInteger( p_real_vout, "video-device" ); - if( i_device < 0 ) + if( i_device <= 0 || i_device > (int)[o_screens count] ) { /* No preference specified. Use the main screen */ o_screen = [NSScreen mainScreen]; - b_main_screen = 1; + if( o_screen == [o_screens objectAtIndex: 0] ) + b_menubar_screen = VLC_TRUE; } else { - NSArray *o_screens = [NSScreen screens]; - - if( [o_screens count] < (unsigned) i_device ) - { - o_screen = [NSScreen mainScreen]; - b_main_screen = 1; - } - else - { - i_device--; - o_screen = [o_screens objectAtIndex: i_device]; - var_SetInteger( p_real_vout, "macosx-vdev", i_device ); - b_main_screen = ( i_device == 0 ); - } + i_device--; + o_screen = [o_screens objectAtIndex: i_device]; + b_menubar_screen = ( i_device == 0 ); } - NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init]; - if( p_vout->b_fullscreen ) { NSRect screen_rect = [o_screen frame]; @@ -158,7 +228,7 @@ backing: NSBackingStoreBuffered defer: YES screen: o_screen]; - if( b_main_screen ) + if( b_menubar_screen ) { BeginFullScreen( &p_fullscreen_state, NULL, 0, 0, NULL, NULL, fullScreenAllowEvents ); @@ -202,25 +272,41 @@ [self updateTitle]; [self makeKeyAndOrderFront: nil]; + [self setReleasedWhenClosed: YES]; /* We'll catch mouse events */ [self setAcceptsMouseMovedEvents: YES]; [self makeFirstResponder: self]; + + /* Add the view. It's automatically resized to fit the window */ + [self setContentView: o_view]; [o_pool release]; + + b_init_ok = VLC_TRUE; return self; } -- (void)close +- (void) close +{ + /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting + Command-Q */ + [self setContentView: NULL]; + [self performSelectorOnMainThread: @selector(closeReal:) + withObject: NULL waitUntilDone: NO]; +} + +- (id) closeReal: (id) sender { + [super close]; if( p_fullscreen_state ) { - EndFullScreen( p_fullscreen_state, NULL ); + EndFullScreen( p_fullscreen_state, 0 ); } - [super close]; + return NULL; } -- (void)setOnTop:(bool)b_on_top +- (void)setOnTop:(BOOL)b_on_top { if( b_on_top ) { @@ -232,7 +318,7 @@ } } -- (void)hideMouse:(bool)b_hide +- (void)hideMouse:(BOOL)b_hide { BOOL b_inside; NSPoint ml; @@ -309,33 +395,36 @@ - (void)toggleFloatOnTop { vlc_value_t val; - if( var_Get( p_vout, "video-on-top", &val )>=0 && val.b_bool) + + if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool) { val.b_bool = VLC_FALSE; - var_Set( p_vout, "video-on-top", val ); } else { val.b_bool = VLC_TRUE; - var_Set( p_vout, "video-on-top", val ); } + var_Set( p_real_vout, "video-on-top", val ); } - (void)toggleFullscreen { vlc_value_t val; - val.b_bool = !p_real_vout->b_fullscreen; + var_Get( p_real_vout, "fullscreen", &val ); + val.b_bool = !val.b_bool; var_Set( p_real_vout, "fullscreen", val ); } - (BOOL)isFullscreen { - return( p_vout->b_fullscreen ); + vlc_value_t val; + var_Get( p_real_vout, "fullscreen", &val ); + return( val.b_bool ); } - (void)snapshot { - vout_Control( p_vout, VOUT_SNAPSHOT ); + vout_Control( p_real_vout, VOUT_SNAPSHOT ); } - (BOOL)canBecomeKeyWindow @@ -399,37 +488,42 @@ - (void)updateTitle { - NSMutableString * o_title; - playlist_t * p_playlist; + NSMutableString * o_title = NULL, * o_mrl = NULL; + input_thread_t * p_input; if( p_vout == NULL ) { return; } - p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, + FIND_PARENT ); - if( p_playlist == NULL ) + if( p_input == NULL ) { return; } - vlc_mutex_lock( &p_playlist->object_lock ); - o_title = [NSMutableString stringWithUTF8String: - p_playlist->status.p_item->input.psz_uri]; - vlc_mutex_unlock( &p_playlist->object_lock ); - vlc_object_release( p_playlist ); - - if( o_title != nil ) + if( p_input->input.p_item->psz_name != NULL ) + o_title = [NSMutableString stringWithUTF8String: + p_input->input.p_item->psz_name]; + if( p_input->input.p_item->psz_uri != NULL ) + o_mrl = [NSMutableString stringWithUTF8String: + p_input->input.p_item->psz_uri]; + if( o_title == nil ) + o_title = o_mrl; + + vlc_object_release( p_input ); + if( o_mrl != nil ) { - NSRange prefix_range = [o_title rangeOfString: @"file:"]; - if( prefix_range.location != NSNotFound ) + if( p_input->input.p_access && !strcmp( p_input->input.p_access->p_module->psz_shortname, "File" ) ) { - [o_title deleteCharactersInRange: prefix_range]; + NSRange prefix_range = [o_mrl rangeOfString: @"file:"]; + if( prefix_range.location != NSNotFound ) + [o_mrl deleteCharactersInRange: prefix_range]; + [self setRepresentedFilename: o_mrl]; } - - [self setTitleWithRepresentedFilename: o_title]; + [self setTitle: o_title]; } else { @@ -615,11 +709,9 @@ NSPoint ml; NSRect s_rect; BOOL b_inside; - NSView * o_view; i_time_mouse_last_moved = mdate(); - o_view = [self contentView]; s_rect = [o_view bounds]; ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil]; b_inside = [o_view mouse: ml inRect: s_rect]; @@ -627,7 +719,7 @@ if( b_inside ) { vlc_value_t val; - int i_width, i_height, i_x, i_y; + unsigned int i_width, i_height, i_x, i_y; vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width, (unsigned int)s_rect.size.height,