button, key: emit events

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-06-25 16:32:15 +02:00
parent 04e55739fe
commit 4871dbb1aa
4 changed files with 15 additions and 37 deletions

27
event.c
View File

@ -63,40 +63,17 @@
} \ } \
for(; item_matching > 0; item_matching--) \ for(; item_matching > 0; item_matching--) \
{ \ { \
type *item = luaL_checkudata(globalconf.L, -1, #prefix); \
switch(ev->response_type) \ switch(ev->response_type) \
{ \ { \
case xcbeventprefix##_PRESS: \ case xcbeventprefix##_PRESS: \
if(item->press) \
{ \
for(int i = 0; i < nargs; i++) \ for(int i = 0; i < nargs; i++) \
lua_pushvalue(globalconf.L, - nargs - item_matching); \ lua_pushvalue(globalconf.L, - nargs - item_matching); \
if(oud) \ luaA_object_emit_signal(globalconf.L, - nargs - 1, "press", nargs); \
{ \
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); \
} \
break; \ break; \
case xcbeventprefix##_RELEASE: \ case xcbeventprefix##_RELEASE: \
if(item->release) \
{ \
for(int i = 0; i < nargs; i++) \ for(int i = 0; i < nargs; i++) \
lua_pushvalue(globalconf.L, - nargs - item_matching); \ lua_pushvalue(globalconf.L, - nargs - item_matching); \
if(oud) \ luaA_object_emit_signal(globalconf.L, - nargs - 1, "release", nargs); \
{ \
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); \
} \
break; \ break; \
} \ } \
lua_pop(globalconf.L, 1); \ lua_pop(globalconf.L, 1); \

2
key.c
View File

@ -1023,8 +1023,6 @@ luaA_key_new(lua_State *L)
luaA_checkfunction(L, 5); luaA_checkfunction(L, 5);
k = key_new(L); 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); luaA_keystore(L, -1, key, len);
k->modifiers = luaA_tomodifiers(L, 2); k->modifiers = luaA_tomodifiers(L, 2);

4
key.h
View File

@ -33,10 +33,6 @@ typedef struct keyb_t
xcb_keysym_t keysym; xcb_keysym_t keysym;
/** Keycode */ /** Keycode */
xcb_keycode_t keycode; xcb_keycode_t keycode;
/** Lua function to execute on press */
void *press;
/** Lua function to execute on release */
void *release;
} keyb_t; } keyb_t;
lua_class_t key_class; lua_class_t key_class;

View File

@ -26,11 +26,18 @@ ignore_modifiers = { "Lock", "Mod2" }
-- CapsLock off. -- CapsLock off.
-- @see capi.key -- @see capi.key
-- @return A table with one or several key objects. -- @return A table with one or several key objects.
function new(mod, ...) function new(mod, key, press, release)
local ret = {} local ret = {}
local subsets = util.subsets(ignore_modifiers) local subsets = util.subsets(ignore_modifiers)
for _, set in ipairs(subsets) do 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 end
return ret return ret
end end