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

core: Add a private pointer for hotkeys/actions handler

We cannot fully privatize this, as the global hotkeys plugin read the
list of actions through the public LibVLC instance pointer.
parent 965f2f1b
......@@ -334,6 +334,11 @@ static int keycmp (const void *a, const void *b)
#endif
}
struct vlc_actions
{
struct hotkey keys[0];
};
/**
* Get the action ID associated with a VLC key code, if any.
*/
......@@ -362,29 +367,27 @@ static int vlc_key_to_action (vlc_object_t *libvlc, const char *varname,
}
int vlc_InitActions (libvlc_int_t *libvlc)
struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc)
{
struct hotkey *keys;
struct vlc_actions *as = malloc (sizeof (*as) + (ACTIONS_COUNT + 1) * sizeof (*keys));
if (unlikely(as == NULL))
return NULL;
keys = as->keys;
var_Create (libvlc, "key-pressed", VLC_VAR_INTEGER);
var_Create (libvlc, "key-action", VLC_VAR_INTEGER);
keys = malloc ((ACTIONS_COUNT + 1) * sizeof (*keys));
if (keys == NULL)
{
libvlc->p_hotkeys = NULL;
return VLC_ENOMEM;
}
/* Initialize from configuration */
for (size_t i = 0; i < ACTIONS_COUNT; i++)
{
char *str = var_InheritString (libvlc, actions[i].name);
uint32_t code = str ? vlc_str2keycode (str) : KEY_UNSET;
keys[i].psz_action = actions[i].name;
keys[i].i_key = code;
keys[i].i_action = actions[i].value;
keys->psz_action = actions[i].name;
keys->i_key = code;
keys->i_action = actions[i].value;
#ifndef NDEBUG
if (i > 0
&& strcmp (actions[i-1].name, actions[i].name) >= 0)
......@@ -394,24 +397,27 @@ int vlc_InitActions (libvlc_int_t *libvlc)
abort ();
}
#endif
keys++;
}
qsort (keys, ACTIONS_COUNT, sizeof (*keys), keycmp);
qsort (as->keys, ACTIONS_COUNT, sizeof (*keys), keycmp);
keys[ACTIONS_COUNT].psz_action = NULL;
keys[ACTIONS_COUNT].i_key = 0;
keys[ACTIONS_COUNT].i_action = 0;
keys->psz_action = NULL;
keys->i_key = 0;
keys->i_action = 0;
libvlc->p_hotkeys = keys;
var_AddCallback (libvlc, "key-pressed", vlc_key_to_action, NULL);
libvlc->p_hotkeys = as->keys;
var_AddCallback (libvlc, "key-pressed", vlc_key_to_action, as);
return VLC_SUCCESS;
}
void vlc_DeinitActions (libvlc_int_t *libvlc)
void vlc_DeinitActions (libvlc_int_t *libvlc, struct vlc_actions *as)
{
if (unlikely(libvlc->p_hotkeys == NULL))
if (unlikely(as == NULL))
return;
var_DelCallback (libvlc, "key-pressed", vlc_key_to_action, NULL);
free ((void *)libvlc->p_hotkeys);
var_DelCallback (libvlc, "key-pressed", vlc_key_to_action, as);
free (as);
libvlc->p_hotkeys = NULL;
}
......
......@@ -763,7 +763,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/*
* Initialize hotkey handling
*/
vlc_InitActions( p_libvlc );
priv->actions = vlc_InitActions( p_libvlc );
/* Create a variable for showing the fullscreen interface */
var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL );
......@@ -1054,7 +1054,7 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
/* Free module bank. It is refcounted, so we call this each time */
module_EndBank( p_libvlc, true );
vlc_DeinitActions( p_libvlc );
vlc_DeinitActions( p_libvlc, priv->actions );
}
/**
......
......@@ -28,8 +28,9 @@
typedef struct variable_t variable_t;
/* Actions (hot keys) */
extern int vlc_InitActions (libvlc_int_t *);
extern void vlc_DeinitActions (libvlc_int_t *);
struct vlc_actions;
struct vlc_actions *vlc_InitActions (libvlc_int_t *);
extern void vlc_DeinitActions (libvlc_int_t *, struct vlc_actions *);
size_t vlc_towc (const char *str, uint32_t *restrict pwc);
......@@ -211,6 +212,7 @@ typedef struct libvlc_priv_t
#ifdef ENABLE_SOUT
sap_handler_t *p_sap; ///< SAP SDP advertiser
#endif
struct vlc_actions *actions; ///< Hotkeys handler
/* Interfaces */
struct intf_thread_t *p_intf; ///< Interfaces linked-list
......
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