Commit 469613e2 authored by dionoea's avatar dionoea

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().
parent 621afc68
...@@ -205,4 +205,7 @@ typedef enum vlc_key { ...@@ -205,4 +205,7 @@ typedef enum vlc_key {
ACTIONID_RATE_FASTER_FINE, ACTIONID_RATE_FASTER_FINE,
} vlc_key_t; } vlc_key_t;
VLC_EXPORT( vlc_key_t, vlc_GetActionId, (const char *psz_key) ) LIBVLC_USED;
#endif #endif
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <vlc_charset.h> #include <vlc_charset.h>
#include <vlc_aout.h> #include <vlc_aout.h>
#include <vlc_interface.h> #include <vlc_interface.h>
#include <vlc_keys.h>
#include <lua.h> /* Low level lua C API */ #include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */ #include <lauxlib.h> /* Higher level C API */
...@@ -209,6 +210,15 @@ static int vlclua_intf_should_die( lua_State *L ) ...@@ -209,6 +210,15 @@ static int vlclua_intf_should_die( lua_State *L )
return 1; 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[] = { ...@@ -224,6 +234,8 @@ static const luaL_Reg vlclua_misc_reg[] = {
{ "cachedir", vlclua_cachedir }, { "cachedir", vlclua_cachedir },
{ "datadir_list", vlclua_datadir_list }, { "datadir_list", vlclua_datadir_list },
{ "action_id", vlclua_action_id },
{ "mdate", vlclua_mdate }, { "mdate", vlclua_mdate },
{ "mwait", vlclua_mwait }, { "mwait", vlclua_mwait },
......
...@@ -23,7 +23,13 @@ end ...@@ -23,7 +23,13 @@ end
-- Trigger a hotkey -- Trigger a hotkey
function hotkey(arg) 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 end
-- Take a video snapshot -- Take a video snapshot
......
...@@ -447,7 +447,7 @@ function menu(name,client,value) ...@@ -447,7 +447,7 @@ function menu(name,client,value)
end end
function eval(client,val) function eval(client,val)
client:append(loadstring("return "..val)()) client:append(tostring(loadstring("return "..val)()))
end end
--[[ Declare commands, register their callback functions and provide --[[ Declare commands, register their callback functions and provide
......
...@@ -817,7 +817,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -817,7 +817,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
struct hotkey *p_keys = struct hotkey *p_keys =
malloc( (libvlc_actions_count + 1) * sizeof (*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++ ) for( size_t i = 0; i < libvlc_actions_count; i++ )
{ {
p_keys[i].psz_action = libvlc_actions[i].name; p_keys[i].psz_action = libvlc_actions[i].name;
......
...@@ -494,6 +494,7 @@ vlc_fourcc_GetYUVFallback ...@@ -494,6 +494,7 @@ vlc_fourcc_GetYUVFallback
vlc_fourcc_AreUVPlanesSwapped vlc_fourcc_AreUVPlanesSwapped
vlc_gai_strerror vlc_gai_strerror
vlc_gc_init vlc_gc_init
vlc_GetActionId
vlc_getaddrinfo vlc_getaddrinfo
vlc_getnameinfo vlc_getnameinfo
vlc_gettext vlc_gettext
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* action.c: key to action mapping * action.c: key to action mapping
***************************************************************************** *****************************************************************************
* Copyright © 2008 Rémi Denis-Courmont * Copyright © 2008 Rémi Denis-Courmont
* © 2009 Antoine Cellerier
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -24,6 +25,7 @@ ...@@ -24,6 +25,7 @@
#include <vlc_common.h> #include <vlc_common.h>
#include "../libvlc.h" #include "../libvlc.h"
#include <vlc_keys.h>
int vlc_key_to_action (vlc_object_t *libvlc, const char *varname, int vlc_key_to_action (vlc_object_t *libvlc, const char *varname,
vlc_value_t prevkey, vlc_value_t curkey, void *priv) 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, ...@@ -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); 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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment