[vlc-devel] [PATCH v2] hotkeys: new hotkey for toggling subtitles
Adrian Haensler
a.hae at gmx.de
Wed May 21 05:35:02 CEST 2014
A subtitle track chosen by hotkey "v" is remembered in variable "spu-choice".
The hotkey "Shift+v" toggles subtitle visibility.
---
include/vlc_keys.h | 1 +
modules/control/hotkeys.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++-
src/config/keys.c | 1 +
src/input/var.c | 4 ++++
src/libvlc-module.c | 5 +++++
5 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/include/vlc_keys.h b/include/vlc_keys.h
index aafa589..49edab3 100644
--- a/include/vlc_keys.h
+++ b/include/vlc_keys.h
@@ -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,
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 1e7fcdf..7a5db8c 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -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 )
diff --git a/src/config/keys.c b/src/config/keys.c
index 1c3304f..9ae252b 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -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, },
diff --git a/src/input/var.c b/src/input/var.c
index 3e722f4..7591de4 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -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 );
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 0dd4c26..b304a08 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -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")
@@ -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"
@@ -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,
--
1.9.0
More information about the vlc-devel
mailing list