mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
wayland: unify key- and mouse-binding structs
This commit is contained in:
parent
d04bc6ab10
commit
dcd79065c8
5 changed files with 47 additions and 37 deletions
40
input.c
40
input.c
|
|
@ -524,11 +524,14 @@ convert_key_binding(const struct seat *seat,
|
|||
xkb_keysym_t sym = maybe_repair_key_combo(seat, conf_binding->k.sym, mods);
|
||||
|
||||
struct key_binding binding = {
|
||||
.mods = mods,
|
||||
.sym = sym,
|
||||
.key_codes = key_codes_for_xkb_sym(seat->kbd.xkb_keymap, sym),
|
||||
.type = KEY_BINDING,
|
||||
.action = conf_binding->action,
|
||||
.pipe_argv = conf_binding->pipe.argv.args,
|
||||
.mods = mods,
|
||||
.k = {
|
||||
.sym = sym,
|
||||
.key_codes = key_codes_for_xkb_sym(seat->kbd.xkb_keymap, sym),
|
||||
},
|
||||
};
|
||||
tll_push_back(*bindings, binding);
|
||||
}
|
||||
|
|
@ -564,12 +567,15 @@ static void
|
|||
convert_mouse_binding(struct seat *seat,
|
||||
const struct config_key_binding *conf_binding)
|
||||
{
|
||||
struct mouse_binding binding = {
|
||||
struct key_binding binding = {
|
||||
.type = MOUSE_BINDING,
|
||||
.action = conf_binding->action,
|
||||
.mods = conf_modifiers_to_mask(seat, &conf_binding->modifiers),
|
||||
.button = conf_binding->m.button,
|
||||
.count = conf_binding->m.count,
|
||||
.pipe_argv = conf_binding->pipe.argv.args,
|
||||
.mods = conf_modifiers_to_mask(seat, &conf_binding->modifiers),
|
||||
.m = {
|
||||
.button = conf_binding->m.button,
|
||||
.count = conf_binding->m.count,
|
||||
},
|
||||
};
|
||||
tll_push_back(seat->mouse.bindings, binding);
|
||||
}
|
||||
|
|
@ -619,11 +625,11 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
|
|||
}
|
||||
|
||||
tll_foreach(seat->kbd.bindings.key, it)
|
||||
tll_free(it->item.key_codes);
|
||||
tll_free(it->item.k.key_codes);
|
||||
tll_free(seat->kbd.bindings.key);
|
||||
|
||||
tll_foreach(seat->kbd.bindings.search, it)
|
||||
tll_free(it->item.key_codes);
|
||||
tll_free(it->item.k.key_codes);
|
||||
tll_free(seat->kbd.bindings.search);
|
||||
|
||||
tll_free(seat->mouse.bindings);
|
||||
|
|
@ -1525,7 +1531,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
|
|||
const struct key_binding *bind = &it->item;
|
||||
|
||||
/* Match translated symbol */
|
||||
if (bind->sym == sym &&
|
||||
if (bind->k.sym == sym &&
|
||||
bind->mods == (bind_mods & ~bind_consumed) &&
|
||||
execute_binding(
|
||||
seat, term, bind->action, bind->pipe_argv, serial))
|
||||
|
|
@ -1538,7 +1544,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
|
|||
|
||||
/* Match untranslated symbols */
|
||||
for (size_t i = 0; i < raw_count; i++) {
|
||||
if (bind->sym == raw_syms[i] && execute_binding(
|
||||
if (bind->k.sym == raw_syms[i] && execute_binding(
|
||||
seat, term, bind->action, bind->pipe_argv, serial))
|
||||
{
|
||||
goto maybe_repeat;
|
||||
|
|
@ -1546,7 +1552,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
|
|||
}
|
||||
|
||||
/* Match raw key code */
|
||||
tll_foreach(bind->key_codes, code) {
|
||||
tll_foreach(bind->k.key_codes, code) {
|
||||
if (code->item == key && execute_binding(
|
||||
seat, term, bind->action, bind->pipe_argv, serial))
|
||||
{
|
||||
|
|
@ -2411,12 +2417,12 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|||
/* Ignore selection override modifiers when matching modifiers */
|
||||
mods &= ~seat->kbd.selection_override_modmask;
|
||||
|
||||
const struct mouse_binding *match = NULL;
|
||||
const struct key_binding *match = NULL;
|
||||
|
||||
tll_foreach(seat->mouse.bindings, it) {
|
||||
const struct mouse_binding *binding = &it->item;
|
||||
const struct key_binding *binding = &it->item;
|
||||
|
||||
if (binding->button != button) {
|
||||
if (binding->m.button != button) {
|
||||
/* Wrong button */
|
||||
continue;
|
||||
}
|
||||
|
|
@ -2426,12 +2432,12 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (binding->count > seat->mouse.count) {
|
||||
if (binding->m.count > seat->mouse.count) {
|
||||
/* Not correct click count */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (match == NULL || binding->count > match->count)
|
||||
if (match == NULL || binding->m.count > match->m.count)
|
||||
match = binding;
|
||||
}
|
||||
|
||||
|
|
|
|||
6
search.c
6
search.c
|
|
@ -838,7 +838,7 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key,
|
|||
const struct key_binding *bind = &it->item;
|
||||
|
||||
/* Match translated symbol */
|
||||
if (bind->sym == sym &&
|
||||
if (bind->k.sym == sym &&
|
||||
bind->mods == (mods & ~consumed)) {
|
||||
|
||||
if (execute_binding(seat, term, bind->action, serial,
|
||||
|
|
@ -854,7 +854,7 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key,
|
|||
|
||||
/* Match untranslated symbols */
|
||||
for (size_t i = 0; i < raw_count; i++) {
|
||||
if (bind->sym == raw_syms[i]) {
|
||||
if (bind->k.sym == raw_syms[i]) {
|
||||
if (execute_binding(seat, term, bind->action, serial,
|
||||
&update_search_result, &redraw))
|
||||
{
|
||||
|
|
@ -865,7 +865,7 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key,
|
|||
}
|
||||
|
||||
/* Match raw key code */
|
||||
tll_foreach(bind->key_codes, code) {
|
||||
tll_foreach(bind->k.key_codes, code) {
|
||||
if (code->item == key) {
|
||||
if (execute_binding(seat, term, bind->action, serial,
|
||||
&update_search_result, &redraw))
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key,
|
|||
const struct key_binding *bind = &it->item;
|
||||
|
||||
/* Match translated symbol */
|
||||
if (bind->sym == sym &&
|
||||
if (bind->k.sym == sym &&
|
||||
bind->mods == (mods & ~consumed))
|
||||
{
|
||||
execute_binding(seat, term, bind->action, serial);
|
||||
|
|
@ -136,14 +136,14 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key,
|
|||
continue;
|
||||
|
||||
for (size_t i = 0; i < raw_count; i++) {
|
||||
if (bind->sym == raw_syms[i]) {
|
||||
if (bind->k.sym == raw_syms[i]) {
|
||||
execute_binding(seat, term, bind->action, serial);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Match raw key code */
|
||||
tll_foreach(bind->key_codes, code) {
|
||||
tll_foreach(bind->k.key_codes, code) {
|
||||
if (code->item == key) {
|
||||
execute_binding(seat, term, bind->action, serial);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ static void
|
|||
key_bindings_destroy(key_binding_list_t *bindings)
|
||||
{
|
||||
tll_foreach(*bindings, it) {
|
||||
tll_free(it->item.key_codes);
|
||||
tll_free(it->item.k.key_codes);
|
||||
tll_remove(*bindings, it);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
wayland.h
30
wayland.h
|
|
@ -101,24 +101,28 @@ enum bind_action_url {
|
|||
typedef tll(xkb_keycode_t) xkb_keycode_list_t;
|
||||
|
||||
struct key_binding {
|
||||
xkb_mod_mask_t mods;
|
||||
xkb_keysym_t sym;
|
||||
xkb_keycode_list_t key_codes;
|
||||
enum config_key_binding_type type;
|
||||
|
||||
int action; /* enum bind_action_* */
|
||||
char **pipe_argv;
|
||||
|
||||
xkb_mod_mask_t mods;
|
||||
|
||||
union {
|
||||
struct {
|
||||
xkb_keysym_t sym;
|
||||
xkb_keycode_list_t key_codes;
|
||||
} k;
|
||||
|
||||
struct {
|
||||
uint32_t button;
|
||||
int count;
|
||||
} m;
|
||||
};
|
||||
|
||||
};
|
||||
typedef tll(struct key_binding) key_binding_list_t;
|
||||
|
||||
struct mouse_binding {
|
||||
enum bind_action_normal action;
|
||||
xkb_mod_mask_t mods;
|
||||
uint32_t button;
|
||||
int count;
|
||||
char **pipe_argv;
|
||||
};
|
||||
typedef tll(struct mouse_binding) mouse_binding_list_t;
|
||||
|
||||
/* Mime-types we support when dealing with data offers (e.g. copy-paste, or DnD) */
|
||||
enum data_offer_mime_type {
|
||||
DATA_OFFER_MIME_UNSET,
|
||||
|
|
@ -254,7 +258,7 @@ struct seat {
|
|||
double aggregated[2];
|
||||
bool have_discrete;
|
||||
|
||||
mouse_binding_list_t bindings;
|
||||
key_binding_list_t bindings;
|
||||
} mouse;
|
||||
|
||||
/* Clipboard */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue