[vlc-devel] [PATCH] hotkeys: new hotkey for toggling subtitles
Adrian Haensler
a.hae at gmx.de
Wed May 21 03:31:25 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 | 47 +++++++++++++++++++++++++++++++++++++++++++++++
src/config/keys.c | 1 +
src/input/var.c | 4 ++++
src/libvlc-module.c | 5 +++++
5 files changed, 58 insertions(+)
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..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 );
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 );
+
+ 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 )
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..0f975d2 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 = 0;
+ 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