key: split luaA_pushmodifiers() out of index

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-26 19:41:53 +02:00
parent 566e40638b
commit e071514704
2 changed files with 26 additions and 13 deletions

38
key.c
View File

@ -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);

1
key.h
View File

@ -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