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;
......
......@@ -2700,110 +2700,110 @@ vlc_module_end ()
* Initializer for the libvlc instance structure
* storing the action / key associations
*****************************************************************************/
const struct hotkey libvlc_hotkeys[] =
const struct action libvlc_actions[] =
{
{ "key-quit", ACTIONID_QUIT, 0, },
{ "key-play-pause", ACTIONID_PLAY_PAUSE, 0, },
{ "key-play", ACTIONID_PLAY, 0, },
{ "key-pause", ACTIONID_PAUSE, 0, },
{ "key-stop", ACTIONID_STOP, 0, },
{ "key-position", ACTIONID_POSITION, 0, },
{ "key-jump-extrashort", ACTIONID_JUMP_BACKWARD_EXTRASHORT, 0, },
{ "key-jump+extrashort", ACTIONID_JUMP_FORWARD_EXTRASHORT, 0, },
{ "key-jump-short", ACTIONID_JUMP_BACKWARD_SHORT, 0, },
{ "key-jump+short", ACTIONID_JUMP_FORWARD_SHORT, 0, },
{ "key-jump-medium", ACTIONID_JUMP_BACKWARD_MEDIUM, 0, },
{ "key-jump+medium", ACTIONID_JUMP_FORWARD_MEDIUM, 0, },
{ "key-jump-long", ACTIONID_JUMP_BACKWARD_LONG, 0, },
{ "key-jump+long", ACTIONID_JUMP_FORWARD_LONG, 0, },
{ "key-frame-next", ACTIONID_FRAME_NEXT, 0, },
{ "key-prev", ACTIONID_PREV, 0, },
{ "key-next", ACTIONID_NEXT, 0, },
{ "key-faster", ACTIONID_FASTER, 0, },
{ "key-slower", ACTIONID_SLOWER, 0, },
{ "key-rate-normal", ACTIONID_RATE_NORMAL, 0, },
{ "key-rate-faster-fine", ACTIONID_RATE_FASTER_FINE, 0, },
{ "key-rate-slower-fine", ACTIONID_RATE_SLOWER_FINE, 0, },
{ "key-toggle-fullscreen", ACTIONID_TOGGLE_FULLSCREEN, 0, },
{ "key-leave-fullscreen", ACTIONID_LEAVE_FULLSCREEN, 0, },
{ "key-vol-up", ACTIONID_VOL_UP, 0, },
{ "key-vol-down", ACTIONID_VOL_DOWN, 0, },
{ "key-vol-mute", ACTIONID_VOL_MUTE, 0, },
{ "key-subdelay-down", ACTIONID_SUBDELAY_DOWN, 0, },
{ "key-subdelay-up", ACTIONID_SUBDELAY_UP, 0, },
{ "key-audiodelay-down", ACTIONID_AUDIODELAY_DOWN, 0, },
{ "key-audiodelay-up", ACTIONID_AUDIODELAY_UP, 0, },
{ "key-audio-track", ACTIONID_AUDIO_TRACK, 0, },
{ "key-subtitle-track", ACTIONID_SUBTITLE_TRACK, 0, },
{ "key-aspect-ratio", ACTIONID_ASPECT_RATIO, 0, },
{ "key-crop", ACTIONID_CROP, 0, },
{ "key-deinterlace", ACTIONID_DEINTERLACE, 0, },
{ "key-intf-show", ACTIONID_INTF_SHOW, 0, },
{ "key-intf-hide", ACTIONID_INTF_HIDE, 0, },
{ "key-snapshot", ACTIONID_SNAPSHOT, 0, },
{ "key-zoom", ACTIONID_ZOOM, 0, },
{ "key-unzoom", ACTIONID_UNZOOM, 0, },
{ "key-crop-top", ACTIONID_CROP_TOP, 0, },
{ "key-uncrop-top", ACTIONID_UNCROP_TOP, 0, },
{ "key-crop-left", ACTIONID_CROP_LEFT, 0, },
{ "key-uncrop-left", ACTIONID_UNCROP_LEFT, 0, },
{ "key-crop-bottom", ACTIONID_CROP_BOTTOM, 0, },
{ "key-uncrop-bottom", ACTIONID_UNCROP_BOTTOM, 0, },
{ "key-crop-right", ACTIONID_CROP_RIGHT, 0, },
{ "key-uncrop-right", ACTIONID_UNCROP_RIGHT, 0, },
{ "key-nav-activate", ACTIONID_NAV_ACTIVATE, 0, },
{ "key-nav-up", ACTIONID_NAV_UP, 0, },
{ "key-nav-down", ACTIONID_NAV_DOWN, 0, },
{ "key-nav-left", ACTIONID_NAV_LEFT, 0, },
{ "key-nav-right", ACTIONID_NAV_RIGHT, 0, },
{ "key-disc-menu", ACTIONID_DISC_MENU, 0, },
{ "key-title-prev", ACTIONID_TITLE_PREV, 0, },
{ "key-title-next", ACTIONID_TITLE_NEXT, 0, },
{ "key-chapter-prev", ACTIONID_CHAPTER_PREV, 0, },
{ "key-chapter-next", ACTIONID_CHAPTER_NEXT, 0, },
{ "key-zoom-quarter", ACTIONID_ZOOM_QUARTER, 0, },
{ "key-zoom-half", ACTIONID_ZOOM_HALF, 0, },
{ "key-zoom-original", ACTIONID_ZOOM_ORIGINAL, 0, },
{ "key-zoom-double", ACTIONID_ZOOM_DOUBLE, 0, },
{ "key-set-bookmark1", ACTIONID_SET_BOOKMARK1, 0, },
{ "key-set-bookmark2", ACTIONID_SET_BOOKMARK2, 0, },
{ "key-set-bookmark3", ACTIONID_SET_BOOKMARK3, 0, },
{ "key-set-bookmark4", ACTIONID_SET_BOOKMARK4, 0, },
{ "key-set-bookmark5", ACTIONID_SET_BOOKMARK5, 0, },
{ "key-set-bookmark6", ACTIONID_SET_BOOKMARK6, 0, },
{ "key-set-bookmark7", ACTIONID_SET_BOOKMARK7, 0, },
{ "key-set-bookmark8", ACTIONID_SET_BOOKMARK8, 0, },
{ "key-set-bookmark9", ACTIONID_SET_BOOKMARK9, 0, },
{ "key-set-bookmark10", ACTIONID_SET_BOOKMARK10, 0, },
{ "key-play-bookmark1", ACTIONID_PLAY_BOOKMARK1, 0, },
{ "key-play-bookmark2", ACTIONID_PLAY_BOOKMARK2, 0, },
{ "key-play-bookmark3", ACTIONID_PLAY_BOOKMARK3, 0, },
{ "key-play-bookmark4", ACTIONID_PLAY_BOOKMARK4, 0, },
{ "key-play-bookmark5", ACTIONID_PLAY_BOOKMARK5, 0, },
{ "key-play-bookmark6", ACTIONID_PLAY_BOOKMARK6, 0, },
{ "key-play-bookmark7", ACTIONID_PLAY_BOOKMARK7, 0, },
{ "key-play-bookmark8", ACTIONID_PLAY_BOOKMARK8, 0, },
{ "key-play-bookmark9", ACTIONID_PLAY_BOOKMARK9, 0, },
{ "key-play-bookmark10", ACTIONID_PLAY_BOOKMARK10, 0, },
{ "key-history-back", ACTIONID_HISTORY_BACK, 0, },
{ "key-history-forward", ACTIONID_HISTORY_FORWARD, 0, },
{ "key-record", ACTIONID_RECORD, 0, },
{ "key-dump", ACTIONID_DUMP, 0, },
{ "key-random", ACTIONID_RANDOM, 0, },
{ "key-loop", ACTIONID_LOOP, 0, },
{ "key-wallpaper", ACTIONID_WALLPAPER, 0, },
{ "key-menu-on", ACTIONID_MENU_ON, 0, },
{ "key-menu-off", ACTIONID_MENU_OFF, 0, },
{ "key-menu-right", ACTIONID_MENU_RIGHT, 0, },
{ "key-menu-left", ACTIONID_MENU_LEFT, 0, },
{ "key-menu-up", ACTIONID_MENU_UP, 0, },
{ "key-menu-down", ACTIONID_MENU_DOWN, 0, },
{ "key-menu-select", ACTIONID_MENU_SELECT, 0, },
{ "key-audiodevice-cycle", ACTIONID_AUDIODEVICE_CYCLE, 0, },
{ "key-toggle-autoscale", ACTIONID_TOGGLE_AUTOSCALE, 0, },
{ "key-incr-scalefactor", ACTIONID_SCALE_UP, 0, },
{ "key-decr-scalefactor", ACTIONID_SCALE_DOWN, 0, },
{ NULL, 0, 0, }
{ "key-quit", ACTIONID_QUIT, },
{ "key-play-pause", ACTIONID_PLAY_PAUSE, },
{ "key-play", ACTIONID_PLAY, },
{ "key-pause", ACTIONID_PAUSE, },
{ "key-stop", ACTIONID_STOP, },
{ "key-position", ACTIONID_POSITION, },
{ "key-jump-extrashort", ACTIONID_JUMP_BACKWARD_EXTRASHORT, },
{ "key-jump+extrashort", ACTIONID_JUMP_FORWARD_EXTRASHORT, },
{ "key-jump-short", ACTIONID_JUMP_BACKWARD_SHORT, },
{ "key-jump+short", ACTIONID_JUMP_FORWARD_SHORT, },
{ "key-jump-medium", ACTIONID_JUMP_BACKWARD_MEDIUM, },
{ "key-jump+medium", ACTIONID_JUMP_FORWARD_MEDIUM, },
{ "key-jump-long", ACTIONID_JUMP_BACKWARD_LONG, },
{ "key-jump+long", ACTIONID_JUMP_FORWARD_LONG, },
{ "key-frame-next", ACTIONID_FRAME_NEXT, },
{ "key-prev", ACTIONID_PREV, },
{ "key-next", ACTIONID_NEXT, },
{ "key-faster", ACTIONID_FASTER, },
{ "key-slower", ACTIONID_SLOWER, },
{ "key-rate-normal", ACTIONID_RATE_NORMAL, },
{ "key-rate-faster-fine", ACTIONID_RATE_FASTER_FINE, },
{ "key-rate-slower-fine", ACTIONID_RATE_SLOWER_FINE, },
{ "key-toggle-fullscreen", ACTIONID_TOGGLE_FULLSCREEN, },
{ "key-leave-fullscreen", ACTIONID_LEAVE_FULLSCREEN, },
{ "key-vol-up", ACTIONID_VOL_UP, },
{ "key-vol-down", ACTIONID_VOL_DOWN, },
{ "key-vol-mute", ACTIONID_VOL_MUTE, },
{ "key-subdelay-down", ACTIONID_SUBDELAY_DOWN, },
{ "key-subdelay-up", ACTIONID_SUBDELAY_UP, },
{ "key-audiodelay-down", ACTIONID_AUDIODELAY_DOWN, },
{ "key-audiodelay-up", ACTIONID_AUDIODELAY_UP, },
{ "key-audio-track", ACTIONID_AUDIO_TRACK, },
{ "key-subtitle-track", ACTIONID_SUBTITLE_TRACK, },
{ "key-aspect-ratio", ACTIONID_ASPECT_RATIO, },
{ "key-crop", ACTIONID_CROP, },
{ "key-deinterlace", ACTIONID_DEINTERLACE, },
{ "key-intf-show", ACTIONID_INTF_SHOW, },
{ "key-intf-hide", ACTIONID_INTF_HIDE, },
{ "key-snapshot", ACTIONID_SNAPSHOT, },
{ "key-zoom", ACTIONID_ZOOM, },
{ "key-unzoom", ACTIONID_UNZOOM, },
{ "key-crop-top", ACTIONID_CROP_TOP, },
{ "key-uncrop-top", ACTIONID_UNCROP_TOP, },
{ "key-crop-left", ACTIONID_CROP_LEFT, },
{ "key-uncrop-left", ACTIONID_UNCROP_LEFT, },
{ "key-crop-bottom", ACTIONID_CROP_BOTTOM, },
{ "key-uncrop-bottom", ACTIONID_UNCROP_BOTTOM, },
{ "key-crop-right", ACTIONID_CROP_RIGHT, },
{ "key-uncrop-right", ACTIONID_UNCROP_RIGHT, },
{ "key-nav-activate", ACTIONID_NAV_ACTIVATE, },
{ "key-nav-up", ACTIONID_NAV_UP, },
{ "key-nav-down", ACTIONID_NAV_DOWN, },
{ "key-nav-left", ACTIONID_NAV_LEFT, },
{ "key-nav-right", ACTIONID_NAV_RIGHT, },
{ "key-disc-menu", ACTIONID_DISC_MENU, },
{ "key-title-prev", ACTIONID_TITLE_PREV, },
{ "key-title-next", ACTIONID_TITLE_NEXT, },
{ "key-chapter-prev", ACTIONID_CHAPTER_PREV, },
{ "key-chapter-next", ACTIONID_CHAPTER_NEXT, },
{ "key-zoom-quarter", ACTIONID_ZOOM_QUARTER, },
{ "key-zoom-half", ACTIONID_ZOOM_HALF, },
{ "key-zoom-original", ACTIONID_ZOOM_ORIGINAL, },
{ "key-zoom-double", ACTIONID_ZOOM_DOUBLE, },
{ "key-set-bookmark1", ACTIONID_SET_BOOKMARK1, },
{ "key-set-bookmark2", ACTIONID_SET_BOOKMARK2, },
{ "key-set-bookmark3", ACTIONID_SET_BOOKMARK3, },
{ "key-set-bookmark4", ACTIONID_SET_BOOKMARK4, },
{ "key-set-bookmark5", ACTIONID_SET_BOOKMARK5, },
{ "key-set-bookmark6", ACTIONID_SET_BOOKMARK6, },
{ "key-set-bookmark7", ACTIONID_SET_BOOKMARK7, },
{ "key-set-bookmark8", ACTIONID_SET_BOOKMARK8, },
{ "key-set-bookmark9", ACTIONID_SET_BOOKMARK9, },
{ "key-set-bookmark10", ACTIONID_SET_BOOKMARK10, },
{ "key-play-bookmark1", ACTIONID_PLAY_BOOKMARK1, },
{ "key-play-bookmark2", ACTIONID_PLAY_BOOKMARK2, },
{ "key-play-bookmark3", ACTIONID_PLAY_BOOKMARK3, },
{ "key-play-bookmark4", ACTIONID_PLAY_BOOKMARK4, },
{ "key-play-bookmark5", ACTIONID_PLAY_BOOKMARK5, },
{ "key-play-bookmark6", ACTIONID_PLAY_BOOKMARK6, },
{ "key-play-bookmark7", ACTIONID_PLAY_BOOKMARK7, },
{ "key-play-bookmark8", ACTIONID_PLAY_BOOKMARK8, },
{ "key-play-bookmark9", ACTIONID_PLAY_BOOKMARK9, },
{ "key-play-bookmark10", ACTIONID_PLAY_BOOKMARK10, },
{ "key-history-back", ACTIONID_HISTORY_BACK, },
{ "key-history-forward", ACTIONID_HISTORY_FORWARD, },
{ "key-record", ACTIONID_RECORD, },
{ "key-dump", ACTIONID_DUMP, },
{ "key-random", ACTIONID_RANDOM, },
{ "key-loop", ACTIONID_LOOP, },
{ "key-wallpaper", ACTIONID_WALLPAPER, },
{ "key-menu-on", ACTIONID_MENU_ON, },
{ "key-menu-off", ACTIONID_MENU_OFF, },
{ "key-menu-right", ACTIONID_MENU_RIGHT, },
{ "key-menu-left", ACTIONID_MENU_LEFT, },
{ "key-menu-up", ACTIONID_MENU_UP, },
{ "key-menu-down", ACTIONID_MENU_DOWN, },
{ "key-menu-select", ACTIONID_MENU_SELECT, },
{ "key-audiodevice-cycle", ACTIONID_AUDIODEVICE_CYCLE, },
{ "key-toggle-autoscale", ACTIONID_TOGGLE_AUTOSCALE, },
{ "key-incr-scalefactor", ACTIONID_SCALE_UP, },
{ "key-decr-scalefactor", ACTIONID_SCALE_DOWN, },
};
const size_t libvlc_hotkeys_size = sizeof (libvlc_hotkeys);
const size_t libvlc_actions_count =
sizeof (libvlc_actions) / sizeof (libvlc_actions[0]);
......@@ -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