From 4871dbb1aa7e1833eea4825cbd204f2cc0af699e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 25 Jun 2009 16:32:15 +0200 Subject: [PATCH] button, key: emit events Signed-off-by: Julien Danjou --- event.c | 35 ++++++----------------------------- key.c | 2 -- key.h | 4 ---- lib/awful/key.lua.in | 11 +++++++++-- 4 files changed, 15 insertions(+), 37 deletions(-) diff --git a/event.c b/event.c index 920a1a45..8a5dd830 100644 --- a/event.c +++ b/event.c @@ -63,40 +63,17 @@ } \ for(; item_matching > 0; item_matching--) \ { \ - type *item = luaL_checkudata(globalconf.L, -1, #prefix); \ switch(ev->response_type) \ { \ case xcbeventprefix##_PRESS: \ - if(item->press) \ - { \ - for(int i = 0; i < nargs; i++) \ - lua_pushvalue(globalconf.L, - nargs - item_matching); \ - if(oud) \ - { \ - luaA_object_push_item(globalconf.L, abs_oud, item); \ - luaA_object_push_item(globalconf.L, -1, item->press); \ - lua_remove(globalconf.L, -2); \ - } \ - else \ - prefix##_push_item(globalconf.L, item, item->press); \ - luaA_dofunction(globalconf.L, nargs, 0); \ - } \ + for(int i = 0; i < nargs; i++) \ + lua_pushvalue(globalconf.L, - nargs - item_matching); \ + luaA_object_emit_signal(globalconf.L, - nargs - 1, "press", nargs); \ break; \ case xcbeventprefix##_RELEASE: \ - if(item->release) \ - { \ - for(int i = 0; i < nargs; i++) \ - lua_pushvalue(globalconf.L, - nargs - item_matching); \ - if(oud) \ - { \ - luaA_object_push_item(globalconf.L, abs_oud, item); \ - luaA_object_push_item(globalconf.L, -1, item->release); \ - lua_remove(globalconf.L, -2); \ - } \ - else \ - prefix##_push_item(globalconf.L, item, item->release); \ - luaA_dofunction(globalconf.L, nargs, 0); \ - } \ + for(int i = 0; i < nargs; i++) \ + lua_pushvalue(globalconf.L, - nargs - item_matching); \ + luaA_object_emit_signal(globalconf.L, - nargs - 1, "release", nargs); \ break; \ } \ lua_pop(globalconf.L, 1); \ diff --git a/key.c b/key.c index 81d3ee0d..d0c5f3e7 100644 --- a/key.c +++ b/key.c @@ -1023,8 +1023,6 @@ luaA_key_new(lua_State *L) luaA_checkfunction(L, 5); k = key_new(L); - k->press = luaA_object_ref_item(L, -1, 4); - k->release = luaA_object_ref_item(L, -1, 4); luaA_keystore(L, -1, key, len); k->modifiers = luaA_tomodifiers(L, 2); diff --git a/key.h b/key.h index 52791409..7d8ede97 100644 --- a/key.h +++ b/key.h @@ -33,10 +33,6 @@ typedef struct keyb_t xcb_keysym_t keysym; /** Keycode */ xcb_keycode_t keycode; - /** Lua function to execute on press */ - void *press; - /** Lua function to execute on release */ - void *release; } keyb_t; lua_class_t key_class; diff --git a/lib/awful/key.lua.in b/lib/awful/key.lua.in index 4747dd54..251433de 100644 --- a/lib/awful/key.lua.in +++ b/lib/awful/key.lua.in @@ -26,11 +26,18 @@ ignore_modifiers = { "Lock", "Mod2" } -- CapsLock off. -- @see capi.key -- @return A table with one or several key objects. -function new(mod, ...) +function new(mod, key, press, release) local ret = {} local subsets = util.subsets(ignore_modifiers) for _, set in ipairs(subsets) do - ret[#ret + 1] = capi.key(util.table.join(mod, set), ...) + ret[#ret + 1] = capi.key({ modifiers = util.table.join(mod, set), + key = key }) + if press then + ret[#ret]:add_signal("press", function(kobj, ...) press(...) end) + end + if release then + ret[#ret]:add_signal("release", function(kobj, ...) release(...) end) + end end return ret end