From 252fd455730be1abc0d9aae8ade8a927e762ce7c Mon Sep 17 00:00:00 2001 From: Lucas de Vries Date: Sat, 31 May 2008 15:47:00 +0200 Subject: [PATCH] [awful] Handle hooks Signed-off-by: Julien Danjou --- awesomerc.lua.in | 13 ++++++------ awful.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index c0dcab82b..31eec8989 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -216,12 +216,13 @@ function hook_timer () end -- Set up some hooks -hooks.focus(hook_focus) -hooks.unfocus(hook_unfocus) -hooks.newclient(hook_newclient) -hooks.mouseover(hook_mouseover) -hooks.arrange(hook_arrange) -hooks.timer(1, hook_timer) +awful.hooks.focus(hook_focus) +awful.hooks.unfocus(hook_unfocus) +awful.hooks.newclient(hook_newclient) +awful.hooks.mouseover(hook_mouseover) +awful.hooks.arrange(hook_arrange) +awful.hooks.timer(1, hook_timer) + -- }}} -- Respect size hints diff --git a/awful.lua b/awful.lua index ced149dcd..5c9311976 100644 --- a/awful.lua +++ b/awful.lua @@ -16,12 +16,15 @@ end -- Grab environment we need local ipairs = ipairs +local pairs = pairs local awesome = awesome local screen = screen local client = client local tag = tag local mouse = mouse local os = os +local table = table +local hooks = hooks -- Reset env setfenv(1, P) @@ -260,6 +263,56 @@ function layout_set(layout) 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) return os.execute(cmd .. "&") end