From 5e64e06a550c2499a23f03749986791136cbbcb9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 27 Feb 2021 20:42:31 +0100 Subject: input: rewrite of how we match foot’s own key bindings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bindings are matched in one out of three ways: * By translated (by XKB) symbols * By untranslated symbols * By raw key codes A translated symbol is affected by pressed modifiers, some of which can be “consumed”. Consumed modifiers to not partake in the comparison with the binding’s modifiers. In this mode, ctrl+shift+2 maps to ctrl+@ on a US layout. Untranslated symbols, or un-shifted symbols refer to the “base” symbol of the pressed key, i.e. it’s unaffected by modifiers. In this mode, consumed modifiers *do* partake in the comparison with the binding’s modifiers, and ctrl+shift+2 maps to ctrl+shift+2 on a US layout. More examples: ctrl+shift+u maps to ctrl+U in the translated lookup, while ctrl+shift+u maps to ctrl+shift+u in the untranslated lookup. Finally, we also match raw key codes. This allows our bindings to work using the same physical keys when the user switches between latin and non-latin layouts. This means key bindings in foot.ini *must* not include both +shift+ and a *shifted* key. I.e. ctrl+shift+U is not a valid combo as it cannot be triggered. Unfortunately, this was how you were supposed to write bindings up until now... so, we try to detect such bindings, log a deprecation warning and then “fix” the binding for the user. When specifying bindings in foot.ini, both ctrl+U and ctrl+shift+u are valid, and will work. The latter is preferred though, since we cannot detect the raw key code for the former variant. Personally, I also prefer the latter one because it is more explicit; it’s more obvious which keys are involved. However, in some cases it makes more sense to use the other variant. Typically for non-letter combos. --- url-mode.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'url-mode.c') diff --git a/url-mode.c b/url-mode.c index 791b4ce0..34866fb8 100644 --- a/url-mode.c +++ b/url-mode.c @@ -115,23 +115,36 @@ activate_url(struct seat *seat, struct terminal *term, const struct url *url) void urls_input(struct seat *seat, struct terminal *term, uint32_t key, - xkb_keysym_t sym, xkb_mod_mask_t mods, uint32_t serial) + xkb_keysym_t sym, xkb_mod_mask_t mods, xkb_mod_mask_t consumed, + const xkb_keysym_t *raw_syms, size_t raw_count, + uint32_t serial) { /* Key bindings */ tll_foreach(seat->kbd.bindings.url, it) { - if (it->item.mods != mods) - continue; + const struct key_binding *bind = &it->item; - /* Match symbol */ - if (it->item.sym == sym) { - execute_binding(seat, term, it->item.action, serial); + /* Match translated symbol */ + if (bind->sym == sym && + bind->mods == (mods & ~consumed)) + { + execute_binding(seat, term, bind->action, serial); return; } + if (bind->mods != mods) + continue; + + for (size_t i = 0; i < raw_count; i++) { + if (bind->sym == raw_syms[i]) { + execute_binding(seat, term, bind->action, serial); + return; + } + } + /* Match raw key code */ - tll_foreach(it->item.key_codes, code) { + tll_foreach(bind->key_codes, code) { if (code->item == key) { - execute_binding(seat, term, it->item.action, serial); + execute_binding(seat, term, bind->action, serial); return; } } -- cgit v1.3 From 93b02cf2b85e080269d6822678df8bbbd94efd42 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 4 Mar 2021 09:36:25 +0100 Subject: url-mode: ignore keys with modifiers --- url-mode.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'url-mode.c') diff --git a/url-mode.c b/url-mode.c index 34866fb8..362ea3af 100644 --- a/url-mode.c +++ b/url-mode.c @@ -161,6 +161,9 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key, return; } + if (mods & ~consumed) + return; + wchar_t wc = xkb_state_key_get_utf32(seat->kbd.xkb_state, key); /* -- cgit v1.3