]> git.sesse.net Git - vlc/commitdiff
Add vlc_GetActionId().
authorAntoine Cellerier <dionoea@videolan.org>
Sun, 27 Dec 2009 20:53:02 +0000 (21:53 +0100)
committerAntoine Cellerier <dionoea@videolan.org>
Sun, 27 Dec 2009 21:05:22 +0000 (22:05 +0100)
vlc_GetActionId() is used to get an ACTIONID from the action's name, which is way better than getting the hotkey setting from the hotkey name and then, if the hotkey was set, looking up the corresponding action id ... since this also works if the hotkey isn't set. Export this function in lua and use in common.hotkey().

include/vlc_keys.h
modules/misc/lua/libs/misc.c
share/lua/intf/modules/common.lua
share/lua/intf/rc.lua
src/libvlc.c
src/libvlccore.sym
src/misc/action.c

index a9c64e5d68c50e176b5337a5b18016c95096f499..1a0b29f5bda0ce0254c3f20711e29f44a81bd10b 100644 (file)
@@ -205,4 +205,7 @@ typedef enum vlc_key {
     ACTIONID_RATE_FASTER_FINE,
 
 } vlc_key_t;
+
+VLC_EXPORT( vlc_key_t, vlc_GetActionId, (const char *psz_key) ) LIBVLC_USED;
+
 #endif
index e92da8cb32af9b3c7e1099cd7763d09044361113..09a8e272701b7f9e91fb68c141b15f6c8b938347 100644 (file)
@@ -39,6 +39,7 @@
 #include <vlc_charset.h>
 #include <vlc_aout.h>
 #include <vlc_interface.h>
+#include <vlc_keys.h>
 
 #include <lua.h>        /* Low level lua C API */
 #include <lauxlib.h>    /* Higher level C API */
@@ -209,6 +210,15 @@ static int vlclua_intf_should_die( lua_State *L )
     return 1;
 }
 
+static int vlclua_action_id( lua_State *L )
+{
+    vlc_key_t i_key = vlc_GetActionId( luaL_checkstring( L, 1 ) );
+    if (i_key == 0)
+        return 0;
+    lua_pushnumber( L, i_key );
+    return 1;
+}
+
 /*****************************************************************************
  *
  *****************************************************************************/
@@ -224,6 +234,8 @@ static const luaL_Reg vlclua_misc_reg[] = {
     { "cachedir", vlclua_cachedir },
     { "datadir_list", vlclua_datadir_list },
 
+    { "action_id", vlclua_action_id },
+
     { "mdate", vlclua_mdate },
     { "mwait", vlclua_mwait },
 
index f2c80618ed7c6c77952154b21e4caf4621325e93..c02d4e7e73e8fac0887f6a5991fed1bb6c5e2108 100644 (file)
@@ -23,7 +23,13 @@ end
 
 -- Trigger a hotkey
 function hotkey(arg)
-    vlc.var.set( vlc.object.libvlc(), "key-pressed", vlc.config.get( arg ) )
+    local id = vlc.misc.action_id( arg )
+    if id ~= nil then
+        vlc.var.set( vlc.object.libvlc(), "key-action", id )
+        return true
+    else
+        return false
+    end
 end
 
 -- Take a video snapshot
index 6acbfedf1fec8524312fb230f0999363eaa61b94..ff75eb420597239e903b710f21af5809945cf87b 100644 (file)
@@ -447,7 +447,7 @@ function menu(name,client,value)
 end
 
 function eval(client,val)
-    client:append(loadstring("return "..val)())
+    client:append(tostring(loadstring("return "..val)()))
 end
 
 --[[ Declare commands, register their callback functions and provide
index 96dae5c2364eebd801174025035a2decb934580f..a6e6b69cbf11778994293ed524cc1ea9759cb252 100644 (file)
@@ -817,7 +817,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         struct hotkey *p_keys =
             malloc( (libvlc_actions_count + 1) * sizeof (*p_keys) );
 
-       /* Initialize from configuration */
+        /* Initialize from configuration */
         for( size_t i = 0; i < libvlc_actions_count; i++ )
         {
             p_keys[i].psz_action = libvlc_actions[i].name;
index ce5fa3c1fc215a7274a6142a3118655646fc5408..484cd77dde009cca208d57d3e80c7f1ea2d49e99 100644 (file)
@@ -494,6 +494,7 @@ vlc_fourcc_GetYUVFallback
 vlc_fourcc_AreUVPlanesSwapped
 vlc_gai_strerror
 vlc_gc_init
+vlc_GetActionId
 vlc_getaddrinfo
 vlc_getnameinfo
 vlc_gettext
index af731a39e621805f9b7b3fb6c0bbdfd1dccdf0f0..e5eb94f8e58d2aeab124cc6bf65c70c826d4021f 100644 (file)
@@ -2,6 +2,7 @@
  * action.c: key to action mapping
  *****************************************************************************
  * Copyright © 2008 Rémi Denis-Courmont
+ *           © 2009 Antoine Cellerier
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,6 +25,7 @@
 
 #include <vlc_common.h>
 #include "../libvlc.h"
+#include <vlc_keys.h>
 
 int vlc_key_to_action (vlc_object_t *libvlc, const char *varname,
                        vlc_value_t prevkey, vlc_value_t curkey, void *priv)
@@ -44,3 +46,11 @@ int vlc_key_to_action (vlc_object_t *libvlc, const char *varname,
     return var_SetInteger (libvlc, "key-action", key->i_action);
 }
 
+vlc_key_t vlc_GetActionId(const char *name)
+{
+    for (size_t i = 0; i < libvlc_actions_count; i++)
+        if (!strcmp(libvlc_actions[i].name, name))
+            return libvlc_actions[i].value;
+    return 0;
+}
+