From e0715147049298ba7dd7df299728fade079f51b6 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 26 Apr 2009 19:41:53 +0200 Subject: [PATCH] key: split luaA_pushmodifiers() out of index Signed-off-by: Julien Danjou --- key.c | 38 +++++++++++++++++++++++++------------- key.h | 1 + 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/key.c b/key.c index 740952ed1..d267adcd9 100644 --- a/key.c +++ b/key.c @@ -376,6 +376,30 @@ luaA_key_array_get(lua_State *L, keybindings_t *keys) return 1; } +/** Push a modifier set to a Lua table. + * \param L The Lua VM state. + * \param mod The modifier. + * \return The number of elements pushed on stack. + */ +int +luaA_pushmodifiers(lua_State *L, uint16_t modifiers) +{ + lua_newtable(L); + { + int i = 1; + for(uint32_t maski = XCB_MOD_MASK_SHIFT; maski <= XCB_BUTTON_MASK_ANY; maski <<= 1) + if(maski & modifiers) + { + const char *mod; + size_t slen; + xutil_key_mask_tostr(maski, &mod, &slen); + lua_pushlstring(L, mod, slen); + lua_rawseti(L, -2, i++); + } + } + return 1; +} + /** Key object. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -410,19 +434,7 @@ luaA_key_index(lua_State *L) lua_pushstring(L, XKeysymToString(k->keysym)); break; case A_TK_MODIFIERS: - lua_newtable(L); - { - int i = 1; - for(uint32_t maski = XCB_MOD_MASK_SHIFT; maski <= XCB_BUTTON_MASK_ANY; maski <<= 1) - if(maski & k->mod) - { - const char *mod; - size_t slen; - xutil_key_mask_tostr(maski, &mod, &slen); - lua_pushlstring(L, mod, slen); - lua_rawseti(L, -2, i++); - } - } + luaA_pushmodifiers(L, k->mod); break; case A_TK_PRESS: lua_rawgeti(L, LUA_REGISTRYINDEX, k->press); diff --git a/key.h b/key.h index 33df7b857..48ebecb6d 100644 --- a/key.h +++ b/key.h @@ -56,5 +56,6 @@ void luaA_key_array_set(lua_State *, int, keybindings_t *); int luaA_key_array_get(lua_State *, keybindings_t *); void window_grabkeys(xcb_window_t, keybindings_t *); +int luaA_pushmodifiers(lua_State *, uint16_t); #endif