]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/vout.m
* New OSX controller (iTunes style)
[vlc] / modules / gui / macosx / vout.m
index 535a468663d8711963b9526e25df1cf9249f6619..9418d85c1cb511c15d442cbdc1d8b89c38b35343 100644 (file)
@@ -2,7 +2,7 @@
  * vout.m: MacOS X video output plugin
  *****************************************************************************
  * Copyright (C) 2001-2003 VideoLAN
- * $Id: vout.m,v 1.47 2003/05/05 22:04:11 hartman Exp $
+ * $Id: vout.m,v 1.65 2003/11/15 22:42:16 hartman Exp $
  *
  * Authors: Colin Delacroix <colin@zoy.org>
  *          Florian G. Pflug <fgp@phlo.org>
@@ -33,6 +33,8 @@
 
 #include <QuickTime/QuickTime.h>
 
+#include <vlc_keys.h>
+
 #include "intf.h"
 #include "vout.h"
 
@@ -51,6 +53,7 @@ struct picture_sys_t
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
+
 static int  vout_Init      ( vout_thread_t * );
 static void vout_End       ( vout_thread_t * );
 static int  vout_Manage    ( vout_thread_t * );
@@ -131,8 +134,7 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
     p_vout->p_sys->p_matrix = (MatrixRecordPtr)malloc( sizeof(MatrixRecord) );
     p_vout->p_sys->p_fullscreen_state = NULL;
 
-    p_vout->p_sys->b_mouse_pointer_visible = YES;
-    p_vout->p_sys->b_mouse_moved = YES;
+    p_vout->p_sys->b_mouse_moved = VLC_TRUE;
     p_vout->p_sys->i_time_mouse_last_moved = mdate();
 
     /* set window size */
@@ -148,24 +150,21 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
         return( 1 );
     } 
 
-    if( vout_ChromaCmp( p_vout->render.i_chroma, VLC_FOURCC('I','4','2','0') ) )
+    /* Damn QT isn't thread safe. so keep a lock in the p_vlc object */
+    vlc_mutex_lock( &p_vout->p_vlc->quicktime_lock );
+
+    err = FindCodec( kYUV420CodecType, bestSpeedCodec,
+                        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 )
     {
-        err = FindCodec( kYUV420CodecType, bestSpeedCodec,
-                         nil, &p_vout->p_sys->img_dc );
-        if( err == noErr && p_vout->p_sys->img_dc != 0 )
-        {
-            p_vout->output.i_chroma = VLC_FOURCC('I','4','2','0');
-            p_vout->p_sys->i_codec = kYUV420CodecType;
-        }
-        else
-        {
-            msg_Err( p_vout, "failed to find an appropriate codec" );
-        }
+        p_vout->output.i_chroma = VLC_FOURCC('I','4','2','0');
+        p_vout->p_sys->i_codec = kYUV420CodecType;
     }
     else
     {
-        msg_Err( p_vout, "chroma 0x%08x not supported",
-                         p_vout->render.i_chroma );
+        msg_Err( p_vout, "failed to find an appropriate codec" );
     }
 
     if( p_vout->p_sys->img_dc == 0 )
@@ -173,7 +172,7 @@ int E_(OpenVideo) ( vlc_object_t *p_this )
         free( p_vout->p_sys->p_matrix );
         DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
         free( p_vout->p_sys );
-        return( 1 );        
+        return VLC_EGENERIC;        
     }
 
     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
@@ -370,47 +369,19 @@ static int vout_Manage( vout_thread_t *p_vout )
      * 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( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 && 
-                   p_vout->p_sys->b_mouse_pointer_visible )
+        if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 3000000 )
         {
             VLCHideMouse( p_vout, YES );
         }
-        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 )
-            {
-                vlc_mutex_lock( &p_playlist->object_lock );
-                if( p_playlist->p_input != NULL )
-                {
-                    vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
-                    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 );
-            }
-            if ( !b_playing )
-            {
-                VLCHideMouse( p_vout, NO );
-            }
-        }
     }
     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 = NO;
-        }
+        VLCHideMouse( p_vout, NO );
     }
     
+    /* disable screen saver */
+    UpdateSystemActivity( UsrActivity );
+    
     return( 0 );
 }
 
@@ -482,10 +453,8 @@ static int CoCreateWindow( vout_thread_t *p_vout )
  *****************************************************************************/
 static int CoDestroyWindow( vout_thread_t *p_vout )
 {
-    if( !p_vout->p_sys->b_mouse_pointer_visible )
-    {
-        VLCHideMouse( p_vout, NO );
-    }
+
+    VLCHideMouse( p_vout, NO );
 
     if( CoSendRequest( p_vout, @selector(destroyWindow:) ) )
     {
@@ -552,13 +521,11 @@ static void VLCHideMouse ( vout_thread_t *p_vout, BOOL b_hide )
     if ( b_hide && b_inside )
     {
         /* only hide if mouse over VLCView */
-        [NSCursor hide];
-        p_vout->p_sys->b_mouse_pointer_visible = 0;
+        [NSCursor setHiddenUntilMouseMoves: YES];
     }
     else if ( !b_hide )
     {
-        [NSCursor unhide];
-        p_vout->p_sys->b_mouse_pointer_visible = 1;
+        [NSCursor setHiddenUntilMouseMoves: NO];
     }
     p_vout->p_sys->b_mouse_moved = NO;
     p_vout->p_sys->i_time_mouse_last_moved = mdate();
@@ -615,6 +582,7 @@ static void QTScaleMatrix( vout_thread_t *p_vout )
     TranslateMatrix( p_vout->p_sys->p_matrix, 
                      Long2Fix(i_offset_x), 
                      Long2Fix(i_offset_y) );
+
 }
 
 /*****************************************************************************
@@ -853,36 +821,52 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
 - (void)keyDown:(NSEvent *)o_event
 {
     unichar key = 0;
+    vlc_value_t val;
+    unsigned int i_pressed_modifiers = 0;
+    val.i_int = 0;
+    
+    i_pressed_modifiers = [o_event modifierFlags];
+
+    if( i_pressed_modifiers & NSShiftKeyMask )
+        val.i_int |= KEY_MODIFIER_SHIFT;
+    if( i_pressed_modifiers & NSControlKeyMask )
+        val.i_int |= KEY_MODIFIER_CTRL;
+    if( i_pressed_modifiers & NSAlternateKeyMask )
+        val.i_int |= KEY_MODIFIER_ALT;
+    if( i_pressed_modifiers & NSCommandKeyMask )
+        val.i_int |= KEY_MODIFIER_COMMAND;
 
-    if( [[o_event characters] length] )
+    key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
+
+    if( key )
     {
-        key = [[o_event characters] characterAtIndex: 0];
+        /* Escape should always get you out of fullscreen */
+        if( key == (unichar) 0x1b )
+        {
+             if( [self isFullscreen] )
+             {
+                 [self toggleFullscreen];
+             }
+        }
+        else if ( key == ' ' )
+        {
+             playlist_t *p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
+                                                     FIND_ANYWHERE );
+             if ( p_playlist != NULL )
+             {
+                 playlist_Pause( p_playlist );
+                 vlc_object_release( p_playlist);
+             }
+        }
+        else
+        {
+            val.i_int |= CocoaKeyToVLC( key );
+            var_Set( p_vout->p_vlc, "key-pressed", val );
+        }
     }
-
-    switch( key )
+    else
     {
-        case 'f': case 'F':
-            [self toggleFullscreen];
-            break;
-
-        case (unichar)0x1b: /* escape */
-            if( [self isFullscreen] )
-            {
-                [self toggleFullscreen];
-            }
-            break;
-
-        case 'q': case 'Q':
-            p_vout->p_vlc->b_die = VLC_TRUE;
-            break;
-
-        case ' ':
-            input_SetStatus( p_vout, INPUT_STATUS_PAUSE );
-            break;
-
-        default:
-            [super keyDown: o_event];
-            break;
+        [super keyDown: o_event];
     }
 }
 
@@ -899,7 +883,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
 
     vlc_mutex_lock( &p_playlist->object_lock );
     o_title = [NSMutableString stringWithUTF8String: 
-        p_playlist->pp_items[p_playlist->i_index]->psz_name]; 
+        p_playlist->pp_items[p_playlist->i_index]->psz_uri]; 
     vlc_mutex_unlock( &p_playlist->object_lock );
 
     vlc_object_release( p_playlist );
@@ -1179,13 +1163,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
         p_vout->p_sys->i_time_mouse_last_moved = mdate();
         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];
 }
 
@@ -1249,7 +1227,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
             backing: NSBackingStoreBuffered
             defer: NO screen: o_screen];
 
-        [p_vout->p_sys->o_window setLevel: NSPopUpMenuWindowLevel - 1];
+        //[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();
     }
@@ -1290,6 +1268,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
 
     [o_view lockFocus];
     p_vout->p_sys->p_qdport = [o_view qdPort];
+
     [o_view unlockFocus];
     
     [p_vout->p_sys->o_window updateTitle];