mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
config: unify key- and mouse bindings
With this patch, key- and mouse-bindings structs (the non-layout specific ones) are unified into a single struct. The logic that parses, and manages, the key- and mouse binding lists are almost identical. The *only* difference between a key- and a mouse binding is that key bindings have an XKB symbol, and mouse bindings a button and click-count. The new, unified, struct uses a union around these, and all functions that need to know which members to use/operate on now takes a ‘type’ parameter.
This commit is contained in:
parent
4c50c44cf7
commit
f6a591b80a
3 changed files with 242 additions and 411 deletions
22
input.c
22
input.c
|
|
@ -520,7 +520,7 @@ convert_key_binding(const struct seat *seat,
|
|||
key_binding_list_t *bindings)
|
||||
{
|
||||
xkb_mod_mask_t mods = conf_modifiers_to_mask(seat, &conf_binding->modifiers);
|
||||
xkb_keysym_t sym = maybe_repair_key_combo(seat, conf_binding->sym, mods);
|
||||
xkb_keysym_t sym = maybe_repair_key_combo(seat, conf_binding->k.sym, mods);
|
||||
|
||||
struct key_binding binding = {
|
||||
.mods = mods,
|
||||
|
|
@ -561,13 +561,13 @@ convert_url_bindings(const struct config *conf, struct seat *seat)
|
|||
|
||||
static void
|
||||
convert_mouse_binding(struct seat *seat,
|
||||
const struct config_mouse_binding *conf_binding)
|
||||
const struct config_key_binding *conf_binding)
|
||||
{
|
||||
struct mouse_binding binding = {
|
||||
.action = conf_binding->action,
|
||||
.mods = conf_modifiers_to_mask(seat, &conf_binding->modifiers),
|
||||
.button = conf_binding->button,
|
||||
.count = conf_binding->count,
|
||||
.button = conf_binding->m.button,
|
||||
.count = conf_binding->m.count,
|
||||
.pipe_argv = conf_binding->pipe.argv.args,
|
||||
};
|
||||
tll_push_back(seat->mouse.bindings, binding);
|
||||
|
|
@ -577,9 +577,7 @@ static void
|
|||
convert_mouse_bindings(const struct config *conf, struct seat *seat)
|
||||
{
|
||||
for (size_t i = 0; i < conf->bindings.mouse.count; i++) {
|
||||
const struct config_mouse_binding *binding = &conf->bindings.mouse.arr[i];
|
||||
if (binding->action == BIND_ACTION_NONE)
|
||||
continue;
|
||||
const struct config_key_binding *binding = &conf->bindings.mouse.arr[i];
|
||||
convert_mouse_binding(seat, binding);
|
||||
}
|
||||
}
|
||||
|
|
@ -2543,19 +2541,19 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|||
|
||||
else {
|
||||
/* Seat does NOT have a keyboard - use mouse bindings *without* modifiers */
|
||||
const struct config_mouse_binding *match = NULL;
|
||||
const struct config_key_binding *match = NULL;
|
||||
const struct config *conf = seat->wayl->conf;
|
||||
|
||||
for (size_t i = 0; i < conf->bindings.mouse.count; i++) {
|
||||
const struct config_mouse_binding *binding =
|
||||
const struct config_key_binding *binding =
|
||||
&conf->bindings.mouse.arr[i];
|
||||
|
||||
if (binding->button != button) {
|
||||
if (binding->m.button != button) {
|
||||
/* Wrong button */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (binding->count > seat->mouse.count) {
|
||||
if (binding->m.count > seat->mouse.count) {
|
||||
/* Incorrect click count */
|
||||
continue;
|
||||
}
|
||||
|
|
@ -2566,7 +2564,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (match == NULL || binding->count > match->count)
|
||||
if (match == NULL || binding->m.count > match->m.count)
|
||||
match = binding;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue