<html><head></head><body><div class="gmail_quote">Le 3 août 2017 16:10:45 GMT+03:00, "Hugo Beauzée-Luyssen" <hugo@beauzee.fr> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">From: Thomas Guillem <thomas@gllm.fr><br /><br />---<br /> include/vlc_actions.h                 |  9 +++++++++<br /> modules/control/globalhotkeys/win32.c | 10 +---------<br /> modules/control/globalhotkeys/xcb.c   | 11 ++---------<br /> src/libvlccore.sym                    |  1 +<br /> src/misc/actions.c                    | 17 +++++++++++++++++<br /> 5 files changed, 30 insertions(+), 18 deletions(-)<br /><br />diff --git a/include/vlc_actions.h b/include/vlc_actions.h<br />index 685264897a..e613e5a310 100644<br />--- a/include/vlc_actions.h<br />+++ b/include/vlc_actions.h<br />@@ -255,6 +255,15 @@ VLC_API vlc_action_id_t<br /> vlc_actions_get_id(const char *psz_key_name);<br /> <br /> /**<br />+ * Get a keycode from a action key name and vlc configuration<br />+ * \return a valid KEY_* or KEY_UNSET if the key is not found<br />+ */<br />+VLC_API uint_fast32_t<br />+vlc_actions_get_keycode(vlc_object_t *p_obj, const char *psz_key_name,<br />+                        bool b_global);<br />+#define vlc_actions_get_keycode(a, b, c) vlc_actions_get_keycode(VLC_OBJECT(a), b, c)<br />+<br />+/**<br />  * Get a list a key names<br />  * \return A NULL terminated list of const char *<br />  */<br />diff --git a/modules/control/globalhotkeys/win32.c b/modules/control/globalhotkeys/win32.c<br />index ff3f3bac61..c3b02e642a 100644<br />--- a/modules/control/globalhotkeys/win32.c<br />+++ b/modules/control/globalhotkeys/win32.c<br />@@ -170,15 +170,7 @@ static void *Thread( void *p_data )<br />     for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );<br />          *ppsz_keys != NULL; ppsz_keys++ )<br />     {<br />-        char varname[12 + strlen( *ppsz_keys )];<br />-        sprintf( varname, "global-key-%s", *ppsz_keys );<br />-<br />-        char *key = var_InheritString( p_intf, varname );<br />-        if( key == NULL )<br />-            continue;<br />-<br />-        UINT i_key = vlc_str2keycode( key );<br />-        free( key );<br />+        uint_fast32_t i_key = vlc_actions_get_keycode( p_intf, *ppsz_keys, true );<br />         if( i_key == KEY_UNSET )<br />             continue;<br /> <br />diff --git a/modules/control/globalhotkeys/xcb.c b/modules/control/globalhotkeys/xcb.c<br />index fb85377383..a6dca21ac2 100644<br />--- a/modules/control/globalhotkeys/xcb.c<br />+++ b/modules/control/globalhotkeys/xcb.c<br />@@ -293,15 +293,8 @@ static bool Mapping( intf_thread_t *p_intf )<br />     for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );<br />          *ppsz_keys != NULL; ppsz_keys++ )<br />     {<br />-        char varname[12 + strlen( *ppsz_keys )];<br />-        sprintf( varname, "global-key-%s", *ppsz_keys );<br />-<br />-        char *key = var_InheritString( p_intf, varname );<br />-        if( key == NULL )<br />-            continue;<br />-<br />-        uint_fast32_t i_vlc_key = vlc_str2keycode( key );<br />-        free( key );<br />+        uint_fast32_t i_vlc_key = vlc_actions_get_keycode( p_intf, *ppsz_keys,<br />+                                                           true );<br />         if( i_vlc_key == KEY_UNSET )<br />             continue;<br /> <br />diff --git a/src/libvlccore.sym b/src/libvlccore.sym<br />index a24cc0a4d5..c63f82923c 100644<br />--- a/src/libvlccore.sym<br />+++ b/src/libvlccore.sym<br />@@ -512,6 +512,7 @@ video_format_Setup<br /> video_format_Print<br /> vlc_actions_get_id<br /> vlc_actions_get_key_names<br />+vlc_actions_get_keycode<br /> vlc_b64_decode<br /> vlc_b64_decode_binary<br /> vlc_b64_decode_binary_to_buffer<br />diff --git a/src/misc/actions.c b/src/misc/actions.c<br />index 1905b978c1..24351ac486 100644<br />--- a/src/misc/actions.c<br />+++ b/src/misc/actions.c<br />@@ -594,6 +594,23 @@ vlc_actions_get_id (const char *name)<br />     return (act != NULL) ? act->id : ACTIONID_NONE;<br /> }<br /> <br />+#undef vlc_actions_get_keycode<br />+uint_fast32_t<br />+vlc_actions_get_keycode(vlc_object_t *p_obj, const char *psz_key_name,<br />+                        bool b_global)<br />+{<br />+    char varname[12 /* "global-key-" */ + strlen( psz_key_name )];<br />+    sprintf( varname, "%skey-%s", b_global ? "global-" : "", psz_key_name );<br />+<br />+    char *psz_key = var_InheritString( p_obj, varname );<br />+    if( psz_key == NULL )<br />+        return KEY_UNSET;<br />+<br />+    uint_fast32_t i_key = vlc_str2keycode( psz_key );<br />+    free( psz_key );<br />+    return i_key;<br />+}<br />+<br /> #undef vlc_actions_get_key_names<br /> const char* const*<br /> vlc_actions_get_key_names(vlc_object_t *p_obj)</pre></blockquote></div><br clear="all">Nack. AFAIR, the core can handle multiple mappings to single actions, which is obviously needed for, e.g. media keys. This API is broken by design.<br>
-- <br>
Rémi Denis-Courmont<br>
Typed on an inconvenient virtual keyboard</body></html>