]> git.sesse.net Git - vlc/blobdiff - modules/control/hotkeys.c
Missing return values.
[vlc] / modules / control / hotkeys.c
index 817fd0a6284100fd924df150c7820752c904fa30..0d77fab74a68a4c0b5e168cf9aa848c322562c71 100644 (file)
@@ -38,7 +38,7 @@
 #include <vlc_aout.h>
 #include <vlc_osd.h>
 #include <vlc_playlist.h>
-#include "vlc_keys.h"
+#include <vlc_keys.h>
 #include "math.h"
 
 #define CHANNELS_NUMBER 4
@@ -121,7 +121,7 @@ static int Open( vlc_object_t *p_this )
 
     p_sys->p_last_vout = NULL;
     p_intf->p_sys->i_mousewheel_mode =
-        config_GetInt( p_intf, "hotkeys-mousewheel-mode" );
+        var_InheritInteger( p_intf, "hotkeys-mousewheel-mode" );
 
     var_AddCallback( p_intf->p_libvlc, "key-pressed", SpecialKeyEvent, p_intf );
     var_AddCallback( p_intf->p_libvlc, "key-action", ActionEvent, p_intf );
@@ -146,7 +146,7 @@ static void Close( vlc_object_t *p_this )
 static int PutAction( intf_thread_t *p_intf, int i_action )
 {
     intf_sys_t *p_sys = p_intf->p_sys;
-    playlist_t *p_playlist = pl_Hold( p_intf );
+    playlist_t *p_playlist = pl_Get( p_intf );
 
     /* Update the input */
     input_thread_t *p_input = playlist_CurrentInput( p_playlist );
@@ -181,7 +181,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
         case ACTIONID_VOL_UP:
         {
             audio_volume_t i_newvol;
-            aout_VolumeUp( p_intf, 1, &i_newvol );
+            aout_VolumeUp( p_playlist, 1, &i_newvol );
             DisplayVolume( p_intf, p_vout, i_newvol );
             break;
         }
@@ -189,7 +189,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
         case ACTIONID_VOL_DOWN:
         {
             audio_volume_t i_newvol;
-            aout_VolumeDown( p_intf, 1, &i_newvol );
+            aout_VolumeDown( p_playlist, 1, &i_newvol );
             DisplayVolume( p_intf, p_vout, i_newvol );
             break;
         }
@@ -197,7 +197,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
         case ACTIONID_VOL_MUTE:
         {
             audio_volume_t i_newvol = -1;
-            aout_VolumeMute( p_intf, &i_newvol );
+            aout_ToggleMute( p_playlist, &i_newvol );
             if( p_vout )
             {
                 if( i_newvol == 0 )
@@ -229,16 +229,16 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
 
         case ACTIONID_TOGGLE_FULLSCREEN:
         {
-            vlc_object_t *obj = p_vout ? VLC_OBJECT(p_vout)
-                                       : VLC_OBJECT(p_playlist);
-            bool b = var_GetBool( obj, "fullscreen" );
-            var_SetBool( obj, "fullscreen", !b );
+            bool fs = var_ToggleBool( p_playlist, "fullscreen" );
+            if( p_vout )
+                var_SetBool( p_vout, "fullscreen", fs );
             break;
         }
 
         case ACTIONID_LEAVE_FULLSCREEN:
-            if( p_vout && var_GetBool( p_vout, "fullscreen" ) )
+            if( p_vout )
                 var_SetBool( p_vout, "fullscreen", false );
+            var_SetBool( p_playlist, "fullscreen", false );
             break;
 
         case ACTIONID_ZOOM_QUARTER:
@@ -260,15 +260,13 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             }
             break;
 
-#ifdef WIN32
         case ACTIONID_WALLPAPER:
         {   /* FIXME: this is invalid if not using DirectX output!!! */
             vlc_object_t *obj = p_vout ? VLC_OBJECT(p_vout)
                                        : VLC_OBJECT(p_playlist);
-            bool b = var_GetBool( obj, "directx-wallpaper" );
-            var_SetBool( obj, "directx-wallpaper", !b );
+            var_ToggleBool( obj, "video-wallpaper" );
+            break;
         }
-#endif
 
         /* Playlist actions */
         case ACTIONID_LOOP:
@@ -287,8 +285,8 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
 
         case ACTIONID_RANDOM:
         {
-            bool b = var_GetBool( p_playlist, "random" );
-            var_SetBool( p_playlist, "random", !b );
+            var_ToggleBool( p_playlist, "random" );
+            break;
         }
 
         case ACTIONID_PLAY_PAUSE:
@@ -388,7 +386,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
                      && b_seekable )
             {
 #define SET_TIME( a, b ) \
-    i_interval = config_GetInt( p_input, a "-jump-size" ); \
+    i_interval = var_InheritInteger( p_input, a "-jump-size" ); \
     if( i_interval > 0 ) { \
         mtime_t i_time = (mtime_t)(i_interval * b) * 1000000L; \
         var_SetTime( p_input, "time-offset", i_time ); \
@@ -597,31 +595,37 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             }
             else if( i_action == ACTIONID_DEINTERLACE && p_vout )
             {
-                vlc_value_t val={0}, val_list, text_list;
-                var_Get( p_vout, "deinterlace", &val );
-                if( var_Change( p_vout, "deinterlace", VLC_VAR_GETLIST,
-                                &val_list, &text_list ) >= 0 )
+                int i_deinterlace = var_GetInteger( p_vout, "deinterlace" );
+                if( i_deinterlace != 0 )
                 {
-                    int i;
-                    for( i = 0; i < val_list.p_list->i_count; i++ )
+                    var_SetInteger( p_vout, "deinterlace", 0 );
+                    vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
+                                     "%s", _("Deinterlace off") );
+                }
+                else
+                {
+                    var_SetInteger( p_vout, "deinterlace", 1 );
+
+                    char *psz_mode = var_GetString( p_vout, "deinterlace-mode" );
+                    vlc_value_t vlist, tlist;
+                    if( psz_mode && !var_Change( p_vout, "deinterlace-mode", VLC_VAR_GETCHOICES, &vlist, &tlist ) >= 0 )
                     {
-                        if( !strcmp( val_list.p_list->p_values[i].psz_string,
-                                     val.psz_string ) )
+                        const char *psz_text = NULL;
+                        for( int i = 0; i < vlist.p_list->i_count; i++ )
                         {
-                            i++;
-                            break;
+                            if( !strcmp( vlist.p_list->p_values[i].psz_string, psz_mode ) )
+                            {
+                                psz_text = tlist.p_list->p_values[i].psz_string;
+                                break;
+                            }
                         }
-                    }
-                    if( i == val_list.p_list->i_count ) i = 0;
-                    var_SetString( p_vout, "deinterlace",
-                                   val_list.p_list->p_values[i].psz_string );
-                    vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
-                                     _("Deinterlace mode: %s"),
-                                     text_list.p_list->p_values[i].psz_string );
+                        vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
+                                         "%s (%s)", _("Deinterlace on"), psz_text ? psz_text : psz_mode );
 
-                    var_FreeList( &val_list, &text_list );
+                        var_FreeList( &vlist, &tlist );
+                    }
+                    free( psz_mode );
                 }
-                free( val.psz_string );
             }
             else if( ( i_action == ACTIONID_ZOOM ||
                        i_action == ACTIONID_UNZOOM ) && p_vout )
@@ -650,7 +654,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
                                   val_list.p_list->p_values[i].f_float );
                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
                                      _("Zoom mode: %s"),
-                                text_list.p_list->p_values[i].var.psz_name );
+                                text_list.p_list->p_values[i].psz_string );
 
                     var_FreeList( &val_list, &text_list );
                 }
@@ -689,58 +693,55 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             }
             else if( i_action == ACTIONID_FRAME_NEXT )
             {
-                var_SetVoid( p_input, "frame-next" );
+                var_TriggerCallback( p_input, "frame-next" );
                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
                                  "%s", _("Next frame") );
             }
             else if( i_action == ACTIONID_FASTER )
             {
-                var_SetVoid( p_input, "rate-faster" );
+                var_TriggerCallback( p_input, "rate-faster" );
                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
                                  "%s", _("Faster") );
             }
             else if( i_action == ACTIONID_SLOWER )
             {
-                var_SetVoid( p_input, "rate-slower" );
+                var_TriggerCallback( p_input, "rate-slower" );
                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
                                  "%s", _("Slower") );
             }
             else if( i_action == ACTIONID_RATE_NORMAL )
             {
-                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
+                var_SetFloat( p_input, "rate", 1. );
                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
                                  "%s", _("1.00x") );
             }
             else if( i_action == ACTIONID_RATE_FASTER_FINE ||
                      i_action == ACTIONID_RATE_SLOWER_FINE )
             {
-                /* The playback rate is defined by INPUT_RATE_DEFAULT / "rate"
-                 * and we want to increase/decrease it by 0.1 while making sure
-                 * that the resulting playback rate is a multiple of 0.1
-                 */
-                int i_rate = var_GetInteger( p_input, "rate" );
-                if( i_rate == 0 )
-                    i_rate = INPUT_RATE_MIN;
-                int i_sign = i_rate < 0 ? -1 : 1;
-                const int i_dir = i_action == ACTIONID_RATE_FASTER_FINE ? 1 : -1;
+                const double f_rate_min = (double)INPUT_RATE_DEFAULT / INPUT_RATE_MAX;
+                const double f_rate_max = (double)INPUT_RATE_DEFAULT / INPUT_RATE_MIN;
+                double f_rate = var_GetFloat( p_input, "rate" );
 
-                const double f_speed = floor( ( (double)INPUT_RATE_DEFAULT / abs(i_rate) + 0.05 ) / 0.1 + i_dir ) * 0.1;
-                if( f_speed <= (double)INPUT_RATE_DEFAULT / INPUT_RATE_MAX ) /* Needed to avoid infinity */
-                    i_rate = INPUT_RATE_MAX;
-                else
-                    i_rate = INPUT_RATE_DEFAULT / f_speed + 0.5;
+                int i_sign = f_rate < 0 ? -1 : 1;
+                const int i_dir = i_action == ACTIONID_RATE_FASTER_FINE ? 1 : -1;
 
-                i_rate = i_sign * __MIN( __MAX( i_rate, INPUT_RATE_MIN ), INPUT_RATE_MAX );
+                f_rate = floor( fabs(f_rate) / 0.1 + i_dir ) * 0.1;
+                if( f_rate < f_rate_min )
+                    f_rate = f_rate_min;
+                else if( f_rate > f_rate_max )
+                    f_rate = f_rate_max;
+                f_rate *= i_sign;
 
-                var_SetInteger( p_input, "rate", i_rate );
+                var_SetFloat( p_input, "rate", f_rate );
 
                 char psz_msg[7+1];
-                snprintf( psz_msg, sizeof(psz_msg), _("%.2fx"), (double)INPUT_RATE_DEFAULT / i_rate );
+                snprintf( psz_msg, sizeof(psz_msg), _("%.2fx"), f_rate );
                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, "%s", psz_msg );
             }
-            else if( i_action == ACTIONID_POSITION && b_seekable )
+            else if( i_action == ACTIONID_POSITION )
             {
-                DisplayPosition( p_intf, p_vout, p_input );
+                if( ( !p_vout || vout_OSDEpg( p_vout, input_GetItem( p_input ) ) ) && b_seekable )
+                    DisplayPosition( p_intf, p_vout, p_input );
             }
             else if( i_action >= ACTIONID_PLAY_BOOKMARK1 &&
                      i_action <= ACTIONID_PLAY_BOOKMARK10 )
@@ -754,13 +755,13 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             }
             /* Only makes sense with DVD */
             else if( i_action == ACTIONID_TITLE_PREV )
-                var_SetVoid( p_input, "prev-title" );
+                var_TriggerCallback( p_input, "prev-title" );
             else if( i_action == ACTIONID_TITLE_NEXT )
-                var_SetVoid( p_input, "next-title" );
+                var_TriggerCallback( p_input, "next-title" );
             else if( i_action == ACTIONID_CHAPTER_PREV )
-                var_SetVoid( p_input, "prev-chapter" );
+                var_TriggerCallback( p_input, "prev-chapter" );
             else if( i_action == ACTIONID_CHAPTER_NEXT )
-                var_SetVoid( p_input, "next-chapter" );
+                var_TriggerCallback( p_input, "next-chapter" );
             else if( i_action == ACTIONID_DISC_MENU )
                 var_SetInteger( p_input, "title  0", 2 );
 
@@ -784,6 +785,26 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
                                 _( "Subtitle delay %i ms" ),
                                  (int)(i_delay/1000) );
             }
+            else if( i_action == ACTIONID_SUBPOS_DOWN )
+            {
+                int i_pos = var_GetInteger( p_input, "sub-margin" );
+                --i_pos;
+                var_SetInteger( p_input, "sub-margin", i_pos );
+                ClearChannels( p_intf, p_vout );
+                vout_OSDMessage( p_intf, DEFAULT_CHAN,
+                                _( "Subtitle position %i px" ),
+                                 (int)(i_pos) );
+            }
+            else if( i_action == ACTIONID_SUBPOS_UP )
+            {
+                int i_pos = var_GetInteger( p_input, "sub-margin" );
+                ++i_pos;
+                var_SetInteger( p_input, "sub-margin", i_pos );
+                ClearChannels( p_intf, p_vout );
+                vout_OSDMessage( p_intf, DEFAULT_CHAN,
+                                _( "Subtitle position %i px" ),
+                                 (int)(i_pos) );
+            }
             else if( i_action == ACTIONID_AUDIODELAY_DOWN )
             {
                 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
@@ -806,9 +827,9 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             }
             else if( i_action == ACTIONID_PLAY )
             {
-                if( var_GetInteger( p_input, "rate" ) != INPUT_RATE_DEFAULT )
+                if( var_GetFloat( p_input, "rate" ) != 1. )
                     /* Return to normal speed */
-                    var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
+                    var_SetFloat( p_input, "rate", 1. );
                 else
                 {
                     ClearChannels( p_intf, p_vout );
@@ -849,13 +870,12 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             {
                 if( var_GetBool( p_input, "can-record" ) )
                 {
-                    const bool b_record = !var_GetBool( p_input, "record" );
+                    const bool b_record = var_ToggleBool( p_input, "record" );
 
                     if( b_record )
                         vout_OSDMessage( p_intf, DEFAULT_CHAN, "%s", _("Recording") );
                     else
                         vout_OSDMessage( p_intf, DEFAULT_CHAN, "%s", _("Recording done") );
-                    var_SetBool( p_input, "record", b_record );
                 }
             }
         }
@@ -867,7 +887,6 @@ cleanup_and_continue:
         vlc_object_release( p_vout );
     if( p_input )
         vlc_object_release( p_input );
-    pl_Release( p_intf );
     return VLC_SUCCESS;
 }
 
@@ -940,7 +959,7 @@ static void PlayBookmark( intf_thread_t *p_intf, int i_num )
     if( asprintf( &psz_bookmark_name, "bookmark%i", i_num ) == -1 )
         return;
 
-    playlist_t *p_playlist = pl_Hold( p_intf );
+    playlist_t *p_playlist = pl_Get( p_intf );
     char *psz_bookmark = var_CreateGetString( p_intf, psz_bookmark_name );
 
     PL_LOCK;
@@ -960,7 +979,6 @@ static void PlayBookmark( intf_thread_t *p_intf, int i_num )
 
     free( psz_bookmark );
     free( psz_bookmark_name );
-    pl_Release( p_intf );
 }
 
 static void SetBookmark( intf_thread_t *p_intf, int i_num )
@@ -969,7 +987,7 @@ static void SetBookmark( intf_thread_t *p_intf, int i_num )
     if( asprintf( &psz_bookmark_name, "bookmark%i", i_num ) == -1 )
         return;
 
-    playlist_t *p_playlist = pl_Hold( p_intf );
+    playlist_t *p_playlist = pl_Get( p_intf );
     var_Create( p_intf, psz_bookmark_name,
                 VLC_VAR_STRING|VLC_VAR_DOINHERIT );
     playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
@@ -982,7 +1000,6 @@ static void SetBookmark( intf_thread_t *p_intf, int i_num )
         config_SaveConfigFile( p_intf, "hotkeys" );
     }
 
-    pl_Release( p_intf );
     free( psz_bookmark_name );
 }