From e2b4fae3e2371ddd9221458a77a1cd42e30fe284 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 27 Apr 2009 17:52:36 +0200 Subject: [PATCH] key: replace key_find() by generic callback Signed-off-by: Julien Danjou --- event.c | 53 +++++++++++++++++------------------------------------ key.c | 17 ----------------- key.h | 1 - 3 files changed, 17 insertions(+), 54 deletions(-) diff --git a/event.c b/event.c index 3df8288eb..02eb2a6f3 100644 --- a/event.c +++ b/event.c @@ -79,7 +79,21 @@ event_button_match(xcb_button_press_event_t *ev, button_t *b) && (b->mod == XCB_BUTTON_MASK_ANY || b->mod == ev->state)); } +static bool +event_key_match(xcb_key_press_event_t *ev, keyb_t *k) +{ + /* get keysym ignoring shift and mod5 */ + xcb_keysym_t keysym = + key_getkeysym(ev->detail, + ev->state & ~(XCB_MOD_MASK_SHIFT | XCB_MOD_MASK_5 | XCB_MOD_MASK_LOCK)); + + return (((k->keycode && ev->detail == k->keycode) + || (k->keysym && keysym == k->keysym)) + && (k->mod == XCB_BUTTON_MASK_ANY || k->mod == ev->state)); +} + DO_EVENT_HOOK_CALLBACK(button, XCB_BUTTON, button_t, button_array_t, event_button_match) +DO_EVENT_HOOK_CALLBACK(key, XCB_KEY, keyb_t, key_array_t, event_key_match) /** Handle an event with mouse grabber if needed * \param x The x coordinate. @@ -598,44 +612,11 @@ event_handle_key(void *data __attribute__ ((unused)), } else if((c = client_getbywin(ev->event))) { - keyb_t *k = key_find(&c->keys, ev); - - if(k) - switch(ev->response_type) - { - case XCB_KEY_PRESS: - if(k->press != LUA_REFNIL) - { - client_push(globalconf.L, c); - luaA_dofunction(globalconf.L, k->press, 1, 0); - } - break; - case XCB_KEY_RELEASE: - if(k->release != LUA_REFNIL) - { - client_push(globalconf.L, c); - luaA_dofunction(globalconf.L, k->release, 1, 0); - } - break; - } + client_push(globalconf.L, c); + event_key_callback(ev, &c->keys, 1); } else - { - keyb_t *k = key_find(&globalconf.keys, ev); - - 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; - } - } + event_key_callback(ev, &globalconf.keys, 0); return 0; } diff --git a/key.c b/key.c index 841f440ff..cbed19136 100644 --- a/key.c +++ b/key.c @@ -153,23 +153,6 @@ key_getkeysym(xcb_keycode_t detail, uint16_t state) return XCB_NO_SYMBOL; } -keyb_t * -key_find(key_array_t *keys, const xcb_key_press_event_t *ev) -{ - /* get keysym ignoring shift and mod5 */ - xcb_keysym_t keysym = - key_getkeysym(ev->detail, - ev->state & ~(XCB_MOD_MASK_SHIFT | XCB_MOD_MASK_5 | XCB_MOD_MASK_LOCK)); - - foreach(k, *keys) - if((((*k)->keycode && ev->detail == (*k)->keycode) - || ((*k)->keysym && keysym == (*k)->keysym)) - && ((*k)->mod == XCB_BUTTON_MASK_ANY || (*k)->mod == ev->state)) - return *k; - - return NULL; -} - static void luaA_keystore(keyb_t *key, const char *str, ssize_t len) { diff --git a/key.h b/key.h index 0372e0d69..04cf06d99 100644 --- a/key.h +++ b/key.h @@ -42,7 +42,6 @@ typedef struct keyb_t ARRAY_TYPE(keyb_t *, key) -keyb_t *key_find(key_array_t *, const xcb_key_press_event_t *); xcb_keysym_t key_getkeysym(xcb_keycode_t, uint16_t); void luaA_key_array_set(lua_State *, int, key_array_t *);