Commit e4ceccd3 authored by hartman's avatar hartman
Browse files

-

parent 359a9baf
......@@ -2,7 +2,7 @@
* darwin_specific.h: Darwin specific features
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: darwin_specific.h,v 1.8 2004/01/25 18:17:08 zorglub Exp $
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -20,4 +20,3 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
......@@ -69,8 +69,6 @@ int E_(OpenIntf) ( vlc_object_t *p_this )
p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
p_intf->b_play = VLC_TRUE;
p_intf->pf_run = Run;
[[VLCMain sharedInstance] setIntf: p_intf];
return( 0 );
}
......@@ -86,7 +84,7 @@ void E_(CloseIntf) ( vlc_object_t *p_this )
[p_intf->p_sys->o_sendport release];
[p_intf->p_sys->o_pool release];
free( p_intf->p_sys );
}
......@@ -99,21 +97,24 @@ static void Run( intf_thread_t *p_intf )
* fails to go to real-time priority with the first launched thread
* (???) --Meuuh */
vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
[[VLCMain sharedInstance] setIntf: p_intf];
[NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
[NSApp run];
[[VLCMain sharedInstance] terminate];
}
int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
{
int i_ret = 0;
NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
//NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
if( [target respondsToSelector: @selector(performSelectorOnMainThread:
withObject:waitUntilDone:)] )
{
[target performSelectorOnMainThread: sel
withObject: [NSValue valueWithPointer: p_arg]
waitUntilDone: YES];
waitUntilDone: NO];
}
else if( NSApp != nil && [[VLCMain sharedInstance] respondsToSelector: @selector(getIntf)] )
{
......@@ -161,7 +162,7 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
i_ret = 1;
}
[o_pool release];
//[o_pool release];
return( i_ret );
}
......@@ -290,7 +291,6 @@ static VLCMain *_o_sharedMainInstance = nil;
- (void)awakeFromNib
{
unsigned int i_key = 0;
intf_thread_t * p_intf = VLCIntf;
playlist_t *p_playlist;
vlc_value_t val;
......@@ -527,7 +527,7 @@ static VLCMain *_o_sharedMainInstance = nil;
vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
}
/*
- (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
{
NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
......@@ -536,7 +536,7 @@ static VLCMain *_o_sharedMainInstance = nil;
return( TRUE );
}
*/
- (NSString *)localizedString:(char *)psz
{
NSString * o_str = nil;
......@@ -637,7 +637,7 @@ static VLCMain *_o_sharedMainInstance = nil;
int i;
val.i_int = 0;
p_hotkeys = VLCIntf->p_vlc->p_hotkeys;
p_hotkeys = p_intf->p_vlc->p_hotkeys;
i_pressed_modifiers = [o_event modifierFlags];
......@@ -658,7 +658,7 @@ static VLCMain *_o_sharedMainInstance = nil;
{
if( p_hotkeys[i].i_key == val.i_int )
{
var_Set( VLCIntf->p_vlc, "key-pressed", val );
var_Set( p_intf->p_vlc, "key-pressed", val );
return YES;
}
}
......@@ -696,6 +696,7 @@ static VLCMain *_o_sharedMainInstance = nil;
- (void)manage
{
NSDate * o_sleep_date;
/* new thread requires a new pool */
NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
......@@ -809,7 +810,7 @@ static VLCMain *_o_sharedMainInstance = nil;
{
if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
{
[o_vout_wnd updateTitle];
;//[o_vout_wnd updateTitle];
}
}
vlc_object_release( (vlc_object_t *)p_vout );
......@@ -1134,7 +1135,6 @@ static VLCMain *_o_sharedMainInstance = nil;
- (IBAction)timesliderUpdate:(id)sender
{
intf_thread_t * p_intf;
input_thread_t * p_input;
float f_updated;
......
......@@ -74,29 +74,18 @@
@end
/*****************************************************************************
* VLCVout interface
*****************************************************************************/
@interface VLCVout : NSObject
{
}
- (void)createWindow:(NSValue *)o_value;
- (void)destroyWindow:(NSValue *)o_value;
@end
/*****************************************************************************
* vout_sys_t: MacOS X video output method descriptor
*****************************************************************************/
struct vout_sys_t
{
int i_opengl;
NSAutoreleasePool *o_pool;
NSRect s_rect;
int b_pos_saved;
VLCWindow * o_window;
int i_opengl;
int b_pos_saved;
vlc_bool_t b_mouse_moved;
mtime_t i_time_mouse_last_moved;
......
......@@ -68,7 +68,6 @@ static void vout_End ( vout_thread_t * );
static int vout_Manage ( vout_thread_t * );
static void vout_Display ( vout_thread_t *, picture_t * );
static int CoSendRequest ( vout_thread_t *, SEL );
static int CoCreateWindow ( vout_thread_t * );
static int CoDestroyWindow ( vout_thread_t * );
static int CoToggleFullscreen ( vout_thread_t * );
......@@ -119,6 +118,7 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
return( 1 );
}
p_vout->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
p_vout->p_sys->b_mouse_moved = VLC_TRUE;
p_vout->p_sys->i_time_mouse_last_moved = mdate();
......@@ -159,7 +159,7 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
free( p_vout->p_sys );
return( 1 );
}
}
/* Damn QT isn't thread safe. so keep a lock in the p_vlc object */
vlc_mutex_lock( &p_vout->p_vlc->quicktime_lock );
......@@ -168,6 +168,7 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
nil, &p_vout->p_sys->img_dc );
vlc_mutex_unlock( &p_vout->p_vlc->quicktime_lock );
if( err == noErr && p_vout->p_sys->img_dc != 0 )
{
p_vout->output.i_chroma = VLC_FOURCC('I','4','2','0');
......@@ -192,7 +193,6 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
msg_Dbg( p_vout, "using OpenGL mode" );
}
NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
NSArray * o_screens = [NSScreen screens];
if( [o_screens count] > 0 && var_Type( p_vout, "video-device" ) == 0 )
{
......@@ -236,7 +236,6 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
val.b_bool = VLC_TRUE;
var_Set( p_vout, "intf-change", val );
}
[o_pool release];
if( CoCreateWindow( p_vout ) )
{
......@@ -432,7 +431,8 @@ static void vout_End( vout_thread_t *p_vout )
* CloseVideo: destroy video thread output method
*****************************************************************************/
void E_(CloseVideo) ( vlc_object_t *p_this )
{
{
NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
vout_thread_t * p_vout = (vout_thread_t *)p_this;
if( p_vout->p_sys->i_opengl )
......@@ -457,6 +457,7 @@ void E_(CloseVideo) ( vlc_object_t *p_this )
DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
}
[o_pool release];
free( p_vout->p_sys );
}
......@@ -570,52 +571,120 @@ static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
}
/*****************************************************************************
* CoSendRequest: send request to interface thread
* CoCreateWindow: create new window
*****************************************************************************
* Returns 0 on success, 1 otherwise
*****************************************************************************/
static int CoSendRequest( vout_thread_t *p_vout, SEL sel )
static int CoCreateWindow( vout_thread_t *p_vout )
{
int i_ret = 0;
vlc_value_t val;
intf_thread_t * p_intf;
VLCQTView * o_view;
NSScreen * o_screen;
vlc_bool_t b_main_screen;
NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
VLCVout * o_vlv = [[VLCVout alloc] init];
p_vout->p_sys->o_window = [VLCWindow alloc];
[p_vout->p_sys->o_window setReleasedWhenClosed: YES];
if( ( i_ret = ExecuteOnMainThread( o_vlv, sel, (void *)p_vout ) ) )
if( var_Get( p_vout, "video-device", &val ) < 0 )
{
msg_Err( p_vout, "SendRequest: no way to communicate with mt" );
o_screen = [NSScreen mainScreen];
b_main_screen = 1;
}
else
{
NSArray *o_screens = [NSScreen screens];
unsigned int i_index = val.i_int;
if( [o_screens count] < i_index )
{
o_screen = [NSScreen mainScreen];
b_main_screen = 1;
}
else
{
i_index--;
o_screen = [o_screens objectAtIndex: i_index];
config_PutInt( p_vout, "macosx-vdev", i_index );
b_main_screen = (i_index == 0);
}
}
[o_vlv release];
if( p_vout->b_fullscreen )
{
NSRect screen_rect = [o_screen frame];
screen_rect.origin.x = screen_rect.origin.y = 0;
/*This makes this function dependant of the presence of a macosx
interface. We do not check if this interface exists, since it has
already been done before.*/
if ( b_main_screen && p_vout->p_sys->p_fullscreen_state == NULL )
BeginFullScreen( &p_vout->p_sys->p_fullscreen_state, NULL, 0, 0,
NULL, NULL, fullScreenAllowEvents );
/*p_intf = VLCIntf;
[p_vout->p_sys->o_window
initWithContentRect: screen_rect
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreBuffered
defer: NO screen: o_screen];
val.b_bool = VLC_TRUE;
var_Create(p_intf,"intf-change",VLC_VAR_BOOL);
var_Set(p_intf, "intf-change",val);
*/
return( i_ret );
}
[p_vout->p_sys->o_window setVout: p_vout];
p_vout->p_sys->b_mouse_moved = YES;
p_vout->p_sys->i_time_mouse_last_moved = mdate();
}
else
{
unsigned int i_stylemask = NSTitledWindowMask |
NSMiniaturizableWindowMask |
NSClosableWindowMask |
NSResizableWindowMask;
if ( p_vout->p_sys->p_fullscreen_state != NULL )
EndFullScreen ( p_vout->p_sys->p_fullscreen_state, NULL );
p_vout->p_sys->p_fullscreen_state = NULL;
/*****************************************************************************
* CoCreateWindow: create new window
*****************************************************************************
* Returns 0 on success, 1 otherwise
*****************************************************************************/
static int CoCreateWindow( vout_thread_t *p_vout )
{
if( CoSendRequest( p_vout, @selector(createWindow:) ) )
[p_vout->p_sys->o_window
initWithContentRect: p_vout->p_sys->s_rect
styleMask: i_stylemask
backing: NSBackingStoreBuffered
defer: NO screen: o_screen];
[p_vout->p_sys->o_window setVout: p_vout];
[p_vout->p_sys->o_window setAlphaValue: config_GetFloat( p_vout, "macosx-opaqueness" )];
if( config_GetInt( p_vout, "video-on-top" ) )
{
[p_vout->p_sys->o_window setLevel: NSStatusWindowLevel];
}
if( !p_vout->p_sys->b_pos_saved )
{
[p_vout->p_sys->o_window center];
}
}
if( !p_vout->p_sys->i_opengl )
{
msg_Err( p_vout, "CoSendRequest (createWindow) failed" );
return( 1 );
o_view = [[VLCQTView alloc] init];
/* FIXME: [o_view setMenu:] */
[p_vout->p_sys->o_window setContentView: o_view];
[o_view autorelease];
[o_view lockFocus];
p_vout->p_sys->p_qdport = [o_view qdPort];
[o_view unlockFocus];
}
else
{
#define o_glview p_vout->p_sys->o_glview
o_glview = [[VLCGLView alloc] initWithFrame: p_vout->p_sys->s_rect vout: p_vout];
[p_vout->p_sys->o_window setContentView: o_glview];
[o_glview autorelease];
#undef o_glview
}
return( 0 );
[p_vout->p_sys->o_window updateTitle];
[p_vout->p_sys->o_window makeKeyAndOrderFront: nil];
[o_pool release];
return( 0);
}
/*****************************************************************************
......@@ -625,16 +694,27 @@ static int CoCreateWindow( vout_thread_t *p_vout )
*****************************************************************************/
static int CoDestroyWindow( vout_thread_t *p_vout )
{
NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
VLCHideMouse( p_vout, NO );
if( CoSendRequest( p_vout, @selector(destroyWindow:) ) )
if( !p_vout->b_fullscreen )
{
msg_Err( p_vout, "CoSendRequest (destroyWindow) failed" );
return( 1 );
}
NSRect s_rect;
return( 0 );
s_rect = [[p_vout->p_sys->o_window contentView] frame];
p_vout->p_sys->s_rect.size = s_rect.size;
s_rect = [p_vout->p_sys->o_window frame];
p_vout->p_sys->s_rect.origin = s_rect.origin;
p_vout->p_sys->b_pos_saved = YES;
}
p_vout->p_sys->p_qdport = nil;
[p_vout->p_sys->o_window close];
p_vout->p_sys->o_window = nil;
[o_pool release];
return 0;
}
/*****************************************************************************
......@@ -644,6 +724,8 @@ static int CoDestroyWindow( vout_thread_t *p_vout )
*****************************************************************************/
static int CoToggleFullscreen( vout_thread_t *p_vout )
{
NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
if( !p_vout->p_sys->i_opengl )
{
QTDestroySequence( p_vout );
......@@ -684,6 +766,7 @@ static int CoToggleFullscreen( vout_thread_t *p_vout )
}
}
[o_pool release];
return( 0 );
}
......@@ -1013,12 +1096,12 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
{
return( YES );
}
/*
- (BOOL)performKeyEquivalent:(NSEvent *)o_event
{
return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
}
*/
- (void)keyDown:(NSEvent *)o_event
{
unichar key = 0;
......@@ -1738,146 +1821,3 @@ CATCH_MOUSE_EVENTS
}
@end
/*****************************************************************************
* VLCVout implementation
*****************************************************************************/
@implementation VLCVout
- (void)createWindow:(NSValue *)o_value
{
vlc_value_t val;
VLCQTView * o_view;
NSScreen * o_screen;
vout_thread_t * p_vout;
vlc_bool_t b_main_screen;
p_vout = (vout_thread_t *)[o_value pointerValue];
p_vout->p_sys->o_window = [VLCWindow alloc];
[p_vout->p_sys->o_window setVout: p_vout];
[p_vout->p_sys->o_window setReleasedWhenClosed: YES];
if( var_Get( p_vout, "video-device", &val ) < 0 )
{
o_screen = [NSScreen mainScreen];
b_main_screen = 1;
}
else
{
NSArray *o_screens = [NSScreen screens];
unsigned int i_index = val.i_int;
if( [o_screens count] < i_index )
{
o_screen = [NSScreen mainScreen];
b_main_screen = 1;
}
else
{
i_index--;
o_screen = [o_screens objectAtIndex: i_index];
config_PutInt( p_vout, "macosx-vdev", i_index );
b_main_screen = (i_index == 0);
}
}
if( p_vout->b_fullscreen )
{
NSRect screen_rect = [o_screen frame];
screen_rect.origin.x = screen_rect.origin.y = 0;
if ( b_main_screen && p_vout->p_sys->p_fullscreen_state == NULL )
BeginFullScreen( &p_vout->p_sys->p_fullscreen_state, NULL, 0, 0,
NULL, NULL, fullScreenAllowEvents );
[p_vout->p_sys->o_window
initWithContentRect: screen_rect
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreBuffered
defer: NO screen: o_screen];
//[p_vout->p_sys->o_window setLevel: NSPopUpMenuWindowLevel - 1];
p_vout->p_sys->b_mouse_moved = YES;
p_vout->p_sys->i_time_mouse_last_moved = mdate();
}
else
{
unsigned int i_stylemask = NSTitledWindowMask |
NSMiniaturizableWindowMask |
NSClosableWindowMask |
NSResizableWindowMask;
if ( p_vout->p_sys->p_fullscreen_state != NULL )
EndFullScreen ( p_vout->p_sys->p_fullscreen_state, NULL );
p_vout->p_sys->p_fullscreen_state = NULL;
[p_vout->p_sys->o_window
initWithContentRect: p_vout->p_sys->s_rect
styleMask: i_stylemask
backing: NSBackingStoreBuffered
defer: NO screen: o_screen];
[p_vout->p_sys->o_window setAlphaValue: config_GetFloat( p_vout, "macosx-opaqueness" )];
if( config_GetInt( p_vout, "video-on-top" ) )
{
[p_vout->p_sys->o_window setLevel: NSStatusWindowLevel];
}
if( !p_vout->p_sys->b_pos_saved )
{
[p_vout->p_sys->o_window center];
}
}
if( !p_vout->p_sys->i_opengl )
{
o_view = [[VLCQTView alloc] init];
/* FIXME: [o_view setMenu:] */
[p_vout->p_sys->o_window setContentView: o_view];
[o_view autorelease];
[o_view lockFocus];
p_vout->p_sys->p_qdport = [o_view qdPort];
[o_view unlockFocus];
}
else
{
#define o_glview p_vout->p_sys->o_glview
o_glview = [[VLCGLView alloc] initWithFrame: p_vout->p_sys->s_rect vout: p_vout];
[p_vout->p_sys->o_window setContentView: o_glview];
[o_glview autorelease];
#undef o_glview
}
[p_vout->p_sys->o_window updateTitle];
[p_vout->p_sys->o_window makeKeyAndOrderFront: nil];
}
- (void)destroyWindow:(NSValue *)o_value
{
vout_thread_t * p_vout;
p_vout = (vout_thread_t *)[o_value pointerValue];
if( !p_vout->b_fullscreen )
{
NSRect s_rect;
s_rect = [[p_vout->p_sys->o_window contentView] frame];
p_vout->p_sys->s_rect.size = s_rect.size;
s_rect = [p_vout->p_sys->o_window frame];
p_vout->p_sys->s_rect.origin = s_rect.origin;
p_vout->p_sys->b_pos_saved = YES;
}
p_vout->p_sys->p_qdport = nil;
[p_vout->p_sys->o_window close];
p_vout->p_sys->o_window = nil;
}
@end
......@@ -60,6 +60,17 @@ static int SwitchIntfCallback( vlc_object_t *, char const *,
static int AddIntfCallback( vlc_object_t *, char const *,
vlc_value_t , vlc_value_t , void * );
#ifdef SYS_DARWIN
/*****************************************************************************
* VLCApplication interface
*****************************************************************************/
@interface VLCApplication : NSApplication
{
}
@end
#endif
/*****************************************************************************
* intf_Create: prepare interface before main loop
*****************************************************************************
......@@ -131,6 +142,8 @@ intf_thread_t* __intf_Create( vlc_object_t *p_this, const char *psz_module )
int intf_RunThread( intf_thread_t *p_intf )
{
#ifdef SYS_DARWIN
NSAutoreleasePool * o_pool;
if( p_intf->b_block )
{
/* This is the primary intf */
......@@ -143,28 +156,36 @@ int intf_RunThread( intf_thread_t *p_intf )
}
}