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 {
VLC_API vlc_action_id_t
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
* \return A NULL terminated list of const char *
......
......@@ -170,22 +170,16 @@ static void *Thread( void *p_data )
for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );
*ppsz_keys != NULL; ppsz_keys++ )
{
char varname[12 + strlen( *ppsz_keys )];
sprintf( varname, "global-key-%s", *ppsz_keys );
char *key = var_InheritString( p_intf, varname );
if( key == NULL )
continue;
UINT i_key = vlc_str2keycode( key );
free( key );
if( i_key == KEY_UNSET )
continue;
UINT i_keyMod = 0;
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_CTRL ) i_keyMod |= MOD_CONTROL;
uint_fast32_t *p_keys;
size_t i_nb_keys = vlc_actions_get_keycodes( p_intf, *ppsz_keys, true,
&p_keys );
for( size_t i = 0; i < i_nb_keys; ++i )
{
uint_fast32_t i_key = p_keys[i];
UINT i_keyMod = 0;
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_CTRL ) i_keyMod |= MOD_CONTROL;
#define HANDLE( key ) case KEY_##key: i_vk = VK_##key; break
#define HANDLE2( key, key2 ) case KEY_##key: i_vk = VK_##key2; break
......@@ -209,55 +203,57 @@ static void *Thread( void *p_data )
#define VK_PAGEDOWN 0x22
#endif
UINT i_vk = 0;
switch( i_key & ~KEY_MODIFIER )
{
HANDLE( LEFT );
HANDLE( RIGHT );
HANDLE( UP );
HANDLE( DOWN );
HANDLE( SPACE );
HANDLE2( ESC, ESCAPE );
HANDLE2( ENTER, RETURN );
HANDLE( F1 );
HANDLE( F2 );
HANDLE( F3 );
HANDLE( F4 );
HANDLE( F5 );
HANDLE( F6 );
HANDLE( F7 );
HANDLE( F8 );
HANDLE( F9 );
HANDLE( F10 );
HANDLE( F11 );
HANDLE( F12 );
HANDLE( PAGEUP );
HANDLE( PAGEDOWN );
HANDLE( HOME );
HANDLE( END );
HANDLE( INSERT );
HANDLE( DELETE );
HANDLE( VOLUME_DOWN );
HANDLE( VOLUME_UP );
HANDLE( MEDIA_PLAY_PAUSE );
HANDLE( MEDIA_STOP );
HANDLE( MEDIA_PREV_TRACK );
HANDLE( MEDIA_NEXT_TRACK );
default:
i_vk = toupper( (uint8_t)(i_key & ~KEY_MODIFIER) );
break;
}
if( !i_vk ) continue;
UINT i_vk = 0;
switch( i_key & ~KEY_MODIFIER )
{
HANDLE( LEFT );
HANDLE( RIGHT );
HANDLE( UP );
HANDLE( DOWN );
HANDLE( SPACE );
HANDLE2( ESC, ESCAPE );
HANDLE2( ENTER, RETURN );
HANDLE( F1 );
HANDLE( F2 );
HANDLE( F3 );
HANDLE( F4 );
HANDLE( F5 );
HANDLE( F6 );
HANDLE( F7 );
HANDLE( F8 );
HANDLE( F9 );
HANDLE( F10 );
HANDLE( F11 );
HANDLE( F12 );
HANDLE( PAGEUP );
HANDLE( PAGEDOWN );
HANDLE( HOME );
HANDLE( END );
HANDLE( INSERT );
HANDLE( DELETE );
HANDLE( VOLUME_DOWN );
HANDLE( VOLUME_UP );
HANDLE( MEDIA_PLAY_PAUSE );
HANDLE( MEDIA_STOP );
HANDLE( MEDIA_PREV_TRACK );
HANDLE( MEDIA_NEXT_TRACK );
default:
i_vk = toupper( (uint8_t)(i_key & ~KEY_MODIFIER) );
break;
}
if( !i_vk ) continue;
#undef HANDLE
#undef HANDLE2
ATOM atom = GlobalAddAtomA( *ppsz_keys );
if( !atom ) continue;
ATOM atom = GlobalAddAtomA( *ppsz_keys );
if( !atom ) continue;
if( !RegisterHotKey( p_sys->hotkeyWindow, atom, i_keyMod, i_vk ) )
GlobalDeleteAtom( atom );
if( !RegisterHotKey( p_sys->hotkeyWindow, atom, i_keyMod, i_vk ) )
GlobalDeleteAtom( atom );
}
free( p_keys );
}
/* Main message loop */
......
......@@ -293,52 +293,49 @@ static bool Mapping( intf_thread_t *p_intf )
for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );
*ppsz_keys != NULL; ppsz_keys++ )
{
char varname[12 + strlen( *ppsz_keys )];
sprintf( varname, "global-key-%s", *ppsz_keys );
uint_fast32_t *p_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;
const unsigned i_modifier = GetX11Modifier( p_sys->p_connection,
p_sys->p_symbols, i_vlc_key & KEY_MODIFIER );
const size_t max = sizeof(p_x11_modifier_ignored) /
sizeof(*p_x11_modifier_ignored);
for( unsigned int i = 0; i < max; i++ )
for( size_t i = 0; i < i_nb_keys; ++i )
{
const unsigned i_ignored = GetModifier( p_sys->p_connection,
p_sys->p_symbols, p_x11_modifier_ignored[i] );
if( i != 0 && i_ignored == 0)
continue;
uint_fast32_t i_vlc_key = p_keys[i];
const unsigned i_modifier = GetX11Modifier( p_sys->p_connection,
p_sys->p_symbols, i_vlc_key & KEY_MODIFIER );
const size_t max = sizeof(p_x11_modifier_ignored) /
sizeof(*p_x11_modifier_ignored);
for( unsigned int i = 0; i < max; i++ )
{
const unsigned i_ignored = GetModifier( p_sys->p_connection,
p_sys->p_symbols, p_x11_modifier_ignored[i] );
if( i != 0 && i_ignored == 0)
continue;
xcb_keycode_t *p_keys = xcb_key_symbols_get_keycode(
p_sys->p_symbols, GetX11Key( i_vlc_key & ~KEY_MODIFIER ) );
xcb_keycode_t *p_keys = xcb_key_symbols_get_keycode(
p_sys->p_symbols, GetX11Key( i_vlc_key & ~KEY_MODIFIER ) );
if( !p_keys )
break;
if( !p_keys )
break;
hotkey_mapping_t *p_map = realloc( p_sys->p_map,
sizeof(*p_sys->p_map) * (p_sys->i_map+1) );
if( !p_map )
{
free( p_keys );
break;
hotkey_mapping_t *p_map = realloc( p_sys->p_map,
sizeof(*p_sys->p_map) * (p_sys->i_map+1) );
if( !p_map )
{
free( p_keys );
break;
}
p_sys->p_map = p_map;
p_map += p_sys->i_map;
p_sys->i_map++;
p_map->p_keys = p_keys;
p_map->i_modifier = i_modifier|i_ignored;
p_map->i_vlc = i_vlc_key;
active = true;
}
p_sys->p_map = p_map;
p_map += p_sys->i_map;
p_sys->i_map++;
p_map->p_keys = p_keys;
p_map->i_modifier = i_modifier|i_ignored;
p_map->i_vlc = i_vlc_key;
active = true;
}
free( p_keys );
}
return active;
}
......
......@@ -512,6 +512,7 @@ video_format_Setup
video_format_Print
vlc_actions_get_id
vlc_actions_get_key_names
vlc_actions_get_keycodes
vlc_b64_decode
vlc_b64_decode_binary
vlc_b64_decode_binary_to_buffer
......
......@@ -594,6 +594,45 @@ vlc_actions_get_id (const char *name)
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
const char* const*
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