Commit e1e7a510 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Thread-safe and more compact hotkeys initialization

parent c5b09080
......@@ -38,7 +38,7 @@ struct libvlc_int_t
VLC_COMMON_MEMBERS
/* Structure storing the action name / key associations */
struct hotkey
const struct hotkey
{
const char *psz_action;
int i_action;
......
......@@ -169,14 +169,6 @@ static void Run( intf_thread_t *p_intf )
vlc_cleanup_push( __pl_Release, p_intf );
/* Initialize hotkey structure */
for( struct hotkey *p_hotkey = p_intf->p_libvlc->p_hotkeys;
p_hotkey->psz_action != NULL;
p_hotkey++ )
{
p_hotkey->i_key = config_GetInt( p_intf, p_hotkey->psz_action );
}
for( ;; )
{
input_thread_t *p_input;
......
This diff is collapsed.
......@@ -797,11 +797,25 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
*/
var_Create( p_libvlc, "key-pressed", VLC_VAR_INTEGER );
var_Create( p_libvlc, "key-action", VLC_VAR_INTEGER );
p_libvlc->p_hotkeys = malloc( libvlc_hotkeys_size );
/* Do a copy (we don't need to modify the strings) */
memcpy( p_libvlc->p_hotkeys, libvlc_hotkeys, libvlc_hotkeys_size );
{
struct hotkey *p_keys =
malloc( (libvlc_actions_count + 1) * sizeof (*p_keys) );
/* Initialize from configuration */
for( size_t i = 0; i < libvlc_actions_count; i++ )
{
p_keys[i].psz_action = libvlc_actions[i].name;
p_keys[i].i_key = config_GetInt( p_libvlc,
libvlc_actions[i].name );
p_keys[i].i_action = libvlc_actions[i].value;
}
p_keys[libvlc_actions_count].psz_action = NULL;
p_keys[libvlc_actions_count].i_key = 0;
p_keys[libvlc_actions_count].i_action = 0;
p_libvlc->p_hotkeys = p_keys;
var_AddCallback( p_libvlc, "key-pressed", vlc_key_to_action,
p_libvlc->p_hotkeys );
p_keys );
}
/* Initialize playlist and get commandline files */
p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) );
......@@ -1093,8 +1107,8 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
FREENULL( priv->psz_configfile );
var_DelCallback( p_libvlc, "key-pressed", vlc_key_to_action,
p_libvlc->p_hotkeys );
FREENULL( p_libvlc->p_hotkeys );
(void *)p_libvlc->p_hotkeys );
free( (void *)p_libvlc->p_hotkeys );
}
/**
......
......@@ -29,9 +29,14 @@ typedef struct variable_t variable_t;
extern const char vlc_usage[];
/* Hotkey stuff */
extern const struct hotkey libvlc_hotkeys[];
extern const size_t libvlc_hotkeys_size;
/* Actions (hot keys) */
typedef struct action
{
char name[24];
int value;
} action_t;
extern const struct action libvlc_actions[];
extern const size_t libvlc_actions_count;
extern int vlc_key_to_action (vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void *);
......
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