diff --git a/keygrabber.c b/keygrabber.c index 498f4b9a1..50bb6c6f1 100644 --- a/keygrabber.c +++ b/keygrabber.c @@ -537,55 +537,38 @@ keygrabber_handlekpress(lua_State *L, xcb_key_press_event_t *e) { xcb_keysym_t ksym = 0; char buf[MAX(MB_LEN_MAX, 32)]; - int i = 1; if (!key_press_lookup_string(e, buf, countof(buf), &ksym)) return false; lua_newtable(L); - if(XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_CONTROL) - { - lua_pushliteral(L, "Control"); - lua_rawseti(L, -2, i++); - } - if(XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_LOCK) - { - lua_pushliteral(L, "Lock"); - lua_rawseti(L, -2, i++); - } - if(XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_SHIFT) - { - lua_pushliteral(L, "Shift"); - lua_rawseti(L, -2, i++); - } - if(XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_1) - { - lua_pushliteral(L, "Mod1"); - lua_rawseti(L, -2, i++); - } - if(XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_2) - { - lua_pushliteral(L, "Mod2"); - lua_rawseti(L, -2, i++); - } - if(XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_3) - { - lua_pushliteral(L, "Mod3"); - lua_rawseti(L, -2, i++); - } - if(XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_4) - { - lua_pushliteral(L, "Mod4"); - lua_rawseti(L, -2, i++); - } - if(XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_5) - { - lua_pushliteral(L, "Mod5"); - lua_rawseti(L, -2, i++); - } + lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_CONTROL); + lua_setfield(L, -2, "Control"); + + lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_LOCK); + lua_setfield(L, -2, "Lock"); + + lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_SHIFT); + lua_setfield(L, -2, "Shift"); + + lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_1); + lua_setfield(L, -2, "Mod1"); + + lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_2); + lua_setfield(L, -2, "Mod2"); + + lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_3); + lua_setfield(L, -2, "Mod3"); + + lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_4); + lua_setfield(L, -2, "Mod4"); + + lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_5); + lua_setfield(L, -2, "Mod5"); lua_pushstring(L, buf); + return true; } diff --git a/lib/awful.lua.in b/lib/awful.lua.in index afd22ad16..c3e715ca4 100644 --- a/lib/awful.lua.in +++ b/lib/awful.lua.in @@ -1102,15 +1102,8 @@ function prompt.run(args, textbox, exe_callback, completion_callback, history_pa textbox.text = prettyprompt .. prompt_text_with_cursor(text, inv_col, cur_col, cur_pos) capi.keygrabber.run( function (mod, key) - local has_ctrl = false - - -- Compute modifiers keys - for k, v in ipairs(mod) do - if v == "Control" then has_ctrl = true end - end - -- Get out cases - if has_ctrl then + if mod.Control then if key == "c" or key == "g" then textbox.text = "" if done_callback then done_callback() end @@ -1136,7 +1129,7 @@ function prompt.run(args, textbox, exe_callback, completion_callback, history_pa end -- Control cases - if has_ctrl then + if mod.Control then if key == "a" then cur_pos = 1 elseif key == "b" then