Changeset 153bf3e0e25d07ebf9b446688fae5073e2f3e026

Show
Ignore:
Timestamp:
18/03/03 23:14:42 (6 years ago)
Author:
Derk-Jan Hartman <hartman@videolan.org>
git-committer:
Derk-Jan Hartman <hartman@videolan.org> 1048025682 +0000
git-parent:

[7a508b374001d7525b1a6ccbccbcb1ddd637f943]

git-author:
Derk-Jan Hartman <hartman@videolan.org> 1048025682 +0000
Message:

* 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.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/gui/macosx/vout.m

    r8d7d0c6 r153bf3e  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001-2003 VideoLAN 
    5  * $Id: vout.m,v 1.40 2003/03/18 04:07:23 hartman Exp $ 
     5 * $Id: vout.m,v 1.41 2003/03/18 22:14:42 hartman Exp $ 
    66 * 
    77 * Authors: Colin Delacroix <colin@zoy.org> 
     
    6262static int  CoToggleFullscreen ( vout_thread_t * ); 
    6363 
    64 static void VLShowHideCursors  ( vout_thread_t *, BOOL ); 
     64static void VLCHideMouse       ( vout_thread_t *, BOOL ); 
    6565 
    6666static void QTScaleMatrix      ( vout_thread_t * ); 
     
    101101    if( NSApp == NULL ) 
    102102    { 
    103         msg_Err( p_vout, "no MacOS X interface present" ); 
     103        /* we need an NSApp to create a window from */ 
     104        msg_Err( p_vout, "no MacOS X application present" ); 
    104105        free( p_vout->p_sys ); 
    105106        return( 1 ); 
     
    131132    p_vout->p_sys->p_fullscreen_state = NULL; 
    132133 
    133     p_vout->p_sys->b_mouse_pointer_visible = 1; 
     134    p_vout->p_sys->b_mouse_pointer_visible = YES; 
     135    p_vout->p_sys->b_mouse_moved = YES; 
     136    p_vout->p_sys->i_time_mouse_last_moved = mdate(); 
    134137 
    135138    /* set window size */ 
     
    340343 *****************************************************************************/ 
    341344static int vout_Manage( vout_thread_t *p_vout ) 
    342 {     
    343     vlc_bool_t b_change = 0; 
    344     intf_thread_t * p_intf = [NSApp getIntf]; 
    345      
     345
    346346    if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE ) 
    347347    { 
     
    363363    } 
    364364 
    365     /* hide/show mouse cursor */ 
    366     if( p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen &&  
    367                         p_intf->p_sys->b_play_status ) 
     365    /* hide/show mouse cursor  
     366     * this code looks unnecessarily complicated, but is necessary like this. 
     367     * it has to deal with multiple monitors and therefore checks a lot */ 
     368    if( !p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen ) 
     369    { 
     370        if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 &&  
     371                   p_vout->p_sys->b_mouse_pointer_visible ) 
     372        { 
     373            VLCHideMouse( p_vout, YES ); 
     374        } 
     375        else if ( !p_vout->p_sys->b_mouse_pointer_visible ) 
     376        { 
     377            vlc_bool_t b_playing = NO; 
     378            playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST, 
     379                                                                    FIND_ANYWHERE ); 
     380 
     381            if ( p_playlist != nil ) 
     382            { 
     383                vlc_mutex_lock( &p_playlist->object_lock ); 
     384                if( p_playlist->p_input != NULL ) 
     385                { 
     386                    vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock ); 
     387                    b_playing = p_playlist->p_input->stream.control.i_status != PAUSE_S; 
     388                    vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock ); 
     389                } 
     390                vlc_mutex_unlock( &p_playlist->object_lock ); 
     391                vlc_object_release( p_playlist ); 
     392            } 
     393            if ( ![p_vout->p_sys->o_window isKeyWindow] || !b_playing ) 
     394            { 
     395                VLCHideMouse( p_vout, NO ); 
     396            } 
     397        } 
     398    } 
     399    else if ( p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen ) 
    368400    { 
    369401        if( !p_vout->p_sys->b_mouse_pointer_visible ) 
    370402        { 
    371             VLShowHideCursors( p_vout, NO ); 
    372             b_change = 1; 
    373         } 
    374         else if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 &&  
    375                    p_vout->p_sys->b_mouse_pointer_visible ) 
    376         { 
    377             VLShowHideCursors( p_vout, YES ); 
    378             b_change = 1; 
    379         } 
    380  
    381     } 
    382     else if ( p_vout->b_fullscreen && !p_intf->p_sys->b_play_status ) 
    383     { 
    384         if( !p_vout->p_sys->b_mouse_pointer_visible ) 
    385         { 
    386             VLShowHideCursors( p_vout, NO ); 
    387             b_change = 1; 
    388         } 
    389         else if( p_vout->p_sys->b_mouse_pointer_visible ) 
    390         { 
    391             p_vout->p_sys->i_time_mouse_last_moved = mdate(); 
    392             p_vout->p_sys->b_mouse_moved = 1; 
    393         } 
    394     } 
    395      
    396     if( b_change ) 
    397     { 
    398         p_vout->p_sys->b_mouse_moved = 0; 
    399         p_vout->p_sys->i_time_mouse_last_moved = 0; 
    400     } 
    401  
     403            VLCHideMouse( p_vout, NO ); 
     404        } 
     405        else 
     406        { 
     407            p_vout->p_sys->b_mouse_moved = NO; 
     408        } 
     409    } 
     410     
    402411    return( 0 ); 
    403412} 
     
    473482    if( !p_vout->p_sys->b_mouse_pointer_visible ) 
    474483    { 
    475         VLShowHideCursors( p_vout, NO ); 
    476         p_vout->p_sys->b_mouse_pointer_visible = 1; 
     484        VLCHideMouse( p_vout, NO ); 
    477485    } 
    478486 
     
    524532 
    525533/***************************************************************************** 
    526  * VLShowHideCursors: if b_hide then hide the cursors on every display 
    527  * that contains p_vout, else show the cursors instead. 
    528  ***************************************************************************** 
    529  * We cannot use kCGDirectMainDisplay, because this is always the display with 
    530  * the menubar. 
    531  *****************************************************************************/ 
    532 static void VLShowHideCursors ( vout_thread_t *p_vout, BOOL b_hide ) 
    533 
    534     NSRect frame; 
    535     NSScreen *o_screen; 
    536     CGDirectDisplayID displays[VL_MAX_DISPLAYS]; 
    537     CGDisplayCount displayCount; 
    538      
    539     o_screen = [p_vout->p_sys->o_window screen]; 
    540     frame = [o_screen frame]; 
    541      
    542     int err = CGGetDisplaysWithRect( CGRectMake( NSMinX( frame ), NSMinY( frame ),  
    543     NSWidth( frame ), NSHeight( frame ) ), VL_MAX_DISPLAYS, displays, &displayCount ); 
    544      
    545     if ( displayCount > 0 && !err ) 
    546     { 
    547         unsigned int i; 
    548         /* multiple displays are possible, because of mirroring. 
    549          * mirroring is essential one screen on mult. displays. */ 
    550         for ( i=0 ; i < displayCount ; i++ ) 
    551         { 
    552             if ( b_hide ) 
    553             { 
    554                 CGDisplayHideCursor( displays[i] ); 
    555                 p_vout->p_sys->b_mouse_pointer_visible = 0; 
    556             } 
    557             else 
    558             { 
    559                 CGDisplayShowCursor( displays[i] ); 
    560                 p_vout->p_sys->b_mouse_pointer_visible = 1; 
    561             } 
    562         } 
    563     } 
     534 * VLCHideMouse: if b_hide then hide the cursor 
     535 *****************************************************************************/ 
     536static void VLCHideMouse ( vout_thread_t *p_vout, BOOL b_hide ) 
     537
     538    BOOL b_inside; 
     539    NSRect s_rect; 
     540    NSPoint ml; 
     541    NSWindow *o_window = p_vout->p_sys->o_window; 
     542    NSView *o_contents = [o_window contentView]; 
     543     
     544    s_rect = [o_contents bounds]; 
     545    ml = [o_window convertScreenToBase:[NSEvent mouseLocation]]; 
     546    ml = [o_contents convertPoint:ml fromView:nil]; 
     547    b_inside = [o_contents mouse: ml inRect: s_rect]; 
     548     
     549    if ( b_hide && b_inside ) 
     550    { 
     551        /* only hide if mouse over VLCView */ 
     552        [NSCursor hide]; 
     553        p_vout->p_sys->b_mouse_pointer_visible = 0; 
     554    } 
     555    else if ( !b_hide ) 
     556    { 
     557        if ( ![o_window isKeyWindow] && b_inside ) 
     558        { 
     559            /* be nice for ppl with multi monitors */ 
     560            p_vout->p_sys->b_mouse_moved = NO; 
     561            p_vout->p_sys->i_time_mouse_last_moved = mdate(); 
     562            return; 
     563        } 
     564        [NSCursor unhide]; 
     565        p_vout->p_sys->b_mouse_pointer_visible = 1; 
     566    } 
     567    p_vout->p_sys->b_mouse_moved = NO; 
     568    p_vout->p_sys->i_time_mouse_last_moved = mdate(); 
    564569    return; 
    565570} 
     
    875880{ 
    876881    NSMutableString * o_title; 
    877  
    878     intf_thread_t * p_intf = [NSApp getIntf]; 
    879     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
     882    playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST, 
    880883                                                       FIND_ANYWHERE ); 
    881884     
     
    912915- (BOOL)windowShouldClose:(id)sender 
    913916{ 
    914     intf_thread_t * p_intf = [NSApp getIntf]; 
    915     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
     917    playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST, 
    916918                                                       FIND_ANYWHERE ); 
    917919    if( p_playlist == NULL )       
     
    954956- (BOOL)becomeFirstResponder 
    955957{ 
    956     [[self window] setAcceptsMouseMovedEvents: YES]; 
     958    vout_thread_t * p_vout; 
     959    id o_window = [self window]; 
     960    p_vout = (vout_thread_t *)[o_window getVout]; 
     961     
     962    [o_window setAcceptsMouseMovedEvents: YES]; 
    957963    return( YES ); 
    958964} 
     
    960966- (BOOL)resignFirstResponder 
    961967{ 
    962     [[self window] setAcceptsMouseMovedEvents: NO]; 
     968    vout_thread_t * p_vout; 
     969    id o_window = [self window]; 
     970    p_vout = (vout_thread_t *)[o_window getVout]; 
     971     
     972    [o_window setAcceptsMouseMovedEvents: NO]; 
     973    VLCHideMouse( p_vout, NO ); 
    963974    return( YES ); 
    964975} 
     
    11561167        val.b_bool = VLC_TRUE; 
    11571168        var_Set( p_vout, "mouse-moved", val ); 
    1158     } 
    1159     p_vout->p_sys->i_time_mouse_last_moved = mdate(); 
    1160     p_vout->p_sys->b_mouse_moved = 1; 
     1169        p_vout->p_sys->i_time_mouse_last_moved = mdate(); 
     1170        p_vout->p_sys->b_mouse_moved = YES; 
     1171    } 
     1172    else if ( !b_inside && !p_vout->p_sys->b_mouse_pointer_visible ) 
     1173    { 
     1174        /* people with multiple monitors need their mouse, 
     1175         * even if VLCView in fullscreen. */ 
     1176        VLCHideMouse( p_vout, NO ); 
     1177    } 
     1178     
    11611179    [super mouseMoved: o_event]; 
    11621180}