]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/intf.m
Adds support for Apple's remote (only handles Play/Pause at the moment).
[vlc] / modules / gui / macosx / intf.m
index c3852d88835689033ea5b405ae523aaf69915c64..31cf524c5699c9817f905b77d221ee37a7129f77 100644 (file)
@@ -45,6 +45,7 @@
 #include "interaction.h"
 #include "embeddedwindow.h"
 #include "update.h"
+#include "AppleRemote.h"
 
 /*****************************************************************************
  * Local prototypes.
@@ -184,9 +185,22 @@ static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
                      vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
     intf_thread_t * p_intf = VLCIntf;
-    p_intf->p_sys->b_playlist_update = TRUE;
-    p_intf->p_sys->b_intf_update = TRUE;
-    p_intf->p_sys->b_playmode_update = TRUE;
+    p_intf->p_sys->b_playlist_update = VLC_TRUE;
+    p_intf->p_sys->b_intf_update = VLC_TRUE;
+    p_intf->p_sys->b_playmode_update = VLC_TRUE;
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * ShowController: Callback triggered by the show-intf playlist variable
+ * through the ShowIntf-control-intf, to let us show the controller-win;
+ * usually when in fullscreen-mode
+ *****************************************************************************/
+static int ShowController( vlc_object_t *p_this, const char *psz_variable,
+                     vlc_value_t old_val, vlc_value_t new_val, void *param )
+{
+    intf_thread_t * p_intf = VLCIntf;
+    p_intf->p_sys->b_intf_show = VLC_TRUE;
     return VLC_SUCCESS;
 }
 
@@ -198,7 +212,7 @@ static int FullscreenChanged( vlc_object_t *p_this, const char *psz_variable,
                      vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
     intf_thread_t * p_intf = VLCIntf;
-    p_intf->p_sys->b_fullscreen_update = TRUE;
+    p_intf->p_sys->b_fullscreen_update = VLC_TRUE;
     return VLC_SUCCESS;
 }
 
@@ -330,6 +344,10 @@ static VLCMain *_o_sharedMainInstance = nil;
     o_update = [[VLCUpdate alloc] init];
 
     i_lastShownVolume = -1;
+
+    o_remote = [[AppleRemote alloc] init];
+    [o_remote setDelegate: _o_sharedMainInstance];
+    
     return _o_sharedMainInstance;
 }
 
@@ -449,6 +467,7 @@ static VLCMain *_o_sharedMainInstance = nil;
         val.b_bool = VLC_FALSE;
 
         var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);
+        var_AddCallback( p_playlist, "intf-show", ShowController, self);
 
         [o_embedded_window setFullscreen: var_GetBool( p_playlist,
                                                             "fullscreen" )];
@@ -654,15 +673,49 @@ static VLCMain *_o_sharedMainInstance = nil;
     if( psz != NULL )
     {
         o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
+
+        if ( o_str == NULL )
+        {
+            msg_Err( VLCIntf, "could not translate: %s", psz );
+            return( @"" );
+        }
     }
-    if ( o_str == NULL )
+    else
     {
-        msg_Err( VLCIntf, "could not translate: %s", psz );
+        msg_Warn( VLCIntf, "can't translate empty strings" );
+        return( @"" );
     }
 
     return( o_str );
 }
 
+/* Listen to the remote in exclusive mode, only when VLC is the active
+   application */
+- (void)applicationDidBecomeActive:(NSNotification *)aNotification
+{
+    [o_remote startListening: self];
+}
+- (void)applicationDidResignActive:(NSNotification *)aNotification
+{
+    [o_remote stopListening: self];
+}
+
+/* Apple Remote callback */
+- (void)appleRemoteButton:(AppleRemoteEventIdentifier)buttonIdentifier
+    pressedDown:(BOOL)pressedDown
+{
+    switch( buttonIdentifier )
+    {
+        case kRemoteButtonPlay:
+            [o_controls play: self];
+            break;
+
+        default:
+            /* Add here whatever you want other buttons to do */
+            break;
+    }
+}
+
 - (char *)delocalizeString:(NSString *)id
 {
     NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
@@ -922,7 +975,6 @@ static VLCMain *_o_sharedMainInstance = nil;
         return;
     }
 
-#define p_input p_intf->p_sys->p_input
     if( p_intf->p_sys->b_input_update )
     {
         /* Called when new input is opened */
@@ -944,17 +996,18 @@ static VLCMain *_o_sharedMainInstance = nil;
 
         vlc_object_release( p_playlist );
 
-        if( ( b_input = ( p_input != NULL ) ) )
+        if( ( b_input = ( p_intf->p_sys->p_input != NULL ) ) )
         {
+            vlc_object_yield( p_intf->p_sys->p_input );
             /* seekable streams */
-            var_Get( p_input, "seekable", &val);
-            b_seekable = val.b_bool;
+            b_seekable = var_GetBool( p_intf->p_sys->p_input, "seekable" );
 
             /* check wether slow/fast motion is possible*/
-            b_control = p_input->input.b_can_pace_control;
+            b_control = p_intf->p_sys->p_input->input.b_can_pace_control;
 
             /* chapters & titles */
-            //b_chapters = p_input->stream.i_area_nb > 1;
+            //b_chapters = p_intf->p_sys->p_input->stream.i_area_nb > 1;
+            vlc_object_release( p_intf->p_sys->p_input );
         }
 
         [o_btn_stop setEnabled: b_input];
@@ -994,7 +1047,14 @@ static VLCMain *_o_sharedMainInstance = nil;
         p_intf->p_sys->b_fullscreen_update = VLC_FALSE;
     }
 
-    if( p_input && !p_input->b_die )
+    if( p_intf->p_sys->b_intf_show )
+    {
+        [o_window makeKeyAndOrderFront: self];
+
+        p_intf->p_sys->b_intf_show = VLC_FALSE;
+    }
+
+    if( p_intf->p_sys->p_input && !p_intf->p_sys->p_input->b_die )
     {
         vlc_value_t val;
 
@@ -1010,13 +1070,13 @@ static VLCMain *_o_sharedMainInstance = nil;
                 return;
             }
             o_temp = [NSString stringWithUTF8String:
-                p_playlist->status.p_item->input.psz_name];
+                p_playlist->status.p_item->p_input->psz_name];
             if( o_temp == NULL )
                 o_temp = [NSString stringWithCString:
-                    p_playlist->status.p_item->input.psz_name];
+                    p_playlist->status.p_item->p_input->psz_name];
             [self setScrollField: o_temp stopAfter:-1];
 
-            p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT,
+            p_vout = vlc_object_find( p_intf->p_sys->p_input, VLC_OBJECT_VOUT,
                                                     FIND_PARENT );
             if( p_vout != NULL )
             {
@@ -1040,7 +1100,7 @@ static VLCMain *_o_sharedMainInstance = nil;
             p_intf->p_sys->b_current_title_update = FALSE;
         }
 
-        if( p_input && [o_timeslider isEnabled] )
+        if( p_intf->p_sys->p_input && [o_timeslider isEnabled] )
         {
             /* Update the slider */
             vlc_value_t time;
@@ -1049,11 +1109,11 @@ static VLCMain *_o_sharedMainInstance = nil;
             vlc_value_t pos;
             float f_updated;
 
-            var_Get( p_input, "position", &pos );
+            var_Get( p_intf->p_sys->p_input, "position", &pos );
             f_updated = 10000. * pos.f_float;
             [o_timeslider setFloatValue: f_updated];
 
-            var_Get( p_input, "time", &time );
+            var_Get( p_intf->p_sys->p_input, "time", &time );
             i_seconds = time.i_time / 1000000;
 
             o_time = [NSString stringWithFormat: @"%d:%02d:%02d",
@@ -1079,7 +1139,7 @@ static VLCMain *_o_sharedMainInstance = nil;
         }
 
         /* Manage Playing status */
-        var_Get( p_input, "state", &val );
+        var_Get( p_intf->p_sys->p_input, "state", &val );
         if( p_intf->p_sys->i_play_status != val.i_int )
         {
             p_intf->p_sys->i_play_status = val.i_int;
@@ -1096,7 +1156,6 @@ static VLCMain *_o_sharedMainInstance = nil;
         [self setSubmenusEnabled: FALSE];
     }
 
-#undef p_input
 
     [self updateMessageArray];
 
@@ -1154,10 +1213,10 @@ static VLCMain *_o_sharedMainInstance = nil;
         {
             vlc_object_t * p_dec_obj;
 
-            [o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)[VLCVoutView getRealVout: p_vout]
+            [o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
                 var: "aspect-ratio" selector: @selector(toggleVar:)];
 
-            [o_controls setupVarMenuItem: o_mi_crop target: (vlc_object_t *)[VLCVoutView getRealVout: p_vout]
+            [o_controls setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
                 var: "crop" selector: @selector(toggleVar:)];
 
             [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
@@ -1196,8 +1255,7 @@ static VLCMain *_o_sharedMainInstance = nil;
 - (void)resetScrollField
 {
     i_end_scroll = -1;
-#define p_input p_intf->p_sys->p_input
-    if( p_input && !p_input->b_die )
+    if( p_intf->p_sys->p_input && !p_intf->p_sys->p_input->b_die )
     {
         NSString *o_temp;
         playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
@@ -1207,15 +1265,14 @@ static VLCMain *_o_sharedMainInstance = nil;
             return;
         }
         o_temp = [NSString stringWithUTF8String:
-                  p_playlist->status.p_item->input.psz_name];
+                  p_playlist->status.p_item->p_input->psz_name];
         if( o_temp == NULL )
             o_temp = [NSString stringWithCString:
-                    p_playlist->status.p_item->input.psz_name];
+                    p_playlist->status.p_item->p_input->psz_name];
         [self setScrollField: o_temp stopAfter:-1];
         vlc_object_release( p_playlist );
         return;
     }
-#undef p_input
     [self setScrollField: _NS("VLC media player") stopAfter:-1];
 }