[vlc-devel] [PATCH 11/22] actions: replace libvlc->p_hotkeys
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Thu Aug 3 15:10:44 CEST 2017
From: Thomas Guillem <thomas at gllm.fr>
Use vlc_actions_get_key_names instead
---
include/vlc_actions.h | 11 +++++++----
include/vlc_main.h | 5 -----
modules/control/globalhotkeys/win32.c | 18 ++++++++----------
modules/control/globalhotkeys/xcb.c | 9 ++++-----
modules/gui/macosx/VLCSimplePrefsController.m | 1 -
src/libvlccore.sym | 1 +
src/misc/actions.c | 22 +++++++++++++---------
7 files changed, 33 insertions(+), 34 deletions(-)
diff --git a/include/vlc_actions.h b/include/vlc_actions.h
index c69f33ac7b..685264897a 100644
--- a/include/vlc_actions.h
+++ b/include/vlc_actions.h
@@ -254,9 +254,12 @@ typedef enum vlc_action_id {
VLC_API vlc_action_id_t
vlc_actions_get_id(const char *psz_key_name);
-struct hotkey
-{
- const char *psz_action;
-};
+/**
+ * Get a list a key names
+ * \return A NULL terminated list of const char *
+ */
+VLC_API const char* const*
+vlc_actions_get_key_names(vlc_object_t *p_obj);
+#define vlc_actions_get_key_names(x) vlc_actions_get_key_names(VLC_OBJECT(x))
#endif
diff --git a/include/vlc_main.h b/include/vlc_main.h
index 142ce01081..77866f2d31 100644
--- a/include/vlc_main.h
+++ b/include/vlc_main.h
@@ -26,8 +26,6 @@
* This file defines libvlc_int_t internal libvlc instance
*/
-struct hotkey;
-
/*****************************************************************************
* libvlc_internal_instance_t
*****************************************************************************
@@ -36,8 +34,5 @@ struct hotkey;
struct libvlc_int_t
{
VLC_COMMON_MEMBERS
-
- /* Structure storing the action name / key associations */
- const struct hotkey *p_hotkeys;
};
diff --git a/modules/control/globalhotkeys/win32.c b/modules/control/globalhotkeys/win32.c
index fdde1f1b78..ff3f3bac61 100644
--- a/modules/control/globalhotkeys/win32.c
+++ b/modules/control/globalhotkeys/win32.c
@@ -167,12 +167,11 @@ static void *Thread( void *p_data )
(LONG_PTR)p_intf );
/* Registering of Hotkeys */
- for( const struct hotkey *p_hotkey = p_intf->obj.libvlc->p_hotkeys;
- p_hotkey->psz_action != NULL;
- p_hotkey++ )
+ for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );
+ *ppsz_keys != NULL; ppsz_keys++ )
{
- char varname[12 + strlen( p_hotkey->psz_action )];
- sprintf( varname, "global-key-%s", p_hotkey->psz_action );
+ char varname[12 + strlen( *ppsz_keys )];
+ sprintf( varname, "global-key-%s", *ppsz_keys );
char *key = var_InheritString( p_intf, varname );
if( key == NULL )
@@ -254,7 +253,7 @@ static void *Thread( void *p_data )
#undef HANDLE
#undef HANDLE2
- ATOM atom = GlobalAddAtomA( p_hotkey->psz_action );
+ ATOM atom = GlobalAddAtomA( *ppsz_keys );
if( !atom ) continue;
if( !RegisterHotKey( p_sys->hotkeyWindow, atom, i_keyMod, i_vk ) )
@@ -266,11 +265,10 @@ static void *Thread( void *p_data )
DispatchMessage( &message );
/* Unregistering of Hotkeys */
- for( const struct hotkey *p_hotkey = p_intf->obj.libvlc->p_hotkeys;
- p_hotkey->psz_action != NULL;
- p_hotkey++ )
+ for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );
+ *ppsz_keys != NULL; ppsz_keys++ )
{
- ATOM atom = GlobalFindAtomA( p_hotkey->psz_action );
+ ATOM atom = GlobalFindAtomA( *ppsz_keys );
if( !atom ) continue;
if( UnregisterHotKey( p_sys->hotkeyWindow, atom ) )
diff --git a/modules/control/globalhotkeys/xcb.c b/modules/control/globalhotkeys/xcb.c
index d4c335d98b..fb85377383 100644
--- a/modules/control/globalhotkeys/xcb.c
+++ b/modules/control/globalhotkeys/xcb.c
@@ -290,12 +290,11 @@ static bool Mapping( intf_thread_t *p_intf )
p_sys->p_map = NULL;
/* Registering of Hotkeys */
- for( const struct hotkey *p_hotkey = p_intf->obj.libvlc->p_hotkeys;
- p_hotkey->psz_action != NULL;
- p_hotkey++ )
+ for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );
+ *ppsz_keys != NULL; ppsz_keys++ )
{
- char varname[12 + strlen( p_hotkey->psz_action )];
- sprintf( varname, "global-key-%s", p_hotkey->psz_action );
+ char varname[12 + strlen( *ppsz_keys )];
+ sprintf( varname, "global-key-%s", *ppsz_keys );
char *key = var_InheritString( p_intf, varname );
if( key == NULL )
diff --git a/modules/gui/macosx/VLCSimplePrefsController.m b/modules/gui/macosx/VLCSimplePrefsController.m
index 422dbda94a..55928e39f6 100644
--- a/modules/gui/macosx/VLCSimplePrefsController.m
+++ b/modules/gui/macosx/VLCSimplePrefsController.m
@@ -705,7 +705,6 @@ static inline const char * __config_GetLabel(vlc_object_t *p_this, const char *p
/********************
* hotkeys settings *
********************/
- const struct hotkey *p_hotkeys = p_intf->obj.libvlc->p_hotkeys;
_hotkeySettings = [[NSMutableArray alloc] init];
NSMutableArray *tempArray_desc = [[NSMutableArray alloc] init];
NSMutableArray *tempArray_names = [[NSMutableArray alloc] init];
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 06893a19ef..a24cc0a4d5 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -511,6 +511,7 @@ video_format_IsSimilar
video_format_Setup
video_format_Print
vlc_actions_get_id
+vlc_actions_get_key_names
vlc_b64_decode
vlc_b64_decode_binary
vlc_b64_decode_binary_to_buffer
diff --git a/src/misc/actions.c b/src/misc/actions.c
index 0f7dac133e..1905b978c1 100644
--- a/src/misc/actions.c
+++ b/src/misc/actions.c
@@ -395,7 +395,7 @@ struct vlc_actions_t
{
void *map; /* Key map */
void *global_map; /* Grabbed/global key map */
- struct hotkey keys[1];
+ const char *ppsz_keys[];
};
static int vlc_key_to_action (vlc_object_t *obj, const char *varname,
@@ -502,14 +502,13 @@ int libvlc_InternalActionsInit (libvlc_int_t *libvlc)
assert(libvlc != NULL);
vlc_object_t *obj = VLC_OBJECT(libvlc);
- struct hotkey *keys;
- vlc_actions_t *as = malloc (sizeof (*as) + ACTIONS_COUNT * sizeof (*keys));
+ vlc_actions_t *as = malloc (sizeof (*as) + (1 + ACTIONS_COUNT)
+ * sizeof (*as->ppsz_keys));
if (unlikely(as == NULL))
return VLC_ENOMEM;
as->map = NULL;
as->global_map = NULL;
- keys = as->keys;
var_Create (obj, "key-pressed", VLC_VAR_INTEGER);
var_Create (obj, "global-key-pressed", VLC_VAR_INTEGER);
@@ -527,8 +526,7 @@ int libvlc_InternalActionsInit (libvlc_int_t *libvlc)
abort ();
}
#endif
- keys->psz_action = s_names2actions[i].psz;
- keys++;
+ as->ppsz_keys[i] = s_names2actions[i].psz;
char name[12 + MAXACTION];
@@ -536,7 +534,7 @@ int libvlc_InternalActionsInit (libvlc_int_t *libvlc)
init_action (obj, &as->map, name + 7, s_names2actions[i].id);
init_action (obj, &as->global_map, name, s_names2actions[i].id);
}
- keys->psz_action = NULL;
+ as->ppsz_keys[ACTIONS_COUNT] = NULL;
/* Initialize mouse wheel events */
add_wheel_mapping (&as->map, KEY_MOUSEWHEELRIGHT, KEY_MOUSEWHEELLEFT,
@@ -545,7 +543,6 @@ int libvlc_InternalActionsInit (libvlc_int_t *libvlc)
var_InheritInteger (obj, "hotkeys-y-wheel-mode"));
libvlc_priv(libvlc)->actions = as;
- libvlc->p_hotkeys = as->keys;
var_AddCallback (obj, "key-pressed", vlc_key_to_action, &as->map);
var_AddCallback (obj, "global-key-pressed", vlc_key_to_action,
&as->global_map);
@@ -571,7 +568,6 @@ void libvlc_InternalActionsClean (libvlc_int_t *libvlc)
tdestroy (as->map, free);
free (as);
libvlc_priv(libvlc)->actions = NULL;
- libvlc->p_hotkeys = NULL;
}
@@ -597,3 +593,11 @@ vlc_actions_get_id (const char *name)
act = bsearch(name, s_names2actions, ACTIONS_COUNT, sizeof(*act), actcmp);
return (act != NULL) ? act->id : ACTIONID_NONE;
}
+
+#undef vlc_actions_get_key_names
+const char* const*
+vlc_actions_get_key_names(vlc_object_t *p_obj)
+{
+ vlc_actions_t *as = libvlc_priv(p_obj->obj.libvlc)->actions;
+ return as->ppsz_keys;
+}
--
2.11.0
More information about the vlc-devel
mailing list