Skip to content

Commit

Permalink
hotkeys: new hotkey for toggling subtitles
Browse files Browse the repository at this point in the history
A subtitle track chosen by hotkey "v" is remembered in variable "spu-choice".
The hotkey "Shift+v" toggles subtitle visibility.

Signed-off-by: Jean-Baptiste Kempf <[email protected]>
  • Loading branch information
ahaensler authored and jbkempf committed Jun 14, 2014
1 parent 298616d commit 69d6f2a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/vlc_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ typedef enum vlc_action {
ACTIONID_SUBPOS_DOWN,
ACTIONID_AUDIO_TRACK,
ACTIONID_SUBTITLE_TRACK,
ACTIONID_SUBTITLE_TOGGLE,
ACTIONID_INTF_TOGGLE_FSC,
ACTIONID_INTF_HIDE,
ACTIONID_INTF_BOSS,
Expand Down
53 changes: 52 additions & 1 deletion modules/control/hotkeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,63 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
i = 0;
else
i++;
var_Set( p_input, "spu-es", list.p_list->p_values[i] );
var_SetInteger( p_input, "spu-es", list.p_list->p_values[i].i_int );
var_SetInteger( p_input, "spu-choice", list.p_list->p_values[i].i_int );
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 list, list2;
int i_count, i_sel_index, i_sel_id, i_old_id, i_new_index;
i_old_id = var_GetInteger( p_input, "spu-es" );
i_sel_id = var_GetInteger( p_input, "spu-choice" );

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_sel_index = 0; i_sel_index < i_count; i_sel_index++ )
{
if( i_sel_id == list.p_list->p_values[i_sel_index].i_int )
{
break;
}
}
/* if there is nothing to toggle choose the first track */
if( !i_sel_index ) {
i_sel_index = 1;
i_sel_id = list.p_list->p_values[1].i_int;
var_SetInteger( p_input, "spu-choice", i_sel_id );
}

i_new_index = 0;
if( i_old_id != i_sel_id )
{
if( i_sel_index >= i_count )
{
var_SetInteger( p_input, "spu-choice", list.p_list->p_values[0].i_int );
}
else
{
i_new_index = i_sel_index;
}
}
var_SetInteger( p_input, "spu-es", list.p_list->p_values[i_new_index].i_int );
DisplayMessage( p_vout, _("Subtitle track: %s"),
list2.p_list->p_values[i_new_index].psz_string );
var_FreeList( &list, &list2 );
}
break;
case ACTIONID_PROGRAM_SID_NEXT:
case ACTIONID_PROGRAM_SID_PREV:
if( p_input )
Expand Down
1 change: 1 addition & 0 deletions src/config/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ static const struct action actions[] =
{ "subsync-markaudio", ACTIONID_SUBSYNC_MARKAUDIO, },
{ "subsync-marksub", ACTIONID_SUBSYNC_MARKSUB, },
{ "subsync-reset", ACTIONID_SUBSYNC_RESET, },
{ "subtitle-toggle", ACTIONID_SUBTITLE_TOGGLE, },
{ "subtitle-track", ACTIONID_SUBTITLE_TRACK, },
{ "title-next", ACTIONID_TITLE_NEXT, },
{ "title-prev", ACTIONID_TITLE_PREV, },
Expand Down
4 changes: 4 additions & 0 deletions src/input/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ void input_ControlVarInit ( input_thread_t *p_input )
text.psz_string = _("Subtitle Track");
var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );

var_Create( p_input, "spu-choice", VLC_VAR_INTEGER );
val.i_int = -1;
var_Change( p_input, "spu-choice", VLC_VAR_SETVALUE, &val, NULL );

/* Special read only objects variables for intf */
var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );

Expand Down
5 changes: 5 additions & 0 deletions src/libvlc-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,8 @@ static const char *const mouse_wheel_texts[] =
#define AUDIO_TRACK_KEY_LONGTEXT N_("Cycle through the available audio tracks(languages).")
#define SUBTITLE_TRACK_KEY_TEXT N_("Cycle subtitle track")
#define SUBTITLE_TRACK_KEY_LONGTEXT N_("Cycle through the available subtitle tracks.")
#define SUBTITLE_TOGGLE_KEY_TEXT N_("Toggle subtitles")
#define SUBTITLE_TOGGLE_KEY_LONGTEXT N_("Toggle subtitle track visibility.")
#define PROGRAM_SID_NEXT_KEY_TEXT N_("Cycle next program Service ID")
#define PROGRAM_SID_NEXT_KEY_LONGTEXT N_("Cycle through the available next program Service IDs (SIDs).")
#define PROGRAM_SID_PREV_KEY_TEXT N_("Cycle previous program Service ID")
Expand Down Expand Up @@ -2306,6 +2308,7 @@ vlc_module_begin ()

# define KEY_AUDIO_TRACK "b"
# define KEY_SUBTITLE_TRACK "v"
# define KEY_SUBTITLE_TOGGLE "Shift+v"
# define KEY_PROGRAM_SID_NEXT "x"
# define KEY_PROGRAM_SID_PREV "Shift+x"
# define KEY_ASPECT_RATIO "a"
Expand Down Expand Up @@ -2476,6 +2479,8 @@ vlc_module_begin ()
AUDI_DEVICE_CYCLE_KEY_LONGTEXT, false )
add_key( "key-subtitle-track", KEY_SUBTITLE_TRACK,
SUBTITLE_TRACK_KEY_TEXT, SUBTITLE_TRACK_KEY_LONGTEXT, false )
add_key( "key-subtitle-toggle", KEY_SUBTITLE_TOGGLE,
SUBTITLE_TOGGLE_KEY_TEXT, SUBTITLE_TOGGLE_KEY_LONGTEXT, false )
add_key( "key-program-sid-next", KEY_PROGRAM_SID_NEXT,
PROGRAM_SID_NEXT_KEY_TEXT, PROGRAM_SID_NEXT_KEY_LONGTEXT, false )
add_key( "key-program-sid-prev", KEY_PROGRAM_SID_PREV,
Expand Down

0 comments on commit 69d6f2a

Please sign in to comment.