key: split luaA_pushmodifiers() out of index
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
566e40638b
commit
e071514704
38
key.c
38
key.c
|
@ -376,6 +376,30 @@ luaA_key_array_get(lua_State *L, keybindings_t *keys)
|
||||||
return 1;
|
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.
|
/** Key object.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
|
@ -410,19 +434,7 @@ luaA_key_index(lua_State *L)
|
||||||
lua_pushstring(L, XKeysymToString(k->keysym));
|
lua_pushstring(L, XKeysymToString(k->keysym));
|
||||||
break;
|
break;
|
||||||
case A_TK_MODIFIERS:
|
case A_TK_MODIFIERS:
|
||||||
lua_newtable(L);
|
luaA_pushmodifiers(L, k->mod);
|
||||||
{
|
|
||||||
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++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case A_TK_PRESS:
|
case A_TK_PRESS:
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, k->press);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, k->press);
|
||||||
|
|
1
key.h
1
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 *);
|
int luaA_key_array_get(lua_State *, keybindings_t *);
|
||||||
|
|
||||||
void window_grabkeys(xcb_window_t, keybindings_t *);
|
void window_grabkeys(xcb_window_t, keybindings_t *);
|
||||||
|
int luaA_pushmodifiers(lua_State *, uint16_t);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue