On Mon, Feb 20, 2012 at 7:39 PM, Uli Schlachter <[email protected]> wrote: > On 19.02.2012 14:56, Anurag Priyam wrote: >> It feels silly to return true from the callback to keygrabber.run to >> keep grabbing. [....] > Pointers? I would like to change it if possible. > > keygrabber.run() saves the given function in globalconf.keygrabber. This > function is then called from event.c in event_handle_key(). This code also > checks the return value from the function via lua_isboolean() and > lua_toboolean() (event.c, line 519) and possibly calls keygrabber.stop().
Lua's C stack based API is not very intuitive (or maybe I haven't got a hang of it yet). Hope I have got it right. The patch does seem to work here. -- Anurag Priyam
From e86dc4725bca7c0d64691157047dc787a627d02b Mon Sep 17 00:00:00 2001 From: Anurag Priyam <[email protected]> Date: Tue, 21 Feb 2012 20:25:55 +0530 Subject: [PATCH] keygrabber: continue grabbing till keygrabber.stop is explicitly called Returning true from the callback just to signal keygrabber to continue grabbing felt redundant (and silly :|). This will break old code that relied on returning false to stop grabbing, instead of calling keygrabber.stop. And fix keygrabber docs. Signed-off-by: Anurag Priyam <[email protected]> --- event.c | 2 -- keygrabber.c | 3 +-- luadoc/keygrabber.lua | 16 ++++++++-------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/event.c b/event.c index db18807..c28a3ca 100644 --- a/event.c +++ b/event.c @@ -516,8 +516,6 @@ event_handle_key(xcb_key_press_event_t *ev) warn("error running function: %s", lua_tostring(globalconf.L, -1)); luaA_keygrabber_stop(globalconf.L); } - else if(!lua_isboolean(globalconf.L, -1) || !lua_toboolean(globalconf.L, -1)) - luaA_keygrabber_stop(globalconf.L); } lua_pop(globalconf.L, 1); /* pop returned value or function if not called */ } diff --git a/keygrabber.c b/keygrabber.c index 85c20a9..6f683a5 100644 --- a/keygrabber.c +++ b/keygrabber.c @@ -88,8 +88,7 @@ keygrabber_handlekpress(lua_State *L, xcb_key_press_event_t *e) } /** 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. + * press, until keygrabber.stop is called. * The function is called with 3 arguments: * a table containing modifiers keys, a string with the key pressed and a * string with either "press" or "release" to indicate the event type. diff --git a/luadoc/keygrabber.lua b/luadoc/keygrabber.lua index f7ae788..8b70196 100644 --- a/luadoc/keygrabber.lua +++ b/luadoc/keygrabber.lua @@ -3,21 +3,21 @@ -- @copyright 2008-2009 Julien Danjou module("keygrabber") ---- 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 3 arguments: +--- +-- Grab keyboard and read pressed keys, calling callback function at each key +-- press, until keygrabber.stop is called. +-- The callback function is passed three arguments: -- a table containing modifiers keys, a string with the key pressed and a -- string with either "press" or "release" to indicate the event type. --- @param func A callback function as described above. +-- @param callback A callback function as described above. -- @name run -- @class function -- @usage Following function can be bound to a key, and used to resize a client -- using keyboard. -- <p><code> -- function resize(c) <br/> --- keygrabber.run(function(mod, key, event) </br> --- if event == "release" then return true end </br><br/> +-- keygrabber.run(function(mod, key, event) </br> +-- if event == "release" then return end </br></br> -- -- if key == 'Up' then awful.client.moveresize(0, 0, 0, 5, c) <br/> -- elseif key == 'Down' then awful.client.moveresize(0, 0, 0, -5, c) <br/> @@ -26,7 +26,7 @@ module("keygrabber") -- else keygrabber.stop() <br/> -- end <br/><br/> -- --- return true <br/> +-- end) <br/> -- end <br/> -- </code></p> -- 1.7.9
