keybinding: add support for release event

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-12-16 12:00:51 +01:00
parent 13787c0ba8
commit 67a9f0d302
3 changed files with 36 additions and 13 deletions

20
event.c
View File

@ -538,7 +538,7 @@ event_handle_expose(void *data __attribute__ ((unused)),
* \param ev The event. * \param ev The event.
*/ */
static int static int
event_handle_keypress(void *data __attribute__ ((unused)), event_handle_key(void *data __attribute__ ((unused)),
xcb_connection_t *connection __attribute__ ((unused)), xcb_connection_t *connection __attribute__ ((unused)),
xcb_key_press_event_t *ev) xcb_key_press_event_t *ev)
{ {
@ -560,8 +560,19 @@ event_handle_keypress(void *data __attribute__ ((unused)),
else else
{ {
keybinding_t *k = keybinding_find(ev); keybinding_t *k = keybinding_find(ev);
if (k && k->fct != LUA_REFNIL)
luaA_dofunction(globalconf.L, k->fct, 0, 0); if(k)
switch(ev->response_type)
{
case XCB_KEY_PRESS:
if(k->press != LUA_REFNIL)
luaA_dofunction(globalconf.L, k->press, 0, 0);
break;
case XCB_KEY_RELEASE:
if(k->release != LUA_REFNIL)
luaA_dofunction(globalconf.L, k->release, 0, 0);
break;
}
} }
return 0; return 0;
@ -814,7 +825,8 @@ void a_xcb_set_event_handlers(void)
xcb_event_set_leave_notify_handler(&globalconf.evenths, event_handle_leavenotify, NULL); xcb_event_set_leave_notify_handler(&globalconf.evenths, event_handle_leavenotify, NULL);
xcb_event_set_motion_notify_handler(&globalconf.evenths, event_handle_motionnotify, NULL); xcb_event_set_motion_notify_handler(&globalconf.evenths, event_handle_motionnotify, NULL);
xcb_event_set_expose_handler(&globalconf.evenths, event_handle_expose, NULL); xcb_event_set_expose_handler(&globalconf.evenths, event_handle_expose, NULL);
xcb_event_set_key_press_handler(&globalconf.evenths, event_handle_keypress, NULL); xcb_event_set_key_press_handler(&globalconf.evenths, event_handle_key, NULL);
xcb_event_set_key_release_handler(&globalconf.evenths, event_handle_key, NULL);
xcb_event_set_map_request_handler(&globalconf.evenths, event_handle_maprequest, NULL); xcb_event_set_map_request_handler(&globalconf.evenths, event_handle_maprequest, NULL);
xcb_event_set_unmap_notify_handler(&globalconf.evenths, event_handle_unmapnotify, NULL); xcb_event_set_unmap_notify_handler(&globalconf.evenths, event_handle_unmapnotify, NULL);
xcb_event_set_client_message_handler(&globalconf.evenths, event_handle_clientmessage, NULL); xcb_event_set_client_message_handler(&globalconf.evenths, event_handle_clientmessage, NULL);

View File

@ -30,7 +30,8 @@ extern awesome_t globalconf;
static void static void
keybinding_delete(keybinding_t **kbp) keybinding_delete(keybinding_t **kbp)
{ {
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*kbp)->fct); luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*kbp)->press);
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*kbp)->release);
p_delete(kbp); p_delete(kbp);
} }
@ -313,7 +314,8 @@ luaA_keystore(keybinding_t *key, const char *str, ssize_t len)
* \luastack * \luastack
* \lparam A table with modifier keys. * \lparam A table with modifier keys.
* \lparam A key name. * \lparam A key name.
* \lparam A function to execute. * \lparam A function to execute on key press.
* \lparam A function to execute on key release.
* \lreturn The keybinding. * \lreturn The keybinding.
*/ */
static int static int
@ -322,18 +324,25 @@ luaA_keybinding_new(lua_State *L)
size_t i, len; size_t i, len;
keybinding_t *k; keybinding_t *k;
const char *key; const char *key;
luaA_ref press = LUA_REFNIL, release = LUA_REFNIL;
/* arg 2 is key mod table */ /* arg 2 is key mod table */
luaA_checktable(L, 2); luaA_checktable(L, 2);
/* arg 3 is key */ /* arg 3 is key */
key = luaL_checklstring(L, 3, &len); key = luaL_checklstring(L, 3, &len);
/* arg 4 is cmd to run */
luaA_checkfunction(L, 4); if(!lua_isnil(L, 4))
luaA_registerfct(L, 4, &press);
if(lua_gettop(L) == 5 && !lua_isnil(L, 5))
luaA_registerfct(L, 5, &release);
/* get the last arg as function */ /* get the last arg as function */
k = p_new(keybinding_t, 1); k = p_new(keybinding_t, 1);
luaA_keystore(k, key, len); luaA_keystore(k, key, len);
luaA_registerfct(L, 4, &k->fct);
k->press = press;
k->release = release;
len = lua_objlen(L, 2); len = lua_objlen(L, 2);
for(i = 1; i <= len; i++) for(i = 1; i <= len; i++)

View File

@ -36,8 +36,10 @@ typedef struct keybinding_t
xcb_keysym_t keysym; xcb_keysym_t keysym;
/** Keycode */ /** Keycode */
xcb_keycode_t keycode; xcb_keycode_t keycode;
/** Lua function to execute. */ /** Lua function to execute on press */
luaA_ref fct; luaA_ref press;
/** Lua function to execute on release */
luaA_ref release;
} keybinding_t; } keybinding_t;
ARRAY_TYPE(keybinding_t *, keybinding) ARRAY_TYPE(keybinding_t *, keybinding)