[awful] Handle hooks

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Lucas de Vries 2008-05-31 15:47:00 +02:00 committed by Julien Danjou
parent 878b4de509
commit 252fd45573
2 changed files with 60 additions and 6 deletions

View File

@ -216,12 +216,13 @@ function hook_timer ()
end end
-- Set up some hooks -- Set up some hooks
hooks.focus(hook_focus) awful.hooks.focus(hook_focus)
hooks.unfocus(hook_unfocus) awful.hooks.unfocus(hook_unfocus)
hooks.newclient(hook_newclient) awful.hooks.newclient(hook_newclient)
hooks.mouseover(hook_mouseover) awful.hooks.mouseover(hook_mouseover)
hooks.arrange(hook_arrange) awful.hooks.arrange(hook_arrange)
hooks.timer(1, hook_timer) awful.hooks.timer(1, hook_timer)
-- }}} -- }}}
-- Respect size hints -- Respect size hints

View File

@ -16,12 +16,15 @@ end
-- Grab environment we need -- Grab environment we need
local ipairs = ipairs local ipairs = ipairs
local pairs = pairs
local awesome = awesome local awesome = awesome
local screen = screen local screen = screen
local client = client local client = client
local tag = tag local tag = tag
local mouse = mouse local mouse = mouse
local os = os local os = os
local table = table
local hooks = hooks
-- Reset env -- Reset env
setfenv(1, P) setfenv(1, P)
@ -260,6 +263,56 @@ function layout_set(layout)
end end
end end
-- Hook functions, wrappers around awesome's hooks. functions so we
-- can easily add multiple functions per hook.
P.hooks = {}
P.myhooks = {}
for name, hook in pairs(hooks) do
if name ~= 'timer' then
P.hooks[name] = function (f)
if P.myhooks[name] == nil then
P.myhooks[name] = {}
hooks[name](function (...)
for i,o in pairs(P.myhooks[name]) do
P.myhooks[name][i]['callback'](...)
end
end)
end
table.insert(P.myhooks[name], {callback = f})
end
else
P.hooks[name] = function (time, f, runnow)
if P.myhooks[name] == nil then
P.myhooks[name] = {}
hooks[name](1, function (...)
for i,o in pairs(P.myhooks[name]) do
if P.myhooks[name][i]['counter'] >= P.myhooks[name][i]['timer'] then
P.myhooks[name][i]['counter'] = 1
P.myhooks[name][i]['callback'](...)
else
P.myhooks[name][i]['counter'] = P.myhooks[name][i]['counter']+1
end
end
end)
end
if runnow then
table.insert(P.myhooks[name], {callback = f, timer = time, counter = time})
else
table.insert(P.myhooks[name], {callback = f, timer = time, counter = 0})
end
end
end
end
function spawn(cmd) function spawn(cmd)
return os.execute(cmd .. "&") return os.execute(cmd .. "&")
end end