From 6a089c92ca5117480d459d92c9c1e67336f5013c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 27 Sep 2020 14:31:39 +0200 Subject: [PATCH] =?UTF-8?q?input:=20mouse:=20match=20binding=20if=20bindin?= =?UTF-8?q?g=E2=80=99s=20click=20count=20is=20*less*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow a mouse binding to match even if its click count is less than the actual click count. If there are multiple bindings that match, use the one with the highest click count (that less than, or equal to the actual click count). Closes #146 --- CHANGELOG.md | 7 +++++++ input.c | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03e64784..3fbc2cc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,13 @@ ### Deprecated ### Removed ### Fixed + +* Mouse bindings now match even if the actual click count is larger + than specified in the binding. This allows you to, for example, + quickly press the middle-button to paste multiple times + (https://codeberg.org/dnkl/foot/issues/146). + + ### Security ### Contributors diff --git a/input.c b/input.c index cfa99574..cc14d41b 100644 --- a/input.c +++ b/input.c @@ -1526,6 +1526,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, * applications */ mods &= ~(1 << seat->kbd.mod_shift); + const struct mouse_binding *match = NULL; + tll_foreach(seat->mouse.bindings, it) { const struct mouse_binding *binding = &it->item; @@ -1539,19 +1541,25 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, continue; } - if (binding->count != seat->mouse.count) { + if (binding->count > seat->mouse.count) { /* Not correct click count */ continue; } + if (match == NULL || binding->count > match->count) + match = binding; + } + + if (match != NULL) { seat->mouse.consumed = execute_binding( - seat, term, binding->action, NULL, serial); - break; + seat, term, match->action, NULL, serial); } } else { /* Seat does NOT have a keyboard - use mouse bindings *without* modifiers */ + const struct config_mouse_binding *match = NULL; + tll_foreach(seat->wayl->conf->bindings.mouse, it) { const struct config_mouse_binding *binding = &it->item; @@ -1560,7 +1568,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, continue; } - if (binding->count != seat->mouse.count) { + if (binding->count > seat->mouse.count) { /* Incorrect click count */ continue; } @@ -1571,9 +1579,13 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, continue; } + if (match == NULL || binding->count > match->count) + match = binding; + } + + if (match != NULL) { seat->mouse.consumed = execute_binding( - seat, term, binding->action, NULL, serial); - break; + seat, term, match->action, NULL, serial); } }