Move keyboard binding accessor to bindings.[ch]

Rename `get_binding` to `get_keyboard_binding` and ensure that this
function only accesses bindings of type B_KEYBOARD. Other types of
bindings (e.g. mouse bindings) will be accessed by a different function.
This commit is contained in:
Tony Crisci
2014-02-21 19:10:21 -05:00
committed by Michael Stapelberg
parent 0f6c411f06
commit 3d6d0c134c
5 changed files with 71 additions and 67 deletions

View File

@ -30,64 +30,6 @@ void ungrab_all_keys(xcb_connection_t *conn) {
xcb_ungrab_key(conn, XCB_GRAB_ANY, root, XCB_BUTTON_MASK_ANY);
}
/*
* Returns a pointer to the Binding with the specified modifiers and keycode
* or NULL if no such binding exists.
*
*/
Binding *get_binding(uint16_t modifiers, bool key_release, xcb_keycode_t keycode) {
Binding *bind;
if (!key_release) {
/* On a KeyPress event, we first reset all
* B_UPON_KEYRELEASE_IGNORE_MODS bindings back to B_UPON_KEYRELEASE */
TAILQ_FOREACH(bind, bindings, bindings) {
if (bind->release == B_UPON_KEYRELEASE_IGNORE_MODS)
bind->release = B_UPON_KEYRELEASE;
}
}
TAILQ_FOREACH(bind, bindings, bindings) {
/* First compare the modifiers (unless this is a
* B_UPON_KEYRELEASE_IGNORE_MODS binding and this is a KeyRelease
* event) */
if (bind->mods != modifiers &&
(bind->release != B_UPON_KEYRELEASE_IGNORE_MODS ||
!key_release))
continue;
/* If a symbol was specified by the user, we need to look in
* the array of translated keycodes for the events keycode */
if (bind->symbol != NULL) {
if (memmem(bind->translated_to,
bind->number_keycodes * sizeof(xcb_keycode_t),
&keycode, sizeof(xcb_keycode_t)) == NULL)
continue;
} else {
/* This case is easier: The user specified a keycode */
if (bind->keycode != keycode)
continue;
}
/* If this keybinding is a KeyRelease binding, it matches the key which
* the user pressed. We therefore mark it as
* B_UPON_KEYRELEASE_IGNORE_MODS for later, so that the user can
* release the modifiers before the actual key and the KeyRelease will
* still be matched. */
if (bind->release == B_UPON_KEYRELEASE && !key_release)
bind->release = B_UPON_KEYRELEASE_IGNORE_MODS;
/* Check if the binding is for a KeyPress or a KeyRelease event */
if ((bind->release == B_UPON_KEYPRESS && key_release) ||
(bind->release >= B_UPON_KEYRELEASE && !key_release))
continue;
break;
}
return (bind == TAILQ_END(bindings) ? NULL : bind);
}
/*
* Translates keysymbols to keycodes for all bindings which use keysyms.
*