[vlc-devel] [PATCH] hotkeys: new hotkey for toggling subtitles

Rémi Denis-Courmont remi at remlab.net
Wed May 21 03:59:54 CEST 2014


Le 2014-05-21 09:31, Adrian Haensler a écrit :
> A subtitle track chosen by hotkey "v" is remembered in variable 
> "spu-choice".
> The hotkey "Shift+v" toggles subtitle visibility.

> diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
> index 1e7fcdf..47fc395 100644
> --- a/modules/control/hotkeys.c
> +++ b/modules/control/hotkeys.c
> @@ -592,11 +592,58 @@ static int PutAction( intf_thread_t *p_intf,
> int i_action )
>                  else
>                      i++;
>                  var_Set( p_input, "spu-es", list.p_list->p_values[i] 
> );
> +                var_SetInteger( p_input, "spu-choice", i );

Why do you store the index instead of the unique ID? The index will be 
shifted if the set of subtitle tracks changes.

>                  DisplayMessage( p_vout, _("Subtitle track: %s"),
>                                  list2.p_list->p_values[i].psz_string 
> );
>                  var_FreeList( &list, &list2 );
>              }
>              break;
> +        case ACTIONID_SUBTITLE_TOGGLE:
> +            if( p_input )
> +            {
> +                vlc_value_t val, val2, list, list2;
> +                int i_count, i, newTrack;
> +                var_Get( p_input, "spu-es", &val );
> +                var_Get( p_input, "spu-choice", &val2 );

Please, no unchecked raw var_Get() and var_Set() in new code, unless 
you really need to.

> +
> +                var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
> +                            &list, &list2 );
> +                i_count = list.p_list->i_count;
> +                if( i_count <= 1 )
> +                {
> +                    DisplayMessage( p_vout, _("Subtitle track: %s"),
> +                                    _("N/A") );
> +                    var_FreeList( &list, &list2 );
> +                    break;
> +                }
> +                for( i = 0; i < i_count; i++ )
> +                {
> +                    if( val.i_int == list.p_list->p_values[i].i_int 
> )
> +                    {
> +                        break;
> +                    }
> +                }
> +                /* if there is nothing to toggle choose the first 
> track */
> +                if( !val2.i_int ) {
> +                    val2.i_int = 1;
> +                    var_Set( p_input, "spu-choice", val2 );
> +                }
> +
> +                newTrack = 0;
> +                if( i != val2.i_int )
> +                {
> +                    if( val2.i_int >= i_count ){
> +                        var_SetInteger( p_input, "spu-choice", 0 );
> +                    }
> +                    else
> +                        newTrack = val2.i_int;
> +                }
> +                var_Set( p_input, "spu-es",
> list.p_list->p_values[newTrack] );
> +                DisplayMessage( p_vout, _("Subtitle track: %s"),
> +
> list2.p_list->p_values[newTrack].psz_string );
> +                var_FreeList( &list, &list2 );
> +            }
> +            break;
>          case ACTIONID_PROGRAM_SID_NEXT:
>          case ACTIONID_PROGRAM_SID_PREV:
>              if( p_input )

-- 
Rémi Denis-Courmont



More information about the vlc-devel mailing list