key-bindings: refactor: use a single type for all key bindings

Up until now, the various key binding modes (“normal”, “search” and
“url”) have used their own struct definitions for their key bindings.

The only reason for this was to have a properly typed “action” (using
the appropriate “action” enum).

This caused lots of duplicated code. This patch refactors this to use
a single struct definition for the “unparsed” key bindings handled by
the configuration, and another single definition for “parsed” bindings
used while handling input.

This allows us to implement configuration parsing, keymap translation
and so on using one set of functions, regardless of key binding mode.
This commit is contained in:
Daniel Eklöf 2021-02-07 14:46:29 +01:00
parent 63a50afc8e
commit 03bac9dada
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 145 additions and 331 deletions

View file

@ -80,17 +80,17 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key,
{
/* Key bindings */
tll_foreach(seat->kbd.bindings.url, it) {
if (it->item.bind.mods != mods)
if (it->item.mods != mods)
continue;
/* Match symbol */
if (it->item.bind.sym == sym) {
if (it->item.sym == sym) {
execute_binding(seat, term, it->item.action, serial);
return;
}
/* Match raw key code */
tll_foreach(it->item.bind.key_codes, code) {
tll_foreach(it->item.key_codes, code) {
if (code->item == key) {
execute_binding(seat, term, it->item.action, serial);
return;