key: replace key_find() by generic callback

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-27 17:52:36 +02:00
parent d80c6e9c33
commit e2b4fae3e2
3 changed files with 17 additions and 54 deletions

51
event.c
View File

@ -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.
@ -597,45 +611,12 @@ event_handle_key(void *data __attribute__ ((unused)),
lua_pop(globalconf.L, 1); /* pop returned value or function if not called */
}
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;
}
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;
}

17
key.c
View File

@ -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)
{

1
key.h
View File

@ -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 *);