From 1e2d27ad4cbf4079416b95ef888f9507692ef0d8 Mon Sep 17 00:00:00 2001 From: Rob Hoelz Date: Wed, 7 Dec 2011 09:13:25 -0600 Subject: [PATCH] Allow usage of strings as key names for root.fake_input Signed-off-by: Uli Schlachter --- root.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/root.c b/root.c index e2733521..828d1ee5 100644 --- a/root.c +++ b/root.c @@ -19,6 +19,8 @@ * */ +#include +#include #include #include "globalconf.h" @@ -29,6 +31,23 @@ #include "common/xcursor.h" #include "common/xutil.h" +static xcb_keycode_t +_string_to_key_code(const char *s) +{ + xcb_keysym_t keysym; + xcb_keycode_t *keycodes; + + keysym = XStringToKeysym(s); + keycodes = xcb_key_symbols_get_keycode(globalconf.keysyms, keysym); + + if(keycodes) { + return keycodes[0]; /* XXX only returning the first is probably not + * the best */ + } else { + return 0; + } +} + /** Send fake events. Usually the current focused client will get it. * \param L The Lua VM state. * \return The number of element pushed on stack. @@ -58,12 +77,20 @@ luaA_root_fake_input(lua_State *L) if (A_STREQ(stype, "key_press")) { type = XCB_KEY_PRESS; - detail = luaL_checknumber(L, 2); /* keycode */ + if(lua_type(L, 2) == LUA_TSTRING) { + detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */ + } else { + detail = luaL_checknumber(L, 2); /* keycode */ + } } else if(A_STREQ(stype, "key_release")) { type = XCB_KEY_RELEASE; - detail = luaL_checknumber(L, 2); /* keycode */ + if(lua_type(L, 2) == LUA_TSTRING) { + detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */ + } else { + detail = luaL_checknumber(L, 2); /* keycode */ + } } else if(A_STREQ(stype, "button_press")) {