button, key: emit events
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
04e55739fe
commit
4871dbb1aa
35
event.c
35
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); \
|
||||
|
|
2
key.c
2
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);
|
||||
|
||||
|
|
4
key.h
4
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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue