On Sat, Apr 21, 2012 at 9:20 AM, dodo <dodo.the.l...@googlemail.com> wrote: >>> not quite. you tell awful.keygrabber that you want keys but if someone >>> after you asks for keys as well he will get it until he leaves it and >>> you're back in key control again. >>> the attachment might describe it in a better way than my words ^^
Patch 1: [...] +--- Keygrabber Stack +module("awful.keygrabber") + +-- Private data +local grabbers = {} +local keygrabbing = false + +--- The global key grabber +-- that distributes the key events to the last grabber in history +local function grabber(mod, key, event) + for i, g in ipairs(grabbers) do + -- continue if the grabber returns explicitly false + if g(mod, key, event) ~= false then + break + end + end +end + Say I run two grabbers one after the other. If the second grabber returns false, the event will be dispatched to the first one without removing the second one from the stack. This doesn't sound like what you previously said "...if someone after you asks for keys as well he will get it until he leaves it and you're back in key control again." Also, won't bad things happen if the first grabber calls awful.keygrabber.stop and is removed from the stack while the second one is still running? I think it is best to send key events to only the first grabber on the stack: local function grabber(mod, key, event) local g = grabbers[1] g(mod, key, event) end +--- Remove a key grabber from the history +-- @param g The key grabber that must be removed. +function stop(g) + for i, v in ipairs(grabbers) do + if v == g then + table.remove(grabbers, i) + break + end + end In the context of the above argument, I think you just need a stack 'pop' here: table.remove(grabbers, 1) [...] +--- Update key grabber history. +-- @param g The key grabber that will get the key events until it will be deleted or a new grabber is added. +function run(g) + -- Remove the grabber if its in stack + stop(g) + -- Record the grabber has latest added + table.insert(grabbers, 1, g) Why not insert at the last position and assume the tail of the table to be the head of the stack? http://www.lua.org/pil/19.2.html -- Anurag Priyam -- To unsubscribe, send mail to awesome-devel-unsubscr...@naquadah.org.