From 469613e252bc8b0b22e883d88e0be0a6f7b0a4ff Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Sun, 27 Dec 2009 21:53:02 +0100 Subject: [PATCH] Add vlc_GetActionId(). 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 | 3 +++ modules/misc/lua/libs/misc.c | 12 ++++++++++++ share/lua/intf/modules/common.lua | 8 +++++++- share/lua/intf/rc.lua | 2 +- src/libvlc.c | 2 +- src/libvlccore.sym | 1 + src/misc/action.c | 10 ++++++++++ 7 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/vlc_keys.h b/include/vlc_keys.h index a9c64e5d68..1a0b29f5bd 100644 --- a/include/vlc_keys.h +++ b/include/vlc_keys.h @@ -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 diff --git a/modules/misc/lua/libs/misc.c b/modules/misc/lua/libs/misc.c index e92da8cb32..09a8e27270 100644 --- a/modules/misc/lua/libs/misc.c +++ b/modules/misc/lua/libs/misc.c @@ -39,6 +39,7 @@ #include #include #include +#include #include /* Low level lua C API */ #include /* 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 }, diff --git a/share/lua/intf/modules/common.lua b/share/lua/intf/modules/common.lua index f2c80618ed..c02d4e7e73 100644 --- a/share/lua/intf/modules/common.lua +++ b/share/lua/intf/modules/common.lua @@ -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 diff --git a/share/lua/intf/rc.lua b/share/lua/intf/rc.lua index 6acbfedf1f..ff75eb4205 100644 --- a/share/lua/intf/rc.lua +++ b/share/lua/intf/rc.lua @@ -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 diff --git a/src/libvlc.c b/src/libvlc.c index 96dae5c236..a6e6b69cbf 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -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; diff --git a/src/libvlccore.sym b/src/libvlccore.sym index ce5fa3c1fc..484cd77dde 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -494,6 +494,7 @@ vlc_fourcc_GetYUVFallback vlc_fourcc_AreUVPlanesSwapped vlc_gai_strerror vlc_gc_init +vlc_GetActionId vlc_getaddrinfo vlc_getnameinfo vlc_gettext diff --git a/src/misc/action.c b/src/misc/action.c index af731a39e6..e5eb94f8e5 100644 --- a/src/misc/action.c +++ b/src/misc/action.c @@ -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 #include "../libvlc.h" +#include 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; +} + -- 2.39.2