From 8193a9cf0c8048e839c6a501893dab00da7b8d28 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 16 Dec 2008 15:02:54 +0100 Subject: [PATCH] keygrabber: identify release events Signed-off-by: Julien Danjou --- event.c | 2 +- keygrabber.c | 15 +++++++++++++-- lib/awful/prompt.lua.in | 3 ++- lib/invaders.lua.in | 3 ++- lib/revelation.lua.in | 3 ++- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/event.c b/event.c index 6fcce307..b77c119b 100644 --- a/event.c +++ b/event.c @@ -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); diff --git a/keygrabber.c b/keygrabber.c index f41e6363..dc425bfc 100644 --- a/keygrabber.c +++ b/keygrabber.c @@ -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. diff --git a/lib/awful/prompt.lua.in b/lib/awful/prompt.lua.in index afebeb58..1d09beb5 100644 --- a/lib/awful/prompt.lua.in +++ b/lib/awful/prompt.lua.in @@ -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 diff --git a/lib/invaders.lua.in b/lib/invaders.lua.in index 5ac4e054..090bc83d 100644 --- a/lib/invaders.lua.in +++ b/lib/invaders.lua.in @@ -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 diff --git a/lib/revelation.lua.in b/lib/revelation.lua.in index d4ea09ff..3f043629 100644 --- a/lib/revelation.lua.in +++ b/lib/revelation.lua.in @@ -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()