Commit d6bf647e authored by Thomas Guillem's avatar Thomas Guillem Committed by Hugo Beauzée-Luyssen

actions: add vlc_actions_get_keycodes

Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent c46cbfef
...@@ -254,6 +254,16 @@ typedef enum vlc_action_id { ...@@ -254,6 +254,16 @@ typedef enum vlc_action_id {
VLC_API vlc_action_id_t VLC_API vlc_action_id_t
vlc_actions_get_id(const char *psz_key_name); vlc_actions_get_id(const char *psz_key_name);
/**
* Get keycodes from a action key name and vlc configuration
* \return The number of keycodes for this action, or 0 in case of an error.
* The list needs to be released with free()
*/
VLC_API size_t
vlc_actions_get_keycodes(vlc_object_t *p_obj, const char *psz_key_name,
bool b_global, uint_fast32_t **pp_keycodes );
#define vlc_actions_get_keycodes(a, b, c, d) vlc_actions_get_keycodes(VLC_OBJECT(a), b, c, d)
/** /**
* Get a list a key names * Get a list a key names
* \return A NULL terminated list of const char * * \return A NULL terminated list of const char *
......
...@@ -170,18 +170,12 @@ static void *Thread( void *p_data ) ...@@ -170,18 +170,12 @@ static void *Thread( void *p_data )
for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf ); for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );
*ppsz_keys != NULL; ppsz_keys++ ) *ppsz_keys != NULL; ppsz_keys++ )
{ {
char varname[12 + strlen( *ppsz_keys )]; uint_fast32_t *p_keys;
sprintf( varname, "global-key-%s", *ppsz_keys ); size_t i_nb_keys = vlc_actions_get_keycodes( p_intf, *ppsz_keys, true,
&p_keys );
char *key = var_InheritString( p_intf, varname ); for( size_t i = 0; i < i_nb_keys; ++i )
if( key == NULL ) {
continue; uint_fast32_t i_key = p_keys[i];
UINT i_key = vlc_str2keycode( key );
free( key );
if( i_key == KEY_UNSET )
continue;
UINT i_keyMod = 0; UINT i_keyMod = 0;
if( i_key & KEY_MODIFIER_SHIFT ) i_keyMod |= MOD_SHIFT; if( i_key & KEY_MODIFIER_SHIFT ) i_keyMod |= MOD_SHIFT;
if( i_key & KEY_MODIFIER_ALT ) i_keyMod |= MOD_ALT; if( i_key & KEY_MODIFIER_ALT ) i_keyMod |= MOD_ALT;
...@@ -259,6 +253,8 @@ static void *Thread( void *p_data ) ...@@ -259,6 +253,8 @@ static void *Thread( void *p_data )
if( !RegisterHotKey( p_sys->hotkeyWindow, atom, i_keyMod, i_vk ) ) if( !RegisterHotKey( p_sys->hotkeyWindow, atom, i_keyMod, i_vk ) )
GlobalDeleteAtom( atom ); GlobalDeleteAtom( atom );
} }
free( p_keys );
}
/* Main message loop */ /* Main message loop */
while( GetMessage( &message, NULL, 0, 0 ) ) while( GetMessage( &message, NULL, 0, 0 ) )
......
...@@ -293,18 +293,13 @@ static bool Mapping( intf_thread_t *p_intf ) ...@@ -293,18 +293,13 @@ static bool Mapping( intf_thread_t *p_intf )
for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf ); for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );
*ppsz_keys != NULL; ppsz_keys++ ) *ppsz_keys != NULL; ppsz_keys++ )
{ {
char varname[12 + strlen( *ppsz_keys )]; uint_fast32_t *p_keys;
sprintf( varname, "global-key-%s", *ppsz_keys ); size_t i_nb_keys = vlc_actions_get_keycodes( p_intf, *ppsz_keys, true,
&p_keys );
char *key = var_InheritString( p_intf, varname );
if( key == NULL )
continue;
uint_fast32_t i_vlc_key = vlc_str2keycode( key );
free( key );
if( i_vlc_key == KEY_UNSET )
continue;
for( size_t i = 0; i < i_nb_keys; ++i )
{
uint_fast32_t i_vlc_key = p_keys[i];
const unsigned i_modifier = GetX11Modifier( p_sys->p_connection, const unsigned i_modifier = GetX11Modifier( p_sys->p_connection,
p_sys->p_symbols, i_vlc_key & KEY_MODIFIER ); p_sys->p_symbols, i_vlc_key & KEY_MODIFIER );
...@@ -340,6 +335,8 @@ static bool Mapping( intf_thread_t *p_intf ) ...@@ -340,6 +335,8 @@ static bool Mapping( intf_thread_t *p_intf )
active = true; active = true;
} }
} }
free( p_keys );
}
return active; return active;
} }
......
...@@ -512,6 +512,7 @@ video_format_Setup ...@@ -512,6 +512,7 @@ video_format_Setup
video_format_Print video_format_Print
vlc_actions_get_id vlc_actions_get_id
vlc_actions_get_key_names vlc_actions_get_key_names
vlc_actions_get_keycodes
vlc_b64_decode vlc_b64_decode
vlc_b64_decode_binary vlc_b64_decode_binary
vlc_b64_decode_binary_to_buffer vlc_b64_decode_binary_to_buffer
......
...@@ -594,6 +594,45 @@ vlc_actions_get_id (const char *name) ...@@ -594,6 +594,45 @@ vlc_actions_get_id (const char *name)
return (act != NULL) ? act->id : ACTIONID_NONE; return (act != NULL) ? act->id : ACTIONID_NONE;
} }
#undef vlc_actions_get_keycodes
size_t
vlc_actions_get_keycodes(vlc_object_t *p_obj, const char *psz_key_name,
bool b_global, uint_fast32_t **pp_keycodes)
{
char varname[12 /* "global-key-" */ + strlen( psz_key_name )];
sprintf( varname, "%skey-%s", b_global ? "global-" : "", psz_key_name );
*pp_keycodes = NULL;
char *psz_keys = var_InheritString( p_obj, varname );
if( psz_keys == NULL )
return 0;
size_t i_nb_keycodes = 0;
for( const char* psz_it = psz_keys; *psz_it; ++psz_it )
{
if( *psz_it == '\t' )
++i_nb_keycodes;
}
++i_nb_keycodes;
*pp_keycodes = malloc( i_nb_keycodes * sizeof( **pp_keycodes ) );
if( unlikely( !*pp_keycodes ) )
{
free( psz_keys );
return 0;
}
size_t i = 0;
for( char *buf, *key = strtok_r( psz_keys, "\t", &buf );
key != NULL;
key = strtok_r( NULL, "\t", &buf ), ++i )
{
(*pp_keycodes)[i] = vlc_str2keycode( key );
}
assert( i == i_nb_keycodes );
free( psz_keys );
return i_nb_keycodes;
}
#undef vlc_actions_get_key_names #undef vlc_actions_get_key_names
const char* const* const char* const*
vlc_actions_get_key_names(vlc_object_t *p_obj) vlc_actions_get_key_names(vlc_object_t *p_obj)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment