keygrabber: identify release events

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-12-16 15:02:54 +01:00
parent 25ac879569
commit 8193a9cf0c
5 changed files with 20 additions and 6 deletions

View file

@ -547,7 +547,7 @@ event_handle_key(void *data __attribute__ ((unused)),
lua_rawgeti(globalconf.L, LUA_REGISTRYINDEX, globalconf.keygrabber);
if(keygrabber_handlekpress(globalconf.L, ev))
{
if(lua_pcall(globalconf.L, 2, 1, 0))
if(lua_pcall(globalconf.L, 3, 1, 0))
{
warn("error running function: %s", lua_tostring(globalconf.L, -1));
luaA_keygrabber_stop(globalconf.L);

View file

@ -680,14 +680,25 @@ keygrabber_handlekpress(lua_State *L, xcb_key_press_event_t *e)
lua_pushstring(L, buf);
switch(e->response_type)
{
case XCB_KEY_PRESS:
lua_pushliteral(L, "press");
break;
case XCB_KEY_RELEASE:
lua_pushliteral(L, "release");
break;
}
return true;
}
/** Grab keyboard and read pressed keys, calling callback function at each key
* pressed. The callback function must return a boolean value: true to
* continue grabbing, false to stop.
* The function is called with 2 arguments:
* a table containing modifiers keys and a string, the key pressed.
* The function is called with 3 arguments:
* a table containing modifiers keys, a string with the key pressed and a
* string with eithe "press" or "release" to indicate the event type.
*
* \param L The Lua VM state.
* \return The number of elements pushed on stack.

View file

@ -159,7 +159,8 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
end
textbox.text = prettyprompt .. prompt_text_with_cursor(text, inv_col, cur_col, cur_pos, cur_ul, args.selectall)
capi.keygrabber.run(
function (mod, key)
function (mod, key, event)
if event ~= "press" then return true end
-- Get out cases
if (mod.Control and (key == "c" or key == "g"))
or (not mod.Control and key == "Escape") then

View file

@ -285,7 +285,8 @@ function enemies.handle ()
end
end
function keyhandler(mod, key)
function keyhandler(mod, key, event)
if event ~= "press" then return true end
if gamedata.highscore.getkeys then
if key:len() == 1 and gamedata.name:len() < 20 then
gamedata.name = gamedata.name .. key

View file

@ -76,7 +76,8 @@ end
-- Arrow keys move focus, Return selects, Escape cancels.
-- Ignores modifiers.
function keyboardhandler (restore)
return function (mod, key)
return function (mod, key, event)
if event ~= "press" then return true end
if key == "Escape" then
restore()
awful.tag.history.restore()