Allow usage of strings as key names for root.fake_input
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
47238fe6cf
commit
1e2d27ad4c
27
root.c
27
root.c
|
@ -19,6 +19,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/XF86keysym.h>
|
||||
#include <xcb/xtest.h>
|
||||
|
||||
#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,13 +77,21 @@ luaA_root_fake_input(lua_State *L)
|
|||
if (A_STREQ(stype, "key_press"))
|
||||
{
|
||||
type = XCB_KEY_PRESS;
|
||||
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;
|
||||
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"))
|
||||
{
|
||||
type = XCB_BUTTON_PRESS;
|
||||
|
|
Loading…
Reference in New Issue