[vlc-devel] [PATCH 12/22] actions: add vlc_actions_get_keycode

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Aug 3 15:10:45 CEST 2017


From: Thomas Guillem <thomas at gllm.fr>

---
 include/vlc_actions.h                 |  9 +++++++++
 modules/control/globalhotkeys/win32.c | 10 +---------
 modules/control/globalhotkeys/xcb.c   | 11 ++---------
 src/libvlccore.sym                    |  1 +
 src/misc/actions.c                    | 17 +++++++++++++++++
 5 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/include/vlc_actions.h b/include/vlc_actions.h
index 685264897a..e613e5a310 100644
--- a/include/vlc_actions.h
+++ b/include/vlc_actions.h
@@ -255,6 +255,15 @@ VLC_API vlc_action_id_t
 vlc_actions_get_id(const char *psz_key_name);
 
 /**
+ * Get a keycode from a action key name and vlc configuration
+ * \return a valid KEY_* or KEY_UNSET if the key is not found
+ */
+VLC_API uint_fast32_t
+vlc_actions_get_keycode(vlc_object_t *p_obj, const char *psz_key_name,
+                        bool b_global);
+#define vlc_actions_get_keycode(a, b, c) vlc_actions_get_keycode(VLC_OBJECT(a), b, c)
+
+/**
  * Get a list a key names
  * \return A NULL terminated list of const char *
  */
diff --git a/modules/control/globalhotkeys/win32.c b/modules/control/globalhotkeys/win32.c
index ff3f3bac61..c3b02e642a 100644
--- a/modules/control/globalhotkeys/win32.c
+++ b/modules/control/globalhotkeys/win32.c
@@ -170,15 +170,7 @@ static void *Thread( void *p_data )
     for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );
          *ppsz_keys != NULL; ppsz_keys++ )
     {
-        char varname[12 + strlen( *ppsz_keys )];
-        sprintf( varname, "global-key-%s", *ppsz_keys );
-
-        char *key = var_InheritString( p_intf, varname );
-        if( key == NULL )
-            continue;
-
-        UINT i_key = vlc_str2keycode( key );
-        free( key );
+        uint_fast32_t i_key = vlc_actions_get_keycode( p_intf, *ppsz_keys, true );
         if( i_key == KEY_UNSET )
             continue;
 
diff --git a/modules/control/globalhotkeys/xcb.c b/modules/control/globalhotkeys/xcb.c
index fb85377383..a6dca21ac2 100644
--- a/modules/control/globalhotkeys/xcb.c
+++ b/modules/control/globalhotkeys/xcb.c
@@ -293,15 +293,8 @@ static bool Mapping( intf_thread_t *p_intf )
     for( const char* const* ppsz_keys = vlc_actions_get_key_names( p_intf );
          *ppsz_keys != NULL; ppsz_keys++ )
     {
-        char varname[12 + strlen( *ppsz_keys )];
-        sprintf( varname, "global-key-%s", *ppsz_keys );
-
-        char *key = var_InheritString( p_intf, varname );
-        if( key == NULL )
-            continue;
-
-        uint_fast32_t i_vlc_key = vlc_str2keycode( key );
-        free( key );
+        uint_fast32_t i_vlc_key = vlc_actions_get_keycode( p_intf, *ppsz_keys,
+                                                           true );
         if( i_vlc_key == KEY_UNSET )
             continue;
 
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index a24cc0a4d5..c63f82923c 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -512,6 +512,7 @@ video_format_Setup
 video_format_Print
 vlc_actions_get_id
 vlc_actions_get_key_names
+vlc_actions_get_keycode
 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 1905b978c1..24351ac486 100644
--- a/src/misc/actions.c
+++ b/src/misc/actions.c
@@ -594,6 +594,23 @@ vlc_actions_get_id (const char *name)
     return (act != NULL) ? act->id : ACTIONID_NONE;
 }
 
+#undef vlc_actions_get_keycode
+uint_fast32_t
+vlc_actions_get_keycode(vlc_object_t *p_obj, const char *psz_key_name,
+                        bool b_global)
+{
+    char varname[12 /* "global-key-" */ + strlen( psz_key_name )];
+    sprintf( varname, "%skey-%s", b_global ? "global-" : "", psz_key_name );
+
+    char *psz_key = var_InheritString( p_obj, varname );
+    if( psz_key == NULL )
+        return KEY_UNSET;
+
+    uint_fast32_t i_key = vlc_str2keycode( psz_key );
+    free( psz_key );
+    return i_key;
+}
+
 #undef vlc_actions_get_key_names
 const char* const*
 vlc_actions_get_key_names(vlc_object_t *p_obj)
-- 
2.11.0



More information about the vlc-devel mailing list