diff --git a/event.c b/event.c index 920a1a459..8a5dd830c 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 81d3ee0d1..d0c5f3e72 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 52791409a..7d8ede975 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 4747dd547..251433de7 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