keybinding: add support for release event
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
13787c0ba8
commit
67a9f0d302
24
event.c
24
event.c
|
@ -538,9 +538,9 @@ event_handle_expose(void *data __attribute__ ((unused)),
|
|||
* \param ev The event.
|
||||
*/
|
||||
static int
|
||||
event_handle_keypress(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection __attribute__ ((unused)),
|
||||
xcb_key_press_event_t *ev)
|
||||
event_handle_key(void *data __attribute__ ((unused)),
|
||||
xcb_connection_t *connection __attribute__ ((unused)),
|
||||
xcb_key_press_event_t *ev)
|
||||
{
|
||||
if(globalconf.keygrabber != LUA_REFNIL)
|
||||
{
|
||||
|
@ -560,8 +560,19 @@ event_handle_keypress(void *data __attribute__ ((unused)),
|
|||
else
|
||||
{
|
||||
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;
|
||||
|
@ -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_motion_notify_handler(&globalconf.evenths, event_handle_motionnotify, 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_unmap_notify_handler(&globalconf.evenths, event_handle_unmapnotify, NULL);
|
||||
xcb_event_set_client_message_handler(&globalconf.evenths, event_handle_clientmessage, NULL);
|
||||
|
|
19
keybinding.c
19
keybinding.c
|
@ -30,7 +30,8 @@ extern awesome_t globalconf;
|
|||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -313,7 +314,8 @@ luaA_keystore(keybinding_t *key, const char *str, ssize_t len)
|
|||
* \luastack
|
||||
* \lparam A table with modifier keys.
|
||||
* \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.
|
||||
*/
|
||||
static int
|
||||
|
@ -322,18 +324,25 @@ luaA_keybinding_new(lua_State *L)
|
|||
size_t i, len;
|
||||
keybinding_t *k;
|
||||
const char *key;
|
||||
luaA_ref press = LUA_REFNIL, release = LUA_REFNIL;
|
||||
|
||||
/* arg 2 is key mod table */
|
||||
luaA_checktable(L, 2);
|
||||
/* arg 3 is key */
|
||||
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 */
|
||||
k = p_new(keybinding_t, 1);
|
||||
luaA_keystore(k, key, len);
|
||||
luaA_registerfct(L, 4, &k->fct);
|
||||
|
||||
k->press = press;
|
||||
k->release = release;
|
||||
|
||||
len = lua_objlen(L, 2);
|
||||
for(i = 1; i <= len; i++)
|
||||
|
|
|
@ -36,8 +36,10 @@ typedef struct keybinding_t
|
|||
xcb_keysym_t keysym;
|
||||
/** Keycode */
|
||||
xcb_keycode_t keycode;
|
||||
/** Lua function to execute. */
|
||||
luaA_ref fct;
|
||||
/** Lua function to execute on press */
|
||||
luaA_ref press;
|
||||
/** Lua function to execute on release */
|
||||
luaA_ref release;
|
||||
} keybinding_t;
|
||||
|
||||
ARRAY_TYPE(keybinding_t *, keybinding)
|
||||
|
|
Loading…
Reference in New Issue