]> git.sesse.net Git - vlc/blobdiff - modules/control/hotkeys.c
Core implementation of --[no]-autoscale and --scale with x11 vout support
[vlc] / modules / control / hotkeys.c
index 68161c316da687b03575febb21e3bf91211b0798..bdb4ce1ded5d1e62cbb545c266c0bd08c2cfb7da 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * hotkeys.c: Hotkey handling for vlc
  *****************************************************************************
- * Copyright (C) 2005 the VideoLAN team
+ * Copyright (C) 2005-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
@@ -95,12 +95,12 @@ static void ClearChannels  ( intf_thread_t *, vout_thread_t * );
 #define BOOKMARK10_TEXT   N_("Playlist bookmark 10")
 #define BOOKMARK_LONGTEXT N_("Define playlist bookmarks.")
 
-vlc_module_begin();
-    set_shortname( N_("Hotkeys") );
-    set_description( N_("Hotkeys management interface") );
-    set_capability( "interface", 0 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_shortname( N_("Hotkeys") )
+    set_description( N_("Hotkeys management interface") )
+    set_capability( "interface", 0 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 /*****************************************************************************
  * Open: initialize interface
@@ -109,7 +109,9 @@ static int Open( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
     intf_sys_t *p_sys;
-    MALLOC_ERR( p_sys, intf_sys_t );
+    p_sys = malloc( sizeof( intf_sys_t ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
 
     p_intf->p_sys = p_sys;
     p_intf->pf_run = Run;
@@ -174,11 +176,7 @@ static void Run( intf_thread_t *p_intf )
         canc = vlc_savecancel();
 
         /* Update the input */
-        PL_LOCK;
-        p_input = p_playlist->p_input;
-        if( p_input )
-            vlc_object_hold( p_input );
-        PL_UNLOCK;
+        p_input = playlist_CurrentInput( p_playlist );
 
         /* Update the vout */
         p_last_vout = p_vout;
@@ -197,10 +195,8 @@ static void Run( intf_thread_t *p_intf )
         /* Quit */
         if( i_action == ACTIONID_QUIT )
         {
-            if( p_playlist )
-                playlist_Stop( p_playlist );
-            vlc_object_kill( p_intf->p_libvlc );
-            vlc_object_kill( p_intf );
+            libvlc_Quit( p_intf->p_libvlc );
+
             ClearChannels( p_intf, p_vout );
             vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Quit" ) );
             if( p_vout )
@@ -413,7 +409,7 @@ static void Run( intf_thread_t *p_intf )
         /* Input options */
         else if( p_input )
         {
-            bool b_seekable = var_GetBool( p_input, "seekable" );
+            bool b_seekable = var_GetBool( p_input, "can-seek" );
             int i_interval =0;
 
             if( i_action == ACTIONID_PAUSE )
@@ -613,6 +609,45 @@ static void Run( intf_thread_t *p_intf )
                 }
                 free( val.psz_string );
             }
+            else if( i_action == ACTIONID_TOGGLE_AUTOSCALE && p_vout )
+            {
+                float f_scalefactor = var_GetFloat( p_vout, "scale" );
+                if ( f_scalefactor != 1.0 )
+                {
+                    var_SetFloat( p_vout, "scale", 1.0 );
+                    vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
+                                         _("Zooming reset") );
+                }
+                else
+                {
+                    bool b_autoscale = !var_GetBool( p_vout, "autoscale" );
+                    var_SetBool( p_vout, "autoscale", b_autoscale );
+                    if( b_autoscale )
+                        vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
+                                         _("Scaled to screen") );
+                    else
+                        vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
+                                         _("Original Size") );
+                }
+            }
+            else if( i_action == ACTIONID_SCALE_UP && p_vout )
+            {
+               float f_scalefactor;
+
+               f_scalefactor = var_GetFloat( p_vout, "scale" );
+               if( f_scalefactor < 10. )
+                   f_scalefactor += .1;
+               var_SetFloat( p_vout, "scale", f_scalefactor );
+            }
+            else if( i_action == ACTIONID_SCALE_DOWN && p_vout )
+            {
+               float f_scalefactor;
+
+               f_scalefactor = var_GetFloat( p_vout, "scale" );
+               if( f_scalefactor > .3 )
+                   f_scalefactor -= .1;
+               var_SetFloat( p_vout, "scale", f_scalefactor );
+            }
             else if( i_action == ACTIONID_DEINTERLACE && p_vout )
             {
                 vlc_value_t val={0}, val_list, text_list;
@@ -704,6 +739,12 @@ static void Run( intf_thread_t *p_intf )
             {
                 playlist_Stop( p_playlist );
             }
+            else if( i_action == ACTIONID_FRAME_NEXT )
+            {
+                var_SetVoid( p_input, "frame-next" );
+                vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
+                                 _("Next frame") );
+            }
             else if( i_action == ACTIONID_FASTER )
             {
                 var_SetVoid( p_input, "rate-faster" );
@@ -945,15 +986,13 @@ static int ActionEvent( vlc_object_t *libvlc, char const *psz_var,
 
 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
 {
-    vlc_value_t val;
-    char psz_bookmark_name[11];
-    playlist_t *p_playlist = pl_Hold( p_intf );
+    char *psz_bookmark_name;
+    if( asprintf( &psz_bookmark_name, "bookmark%i", i_num ) == -1 )
+        return;
 
-    sprintf( psz_bookmark_name, "bookmark%i", i_num );
-    var_Create( p_intf, psz_bookmark_name, VLC_VAR_STRING|VLC_VAR_DOINHERIT );
-    var_Get( p_intf, psz_bookmark_name, &val );
+    playlist_t *p_playlist = pl_Hold( p_intf );
+    char *psz_bookmark = var_CreateGetString( p_intf, psz_bookmark_name );
 
-    char *psz_bookmark = strdup( val.psz_string );
     PL_LOCK;
     FOREACH_ARRAY( playlist_item_t *p_item, p_playlist->items )
         char *psz_uri = input_item_GetURI( p_item->p_input );
@@ -968,25 +1007,33 @@ static void PlayBookmark( intf_thread_t *p_intf, int i_num )
             free( psz_uri );
     FOREACH_END();
     PL_UNLOCK;
-    vlc_object_release( p_playlist );
+
+    free( psz_bookmark );
+    free( psz_bookmark_name );
+    pl_Release( p_intf );
 }
 
 static void SetBookmark( intf_thread_t *p_intf, int i_num )
 {
+    char *psz_bookmark_name;
+    if( asprintf( &psz_bookmark_name, "bookmark%i", i_num ) == -1 )
+        return;
+
     playlist_t *p_playlist = pl_Hold( p_intf );
-    char psz_bookmark_name[11];
-    sprintf( psz_bookmark_name, "bookmark%i", i_num );
     var_Create( p_intf, psz_bookmark_name,
                 VLC_VAR_STRING|VLC_VAR_DOINHERIT );
-    if( p_playlist->status.p_item )
+    playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
+    if( p_item )
     {
-        char *psz_uri = input_item_GetURI( p_playlist->status.p_item->p_input );
+        char *psz_uri = input_item_GetURI( p_item->p_input );
         config_PutPsz( p_intf, psz_bookmark_name, psz_uri);
         msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num, psz_uri);
         free( psz_uri );
         config_SaveConfigFile( p_intf, "hotkeys" );
     }
+
     pl_Release( p_intf );
+    free( psz_bookmark_name );
 }
 
 static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
@@ -1017,7 +1064,7 @@ static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, psz_time );
     }
 
-    if( !p_vout->p_window || p_vout->b_fullscreen )
+    if( p_vout->b_fullscreen )
     {
         var_Get( p_input, "position", &pos );
         vout_OSDSlider( VLC_OBJECT( p_input ), POSITION_WIDGET_CHAN,
@@ -1034,7 +1081,7 @@ static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
     }
     ClearChannels( p_intf, p_vout );
 
-    if( !p_vout->p_window || p_vout->b_fullscreen )
+    if( p_vout->b_fullscreen )
     {
         vout_OSDSlider( VLC_OBJECT( p_vout ), VOLUME_WIDGET_CHAN,
             i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );