Commit 153bf3e0 authored by Derk-Jan Hartman's avatar Derk-Jan Hartman

* modules/gui/macosx/vout.m:

  Now a complete redesign of the hiding of the mousecursor.
  - We use higher level functions now (NSCursor).
  - We only hide if the cursor is over our VLCView
  - In many exceptions we unhide. This is mainly for multimonitor support.
parent 7a508b37
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* vout.m: MacOS X video output plugin * vout.m: MacOS X video output plugin
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2003 VideoLAN * Copyright (C) 2001-2003 VideoLAN
* $Id: vout.m,v 1.40 2003/03/18 04:07:23 hartman Exp $ * $Id: vout.m,v 1.41 2003/03/18 22:14:42 hartman Exp $
* *
* Authors: Colin Delacroix <colin@zoy.org> * Authors: Colin Delacroix <colin@zoy.org>
* Florian G. Pflug <fgp@phlo.org> * Florian G. Pflug <fgp@phlo.org>
...@@ -61,7 +61,7 @@ static int CoCreateWindow ( vout_thread_t * ); ...@@ -61,7 +61,7 @@ static int CoCreateWindow ( vout_thread_t * );
static int CoDestroyWindow ( vout_thread_t * ); static int CoDestroyWindow ( vout_thread_t * );
static int CoToggleFullscreen ( vout_thread_t * ); static int CoToggleFullscreen ( vout_thread_t * );
static void VLShowHideCursors ( vout_thread_t *, BOOL ); static void VLCHideMouse ( vout_thread_t *, BOOL );
static void QTScaleMatrix ( vout_thread_t * ); static void QTScaleMatrix ( vout_thread_t * );
static int QTCreateSequence ( vout_thread_t * ); static int QTCreateSequence ( vout_thread_t * );
...@@ -100,7 +100,8 @@ int E_(OpenVideo) ( vlc_object_t *p_this ) ...@@ -100,7 +100,8 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
if( NSApp == NULL ) if( NSApp == NULL )
{ {
msg_Err( p_vout, "no MacOS X interface present" ); /* we need an NSApp to create a window from */
msg_Err( p_vout, "no MacOS X application present" );
free( p_vout->p_sys ); free( p_vout->p_sys );
return( 1 ); return( 1 );
} }
...@@ -130,7 +131,9 @@ int E_(OpenVideo) ( vlc_object_t *p_this ) ...@@ -130,7 +131,9 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
p_vout->p_sys->p_matrix = (MatrixRecordPtr)malloc( sizeof(MatrixRecord) ); p_vout->p_sys->p_matrix = (MatrixRecordPtr)malloc( sizeof(MatrixRecord) );
p_vout->p_sys->p_fullscreen_state = NULL; p_vout->p_sys->p_fullscreen_state = NULL;
p_vout->p_sys->b_mouse_pointer_visible = 1; p_vout->p_sys->b_mouse_pointer_visible = YES;
p_vout->p_sys->b_mouse_moved = YES;
p_vout->p_sys->i_time_mouse_last_moved = mdate();
/* set window size */ /* set window size */
p_vout->p_sys->s_rect.size.width = p_vout->i_window_width; p_vout->p_sys->s_rect.size.width = p_vout->i_window_width;
...@@ -340,9 +343,6 @@ void E_(CloseVideo) ( vlc_object_t *p_this ) ...@@ -340,9 +343,6 @@ void E_(CloseVideo) ( vlc_object_t *p_this )
*****************************************************************************/ *****************************************************************************/
static int vout_Manage( vout_thread_t *p_vout ) static int vout_Manage( vout_thread_t *p_vout )
{ {
vlc_bool_t b_change = 0;
intf_thread_t * p_intf = [NSApp getIntf];
if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE ) if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
{ {
if( CoToggleFullscreen( p_vout ) ) if( CoToggleFullscreen( p_vout ) )
...@@ -362,41 +362,50 @@ static int vout_Manage( vout_thread_t *p_vout ) ...@@ -362,41 +362,50 @@ static int vout_Manage( vout_thread_t *p_vout )
p_vout->i_changes &= ~VOUT_SIZE_CHANGE; p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
} }
/* hide/show mouse cursor */ /* hide/show mouse cursor
if( p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen && * this code looks unnecessarily complicated, but is necessary like this.
p_intf->p_sys->b_play_status ) * it has to deal with multiple monitors and therefore checks a lot */
if( !p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen )
{ {
if( !p_vout->p_sys->b_mouse_pointer_visible ) if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 &&
{
VLShowHideCursors( p_vout, NO );
b_change = 1;
}
else if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 &&
p_vout->p_sys->b_mouse_pointer_visible ) p_vout->p_sys->b_mouse_pointer_visible )
{ {
VLShowHideCursors( p_vout, YES ); VLCHideMouse( p_vout, YES );
b_change = 1;
} }
else if ( !p_vout->p_sys->b_mouse_pointer_visible )
{
vlc_bool_t b_playing = NO;
playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
} if ( p_playlist != nil )
else if ( p_vout->b_fullscreen && !p_intf->p_sys->b_play_status )
{ {
if( !p_vout->p_sys->b_mouse_pointer_visible ) vlc_mutex_lock( &p_playlist->object_lock );
if( p_playlist->p_input != NULL )
{ {
VLShowHideCursors( p_vout, NO ); vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
b_change = 1; b_playing = p_playlist->p_input->stream.control.i_status != PAUSE_S;
vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
}
vlc_mutex_unlock( &p_playlist->object_lock );
vlc_object_release( p_playlist );
} }
else if( p_vout->p_sys->b_mouse_pointer_visible ) if ( ![p_vout->p_sys->o_window isKeyWindow] || !b_playing )
{ {
p_vout->p_sys->i_time_mouse_last_moved = mdate(); VLCHideMouse( p_vout, NO );
p_vout->p_sys->b_mouse_moved = 1;
} }
} }
}
if( b_change ) else if ( p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen )
{
if( !p_vout->p_sys->b_mouse_pointer_visible )
{
VLCHideMouse( p_vout, NO );
}
else
{ {
p_vout->p_sys->b_mouse_moved = 0; p_vout->p_sys->b_mouse_moved = NO;
p_vout->p_sys->i_time_mouse_last_moved = 0; }
} }
return( 0 ); return( 0 );
...@@ -472,8 +481,7 @@ static int CoDestroyWindow( vout_thread_t *p_vout ) ...@@ -472,8 +481,7 @@ static int CoDestroyWindow( vout_thread_t *p_vout )
{ {
if( !p_vout->p_sys->b_mouse_pointer_visible ) if( !p_vout->p_sys->b_mouse_pointer_visible )
{ {
VLShowHideCursors( p_vout, NO ); VLCHideMouse( p_vout, NO );
p_vout->p_sys->b_mouse_pointer_visible = 1;
} }
if( CoSendRequest( p_vout, @selector(destroyWindow:) ) ) if( CoSendRequest( p_vout, @selector(destroyWindow:) ) )
...@@ -523,44 +531,41 @@ static int CoToggleFullscreen( vout_thread_t *p_vout ) ...@@ -523,44 +531,41 @@ static int CoToggleFullscreen( vout_thread_t *p_vout )
} }
/***************************************************************************** /*****************************************************************************
* VLShowHideCursors: if b_hide then hide the cursors on every display * VLCHideMouse: if b_hide then hide the cursor
* that contains p_vout, else show the cursors instead.
*****************************************************************************
* We cannot use kCGDirectMainDisplay, because this is always the display with
* the menubar.
*****************************************************************************/ *****************************************************************************/
static void VLShowHideCursors ( vout_thread_t *p_vout, BOOL b_hide ) static void VLCHideMouse ( vout_thread_t *p_vout, BOOL b_hide )
{ {
NSRect frame; BOOL b_inside;
NSScreen *o_screen; NSRect s_rect;
CGDirectDisplayID displays[VL_MAX_DISPLAYS]; NSPoint ml;
CGDisplayCount displayCount; NSWindow *o_window = p_vout->p_sys->o_window;
NSView *o_contents = [o_window contentView];
o_screen = [p_vout->p_sys->o_window screen];
frame = [o_screen frame];
int err = CGGetDisplaysWithRect( CGRectMake( NSMinX( frame ), NSMinY( frame ), s_rect = [o_contents bounds];
NSWidth( frame ), NSHeight( frame ) ), VL_MAX_DISPLAYS, displays, &displayCount ); ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
ml = [o_contents convertPoint:ml fromView:nil];
b_inside = [o_contents mouse: ml inRect: s_rect];
if ( displayCount > 0 && !err ) if ( b_hide && b_inside )
{
unsigned int i;
/* multiple displays are possible, because of mirroring.
* mirroring is essential one screen on mult. displays. */
for ( i=0 ; i < displayCount ; i++ )
{
if ( b_hide )
{ {
CGDisplayHideCursor( displays[i] ); /* only hide if mouse over VLCView */
[NSCursor hide];
p_vout->p_sys->b_mouse_pointer_visible = 0; p_vout->p_sys->b_mouse_pointer_visible = 0;
} }
else else if ( !b_hide )
{ {
CGDisplayShowCursor( displays[i] ); if ( ![o_window isKeyWindow] && b_inside )
p_vout->p_sys->b_mouse_pointer_visible = 1; {
} /* be nice for ppl with multi monitors */
p_vout->p_sys->b_mouse_moved = NO;
p_vout->p_sys->i_time_mouse_last_moved = mdate();
return;
} }
[NSCursor unhide];
p_vout->p_sys->b_mouse_pointer_visible = 1;
} }
p_vout->p_sys->b_mouse_moved = NO;
p_vout->p_sys->i_time_mouse_last_moved = mdate();
return; return;
} }
...@@ -874,9 +879,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -874,9 +879,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
- (void)updateTitle - (void)updateTitle
{ {
NSMutableString * o_title; NSMutableString * o_title;
playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
intf_thread_t * p_intf = [NSApp getIntf];
playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE ); FIND_ANYWHERE );
if( p_playlist == NULL ) if( p_playlist == NULL )
...@@ -911,8 +914,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -911,8 +914,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
/* This is actually the same as VLCControls::stop. */ /* This is actually the same as VLCControls::stop. */
- (BOOL)windowShouldClose:(id)sender - (BOOL)windowShouldClose:(id)sender
{ {
intf_thread_t * p_intf = [NSApp getIntf]; playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE ); FIND_ANYWHERE );
if( p_playlist == NULL ) if( p_playlist == NULL )
{ {
...@@ -953,13 +955,22 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -953,13 +955,22 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
- (BOOL)becomeFirstResponder - (BOOL)becomeFirstResponder
{ {
[[self window] setAcceptsMouseMovedEvents: YES]; vout_thread_t * p_vout;
id o_window = [self window];
p_vout = (vout_thread_t *)[o_window getVout];
[o_window setAcceptsMouseMovedEvents: YES];
return( YES ); return( YES );
} }
- (BOOL)resignFirstResponder - (BOOL)resignFirstResponder
{ {
[[self window] setAcceptsMouseMovedEvents: NO]; vout_thread_t * p_vout;
id o_window = [self window];
p_vout = (vout_thread_t *)[o_window getVout];
[o_window setAcceptsMouseMovedEvents: NO];
VLCHideMouse( p_vout, NO );
return( YES ); return( YES );
} }
...@@ -1155,9 +1166,16 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1155,9 +1166,16 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
val.b_bool = VLC_TRUE; val.b_bool = VLC_TRUE;
var_Set( p_vout, "mouse-moved", val ); var_Set( p_vout, "mouse-moved", val );
}
p_vout->p_sys->i_time_mouse_last_moved = mdate(); p_vout->p_sys->i_time_mouse_last_moved = mdate();
p_vout->p_sys->b_mouse_moved = 1; p_vout->p_sys->b_mouse_moved = YES;
}
else if ( !b_inside && !p_vout->p_sys->b_mouse_pointer_visible )
{
/* people with multiple monitors need their mouse,
* even if VLCView in fullscreen. */
VLCHideMouse( p_vout, NO );
}
[super mouseMoved: o_event]; [super mouseMoved: o_event];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment